magento2-outofstockatlast
magento2-outofstockatlast copied to clipboard
order of Widget new products is broken
module
Preconditions
I installed it on magento 2.4.6-p3 with elasticsearch version 7.17.7.
reproduce
Everything Works Well But when i add a new Products Widget to Home page or etc sort of new Products Broken and show old or random products
Expected Result
Actual result
as you see old products show after enable this module
Thank you !
Thanks @ppeyman for the report, as I know the new products widget used news_from_date as default sorting instead custom sorting out of stock attribute. Please see below for reference https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php#L86-L118 https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/Catalog/Block/Product/NewProduct.php#L147-L150
Further more we support the Product List only, there was no plans for widget yet.
Thanks @ppeyman for the report, as I know the new products widget used news_from_date as default sorting instead custom sorting out of stock attribute. Please see below for reference https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php#L86-L118 https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/Catalog/Block/Product/NewProduct.php#L147-L150
Further more we support the Product List only, there was no plans for widget yet.
so that mean i disable new products in our site ?
@ppeyman not sure, but for sure our module took no effect to the New Products widget and the widget works as Out of the box Magento
Owner
so why when i disable your module problem of widget solved ?
Here what I archived before and after enabling/disabling module, reindexing
Before
After
See https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php#L86-L118
I supposed the logic as your screenshot came to Magento/Catalog/Block/Product/Widget/NewWidget.php::_getRecentlyAddedProductsCollection Where the order was sorting by created_at desc
Are you able to double check the logic?
my logic :
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection()
->setPageSize($this->getPageSize())
->setCurPage($this->getCurrentPage());
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
return $collection;
}
/**
* Prepare collection for recent product list
*
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection|Object|\Magento\Framework\Data\Collection
*/
protected function _getRecentlyAddedProductsCollection()
{
/** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
$collection = $this->_productCollectionFactory->create();
$collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToSort('created_at', 'desc')
->setPageSize($this->getPageSize())
->setCurPage($this->getCurrentPage());
return $collection;
}
@tuyennn Hi dear i test it on new fresh magento installation and add four old products and add four new products when your module is enabled doesn`t show new products and showing another products please check it like me and see results
in adminpanel shows well and true :
in frontend show false :
thank you