Magento products collection change reload category page
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am tring to change product collection using catalog_product_collection_load_before
.
I need to sort products by in stock
. Out of stock must be last.
following config.xml
,
<events>
<catalog_product_collection_load_before>
<observers>
<gst_sales_order_observer>
<class>Magecomp_Sortby_Model_Observer</class>
<method>modifyProductCollection</method>
</gst_sales_order_observer>
</observers>
</catalog_product_collection_load_before>
</events>
following Observer.php
public function modifyProductCollection($observer)
{
if (Mage::registry('current_category'))
{
$products = $observer->getEvent()->getCollection();
$_category_detail=Mage::registry('current_category');
//Inventory Stock
$toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
if ($toolbar) {
$products = $observer->getEvent()->getCollection();
$stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
$websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();
$products->getSelect()->joinLeft(
array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
"_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
array('stock_status')
);
$products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());
$products->getSelect()->reset('order');
$products->getSelect()->order('in_stock DESC');
if ($toolbar->getCurrentOrder()) {
$products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());
}
}
return $this;
}
}
Issue When I reload category page product collection is change. any things wrong ?
magento-1.9 event-observer product-collection category-listing
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am tring to change product collection using catalog_product_collection_load_before
.
I need to sort products by in stock
. Out of stock must be last.
following config.xml
,
<events>
<catalog_product_collection_load_before>
<observers>
<gst_sales_order_observer>
<class>Magecomp_Sortby_Model_Observer</class>
<method>modifyProductCollection</method>
</gst_sales_order_observer>
</observers>
</catalog_product_collection_load_before>
</events>
following Observer.php
public function modifyProductCollection($observer)
{
if (Mage::registry('current_category'))
{
$products = $observer->getEvent()->getCollection();
$_category_detail=Mage::registry('current_category');
//Inventory Stock
$toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
if ($toolbar) {
$products = $observer->getEvent()->getCollection();
$stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
$websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();
$products->getSelect()->joinLeft(
array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
"_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
array('stock_status')
);
$products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());
$products->getSelect()->reset('order');
$products->getSelect()->order('in_stock DESC');
if ($toolbar->getCurrentOrder()) {
$products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());
}
}
return $this;
}
}
Issue When I reload category page product collection is change. any things wrong ?
magento-1.9 event-observer product-collection category-listing
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am tring to change product collection using catalog_product_collection_load_before
.
I need to sort products by in stock
. Out of stock must be last.
following config.xml
,
<events>
<catalog_product_collection_load_before>
<observers>
<gst_sales_order_observer>
<class>Magecomp_Sortby_Model_Observer</class>
<method>modifyProductCollection</method>
</gst_sales_order_observer>
</observers>
</catalog_product_collection_load_before>
</events>
following Observer.php
public function modifyProductCollection($observer)
{
if (Mage::registry('current_category'))
{
$products = $observer->getEvent()->getCollection();
$_category_detail=Mage::registry('current_category');
//Inventory Stock
$toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
if ($toolbar) {
$products = $observer->getEvent()->getCollection();
$stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
$websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();
$products->getSelect()->joinLeft(
array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
"_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
array('stock_status')
);
$products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());
$products->getSelect()->reset('order');
$products->getSelect()->order('in_stock DESC');
if ($toolbar->getCurrentOrder()) {
$products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());
}
}
return $this;
}
}
Issue When I reload category page product collection is change. any things wrong ?
magento-1.9 event-observer product-collection category-listing
I am tring to change product collection using catalog_product_collection_load_before
.
I need to sort products by in stock
. Out of stock must be last.
following config.xml
,
<events>
<catalog_product_collection_load_before>
<observers>
<gst_sales_order_observer>
<class>Magecomp_Sortby_Model_Observer</class>
<method>modifyProductCollection</method>
</gst_sales_order_observer>
</observers>
</catalog_product_collection_load_before>
</events>
following Observer.php
public function modifyProductCollection($observer)
{
if (Mage::registry('current_category'))
{
$products = $observer->getEvent()->getCollection();
$_category_detail=Mage::registry('current_category');
//Inventory Stock
$toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
if ($toolbar) {
$products = $observer->getEvent()->getCollection();
$stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
$websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();
$products->getSelect()->joinLeft(
array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
"_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
array('stock_status')
);
$products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());
$products->getSelect()->reset('order');
$products->getSelect()->order('in_stock DESC');
if ($toolbar->getCurrentOrder()) {
$products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());
}
}
return $this;
}
}
Issue When I reload category page product collection is change. any things wrong ?
magento-1.9 event-observer product-collection category-listing
magento-1.9 event-observer product-collection category-listing
edited Aug 16 '17 at 7:40
PЯINCƏ
8,42931147
8,42931147
asked Aug 16 '17 at 6:23
Hardik VisaHardik Visa
489318
489318
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
your event in config.xml should be like this:
...
</global>
<frontend>
<events>
<catalog_product_collection_load_before>
<observers>
<Gst_Sales_Order_Observer>
<type>singleton</type>
<class>modelNameHere/observer</class> //exemple: sales/observer
<method>modifyProductCollection</method>
</Gst_Sales_Order_Observer>
</observers>
</catalog_product_collection_load_before>
</events>
</frontend>
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f189239%2fmagento-products-collection-change-reload-category-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
your event in config.xml should be like this:
...
</global>
<frontend>
<events>
<catalog_product_collection_load_before>
<observers>
<Gst_Sales_Order_Observer>
<type>singleton</type>
<class>modelNameHere/observer</class> //exemple: sales/observer
<method>modifyProductCollection</method>
</Gst_Sales_Order_Observer>
</observers>
</catalog_product_collection_load_before>
</events>
</frontend>
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
add a comment |
your event in config.xml should be like this:
...
</global>
<frontend>
<events>
<catalog_product_collection_load_before>
<observers>
<Gst_Sales_Order_Observer>
<type>singleton</type>
<class>modelNameHere/observer</class> //exemple: sales/observer
<method>modifyProductCollection</method>
</Gst_Sales_Order_Observer>
</observers>
</catalog_product_collection_load_before>
</events>
</frontend>
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
add a comment |
your event in config.xml should be like this:
...
</global>
<frontend>
<events>
<catalog_product_collection_load_before>
<observers>
<Gst_Sales_Order_Observer>
<type>singleton</type>
<class>modelNameHere/observer</class> //exemple: sales/observer
<method>modifyProductCollection</method>
</Gst_Sales_Order_Observer>
</observers>
</catalog_product_collection_load_before>
</events>
</frontend>
your event in config.xml should be like this:
...
</global>
<frontend>
<events>
<catalog_product_collection_load_before>
<observers>
<Gst_Sales_Order_Observer>
<type>singleton</type>
<class>modelNameHere/observer</class> //exemple: sales/observer
<method>modifyProductCollection</method>
</Gst_Sales_Order_Observer>
</observers>
</catalog_product_collection_load_before>
</events>
</frontend>
answered Aug 16 '17 at 7:52
PЯINCƏPЯINCƏ
8,42931147
8,42931147
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
add a comment |
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
as per your suggestion, but not working
– Hardik Visa
Aug 16 '17 at 12:55
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f189239%2fmagento-products-collection-change-reload-category-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown