Removing a product from the collection on a categoryHow to get the categories of the product collection loadedLayered Navigation for Custom Product Collection filtered via Custom AttributeProducts from a category plus any children and get category ID for conditions from collectionProduct List Collection to not show products in Category x unless products ids in?Get product count of Parent CategoryProduct filter by category not workingAdd Filter to magento 2 category product collectionAdd category IDs to product collectionHow to apply visibility filter to category view's product collection in magento 2?Magento 1 get only those product collection which are not on sale in a category

HashMap containsKey() returns false although hashCode() and equals() are true

What's the purpose of "true" in bash "if sudo true; then"

The baby cries all morning

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

At which point does a character regain all their Hit Dice?

Will it be accepted, if there is no ''Main Character" stereotype?

How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?

Best way to store options for panels

Personal Teleportation as a Weapon

Why does John Bercow say “unlock” after reading out the results of a vote?

What would happen if the UK refused to take part in EU Parliamentary elections?

Teaching indefinite integrals that require special-casing

Modify casing of marked letters

How to prove that the query oracle is unitary?

Is it correct to write "is not focus on"?

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?

Displaying the order of the columns of a table

What will be the benefits of Brexit?

Using parameter substitution on a Bash array

Finding all intervals that match predicate in vector

Bash method for viewing beginning and end of file

If a character can use a +X magic weapon as a spellcasting focus, does it add the bonus to spell attacks or spell save DCs?

What is the opposite of 'gravitas'?

Can criminal fraud exist without damages?



Removing a product from the collection on a category


How to get the categories of the product collection loadedLayered Navigation for Custom Product Collection filtered via Custom AttributeProducts from a category plus any children and get category ID for conditions from collectionProduct List Collection to not show products in Category x unless products ids in?Get product count of Parent CategoryProduct filter by category not workingAdd Filter to magento 2 category product collectionAdd category IDs to product collectionHow to apply visibility filter to category view's product collection in magento 2?Magento 1 get only those product collection which are not on sale in a category













1















I have a Magento site where I need to remove some products from certain customer groups due to them having a zero price on the products.



I have tried catalog_product_collection_load_after event and have successfully managed to remove the products that I want. This however causes a gap on the catagory pages where the products would be. Would there be any way to go about remove products from a collection either before the pagination is set on the collection or to "remake" the collection once you've removed the products.



The code I've tried so far:



 /* Remove all products from the category list where the (group) price is zero */
public function removeZeroPriceProducts($observer)

if (! Mage::app()->getStore()->isAdmin())

$collection = $observer->getEvent()->getCollection();
//Loop through all products in the collection
foreach ($collection as $product)
$product->getFinalPrice() === 0)
$observer->getEvent()->getCollection()->removeItemByKey($origProduct->getId());





Edit:
I've tried added it to _getProductCollection in List.php as suggested by Mohit.
This removes the product as expected but unfortunately still leaves a gap. I'll leave the code for that here as well.



protected function _getProductCollection()

if (is_null($this->_productCollection))
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory())
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());


// if this is a product view page
if (Mage::registry('product'))
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count())
// show products from this category
$this->setCategoryId(current($categories->getIterator()));



$origCategory = null;
if ($this->getCategoryId())
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId())
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);


$this->_productCollection = $layer->getProductCollection();

$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

if ($origCategory)
$layer->setCurrentCategory($origCategory);



//Try and remove a specific ID from the collection
$collection = $this->_productCollection;
$collection->removeItemByKey(4146);
return $collection;










share|improve this question




























    1















    I have a Magento site where I need to remove some products from certain customer groups due to them having a zero price on the products.



    I have tried catalog_product_collection_load_after event and have successfully managed to remove the products that I want. This however causes a gap on the catagory pages where the products would be. Would there be any way to go about remove products from a collection either before the pagination is set on the collection or to "remake" the collection once you've removed the products.



    The code I've tried so far:



     /* Remove all products from the category list where the (group) price is zero */
    public function removeZeroPriceProducts($observer)

    if (! Mage::app()->getStore()->isAdmin())

    $collection = $observer->getEvent()->getCollection();
    //Loop through all products in the collection
    foreach ($collection as $product)
    $product->getFinalPrice() === 0)
    $observer->getEvent()->getCollection()->removeItemByKey($origProduct->getId());





    Edit:
    I've tried added it to _getProductCollection in List.php as suggested by Mohit.
    This removes the product as expected but unfortunately still leaves a gap. I'll leave the code for that here as well.



    protected function _getProductCollection()

    if (is_null($this->_productCollection))
    $layer = $this->getLayer();
    /* @var $layer Mage_Catalog_Model_Layer */
    if ($this->getShowRootCategory())
    $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());


    // if this is a product view page
    if (Mage::registry('product'))
    // get collection of categories this product is associated with
    $categories = Mage::registry('product')->getCategoryCollection()
    ->setPage(1, 1)
    ->load();
    // if the product is associated with any category
    if ($categories->count())
    // show products from this category
    $this->setCategoryId(current($categories->getIterator()));



    $origCategory = null;
    if ($this->getCategoryId())
    $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
    if ($category->getId())
    $origCategory = $layer->getCurrentCategory();
    $layer->setCurrentCategory($category);


    $this->_productCollection = $layer->getProductCollection();

    $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

    if ($origCategory)
    $layer->setCurrentCategory($origCategory);



    //Try and remove a specific ID from the collection
    $collection = $this->_productCollection;
    $collection->removeItemByKey(4146);
    return $collection;










    share|improve this question


























      1












      1








      1








      I have a Magento site where I need to remove some products from certain customer groups due to them having a zero price on the products.



      I have tried catalog_product_collection_load_after event and have successfully managed to remove the products that I want. This however causes a gap on the catagory pages where the products would be. Would there be any way to go about remove products from a collection either before the pagination is set on the collection or to "remake" the collection once you've removed the products.



      The code I've tried so far:



       /* Remove all products from the category list where the (group) price is zero */
      public function removeZeroPriceProducts($observer)

      if (! Mage::app()->getStore()->isAdmin())

      $collection = $observer->getEvent()->getCollection();
      //Loop through all products in the collection
      foreach ($collection as $product)
      $product->getFinalPrice() === 0)
      $observer->getEvent()->getCollection()->removeItemByKey($origProduct->getId());





      Edit:
      I've tried added it to _getProductCollection in List.php as suggested by Mohit.
      This removes the product as expected but unfortunately still leaves a gap. I'll leave the code for that here as well.



      protected function _getProductCollection()

      if (is_null($this->_productCollection))
      $layer = $this->getLayer();
      /* @var $layer Mage_Catalog_Model_Layer */
      if ($this->getShowRootCategory())
      $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());


      // if this is a product view page
      if (Mage::registry('product'))
      // get collection of categories this product is associated with
      $categories = Mage::registry('product')->getCategoryCollection()
      ->setPage(1, 1)
      ->load();
      // if the product is associated with any category
      if ($categories->count())
      // show products from this category
      $this->setCategoryId(current($categories->getIterator()));



      $origCategory = null;
      if ($this->getCategoryId())
      $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
      if ($category->getId())
      $origCategory = $layer->getCurrentCategory();
      $layer->setCurrentCategory($category);


      $this->_productCollection = $layer->getProductCollection();

      $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

      if ($origCategory)
      $layer->setCurrentCategory($origCategory);



      //Try and remove a specific ID from the collection
      $collection = $this->_productCollection;
      $collection->removeItemByKey(4146);
      return $collection;










      share|improve this question
















      I have a Magento site where I need to remove some products from certain customer groups due to them having a zero price on the products.



      I have tried catalog_product_collection_load_after event and have successfully managed to remove the products that I want. This however causes a gap on the catagory pages where the products would be. Would there be any way to go about remove products from a collection either before the pagination is set on the collection or to "remake" the collection once you've removed the products.



      The code I've tried so far:



       /* Remove all products from the category list where the (group) price is zero */
      public function removeZeroPriceProducts($observer)

      if (! Mage::app()->getStore()->isAdmin())

      $collection = $observer->getEvent()->getCollection();
      //Loop through all products in the collection
      foreach ($collection as $product)
      $product->getFinalPrice() === 0)
      $observer->getEvent()->getCollection()->removeItemByKey($origProduct->getId());





      Edit:
      I've tried added it to _getProductCollection in List.php as suggested by Mohit.
      This removes the product as expected but unfortunately still leaves a gap. I'll leave the code for that here as well.



      protected function _getProductCollection()

      if (is_null($this->_productCollection))
      $layer = $this->getLayer();
      /* @var $layer Mage_Catalog_Model_Layer */
      if ($this->getShowRootCategory())
      $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());


      // if this is a product view page
      if (Mage::registry('product'))
      // get collection of categories this product is associated with
      $categories = Mage::registry('product')->getCategoryCollection()
      ->setPage(1, 1)
      ->load();
      // if the product is associated with any category
      if ($categories->count())
      // show products from this category
      $this->setCategoryId(current($categories->getIterator()));



      $origCategory = null;
      if ($this->getCategoryId())
      $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
      if ($category->getId())
      $origCategory = $layer->getCurrentCategory();
      $layer->setCurrentCategory($category);


      $this->_productCollection = $layer->getProductCollection();

      $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

      if ($origCategory)
      $layer->setCurrentCategory($origCategory);



      //Try and remove a specific ID from the collection
      $collection = $this->_productCollection;
      $collection->removeItemByKey(4146);
      return $collection;







      magento-1.7 collection product-collection






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday







      Natalie Hedström

















      asked yesterday









      Natalie HedströmNatalie Hedström

      1115




      1115




















          2 Answers
          2






          active

          oldest

          votes


















          0














          To modify product collection before rendering category page follow these steps:




          1. Override MagentoCatalogBlockProductListProduct

          2. In function _getProductCollection after if statement insert your code:



          $collection = $this->_productCollection;
          foreach ($collection as $k => $product)
          // Here goes your code to modify product
          // For example:

          $collection->removeItemByKey($k);// Remove original item from collection

          $collection->setOrder('position','ASC');// Reorder collection as you want
          return $collection;





          share|improve this answer

























          • Thanks, I'll give it a try.

            – Natalie Hedström
            yesterday











          • By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

            – Natalie Hedström
            yesterday











          • There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

            – Natalie Hedström
            yesterday











          • Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

            – Mohit chauhan
            yesterday











          • Can you show me your code in _getProductCollection function ?

            – Mohit chauhan
            yesterday


















          0














          I found a solution that seems to work.
          On the customer_login event I loop through all the products and add all the products that the customer are not allowed to see into an array that I then save in a customer session variable.



          I then create a function called removeZeroPriceProducts that catches onto the catalog_product_collection_load_before event. In this function I've excluded the products by doing the following:



          /* Remove all products from the category list where the (group) price is zero */
          public function removeZeroPriceProducts($observer)

          if (! Mage::app()->getStore()->isAdmin())

          //Get all disallowed products for the user
          if($disallowed = Mage::getSingleton('checkout/session')->getDisallowedProducts())
          //Add a filter for the product collection that removes all the disallowed products
          $observer->getEvent()->getCollection()->addFieldToFilter('entity_id', array('nin' => $disallowed));





          Instead of using removeItemByKey which removed the product but left a gap I now instead add a filter which removes all products that can be found in my session variable.




          Note. I first tried to loop through all the products in the removeZeroPriceProducts fonction. This however broke the page which is why I instead added all the products to a session variable when the customer logs in







          share|improve this answer






















            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
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267254%2fremoving-a-product-from-the-collection-on-a-category%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            To modify product collection before rendering category page follow these steps:




            1. Override MagentoCatalogBlockProductListProduct

            2. In function _getProductCollection after if statement insert your code:



            $collection = $this->_productCollection;
            foreach ($collection as $k => $product)
            // Here goes your code to modify product
            // For example:

            $collection->removeItemByKey($k);// Remove original item from collection

            $collection->setOrder('position','ASC');// Reorder collection as you want
            return $collection;





            share|improve this answer

























            • Thanks, I'll give it a try.

              – Natalie Hedström
              yesterday











            • By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

              – Natalie Hedström
              yesterday











            • There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

              – Natalie Hedström
              yesterday











            • Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

              – Mohit chauhan
              yesterday











            • Can you show me your code in _getProductCollection function ?

              – Mohit chauhan
              yesterday















            0














            To modify product collection before rendering category page follow these steps:




            1. Override MagentoCatalogBlockProductListProduct

            2. In function _getProductCollection after if statement insert your code:



            $collection = $this->_productCollection;
            foreach ($collection as $k => $product)
            // Here goes your code to modify product
            // For example:

            $collection->removeItemByKey($k);// Remove original item from collection

            $collection->setOrder('position','ASC');// Reorder collection as you want
            return $collection;





            share|improve this answer

























            • Thanks, I'll give it a try.

              – Natalie Hedström
              yesterday











            • By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

              – Natalie Hedström
              yesterday











            • There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

              – Natalie Hedström
              yesterday











            • Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

              – Mohit chauhan
              yesterday











            • Can you show me your code in _getProductCollection function ?

              – Mohit chauhan
              yesterday













            0












            0








            0







            To modify product collection before rendering category page follow these steps:




            1. Override MagentoCatalogBlockProductListProduct

            2. In function _getProductCollection after if statement insert your code:



            $collection = $this->_productCollection;
            foreach ($collection as $k => $product)
            // Here goes your code to modify product
            // For example:

            $collection->removeItemByKey($k);// Remove original item from collection

            $collection->setOrder('position','ASC');// Reorder collection as you want
            return $collection;





            share|improve this answer















            To modify product collection before rendering category page follow these steps:




            1. Override MagentoCatalogBlockProductListProduct

            2. In function _getProductCollection after if statement insert your code:



            $collection = $this->_productCollection;
            foreach ($collection as $k => $product)
            // Here goes your code to modify product
            // For example:

            $collection->removeItemByKey($k);// Remove original item from collection

            $collection->setOrder('position','ASC');// Reorder collection as you want
            return $collection;






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday









            magefms

            2,0472426




            2,0472426










            answered yesterday









            Mohit chauhanMohit chauhan

            498111




            498111












            • Thanks, I'll give it a try.

              – Natalie Hedström
              yesterday











            • By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

              – Natalie Hedström
              yesterday











            • There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

              – Natalie Hedström
              yesterday











            • Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

              – Mohit chauhan
              yesterday











            • Can you show me your code in _getProductCollection function ?

              – Mohit chauhan
              yesterday

















            • Thanks, I'll give it a try.

              – Natalie Hedström
              yesterday











            • By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

              – Natalie Hedström
              yesterday











            • There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

              – Natalie Hedström
              yesterday











            • Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

              – Mohit chauhan
              yesterday











            • Can you show me your code in _getProductCollection function ?

              – Mohit chauhan
              yesterday
















            Thanks, I'll give it a try.

            – Natalie Hedström
            yesterday





            Thanks, I'll give it a try.

            – Natalie Hedström
            yesterday













            By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

            – Natalie Hedström
            yesterday





            By ListProduct I'm guessning you meant List.php? I tried moving my code there but I still get a gap at the end of the page. Where in the function would I be adding the code? I tried a few different places with the same result

            – Natalie Hedström
            yesterday













            There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

            – Natalie Hedström
            yesterday





            There is no file called ListProduct.php in Magento 1.7. I've overridden the code, that's not the issue. The issue is that I'm still getting the gap which is what I'm trying to prevent :)

            – Natalie Hedström
            yesterday













            Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

            – Mohit chauhan
            yesterday





            Yes in Magento 1.7 there is List.php where you need to add this code. but am not getting what gap you are talking about ?

            – Mohit chauhan
            yesterday













            Can you show me your code in _getProductCollection function ?

            – Mohit chauhan
            yesterday





            Can you show me your code in _getProductCollection function ?

            – Mohit chauhan
            yesterday













            0














            I found a solution that seems to work.
            On the customer_login event I loop through all the products and add all the products that the customer are not allowed to see into an array that I then save in a customer session variable.



            I then create a function called removeZeroPriceProducts that catches onto the catalog_product_collection_load_before event. In this function I've excluded the products by doing the following:



            /* Remove all products from the category list where the (group) price is zero */
            public function removeZeroPriceProducts($observer)

            if (! Mage::app()->getStore()->isAdmin())

            //Get all disallowed products for the user
            if($disallowed = Mage::getSingleton('checkout/session')->getDisallowedProducts())
            //Add a filter for the product collection that removes all the disallowed products
            $observer->getEvent()->getCollection()->addFieldToFilter('entity_id', array('nin' => $disallowed));





            Instead of using removeItemByKey which removed the product but left a gap I now instead add a filter which removes all products that can be found in my session variable.




            Note. I first tried to loop through all the products in the removeZeroPriceProducts fonction. This however broke the page which is why I instead added all the products to a session variable when the customer logs in







            share|improve this answer



























              0














              I found a solution that seems to work.
              On the customer_login event I loop through all the products and add all the products that the customer are not allowed to see into an array that I then save in a customer session variable.



              I then create a function called removeZeroPriceProducts that catches onto the catalog_product_collection_load_before event. In this function I've excluded the products by doing the following:



              /* Remove all products from the category list where the (group) price is zero */
              public function removeZeroPriceProducts($observer)

              if (! Mage::app()->getStore()->isAdmin())

              //Get all disallowed products for the user
              if($disallowed = Mage::getSingleton('checkout/session')->getDisallowedProducts())
              //Add a filter for the product collection that removes all the disallowed products
              $observer->getEvent()->getCollection()->addFieldToFilter('entity_id', array('nin' => $disallowed));





              Instead of using removeItemByKey which removed the product but left a gap I now instead add a filter which removes all products that can be found in my session variable.




              Note. I first tried to loop through all the products in the removeZeroPriceProducts fonction. This however broke the page which is why I instead added all the products to a session variable when the customer logs in







              share|improve this answer

























                0












                0








                0







                I found a solution that seems to work.
                On the customer_login event I loop through all the products and add all the products that the customer are not allowed to see into an array that I then save in a customer session variable.



                I then create a function called removeZeroPriceProducts that catches onto the catalog_product_collection_load_before event. In this function I've excluded the products by doing the following:



                /* Remove all products from the category list where the (group) price is zero */
                public function removeZeroPriceProducts($observer)

                if (! Mage::app()->getStore()->isAdmin())

                //Get all disallowed products for the user
                if($disallowed = Mage::getSingleton('checkout/session')->getDisallowedProducts())
                //Add a filter for the product collection that removes all the disallowed products
                $observer->getEvent()->getCollection()->addFieldToFilter('entity_id', array('nin' => $disallowed));





                Instead of using removeItemByKey which removed the product but left a gap I now instead add a filter which removes all products that can be found in my session variable.




                Note. I first tried to loop through all the products in the removeZeroPriceProducts fonction. This however broke the page which is why I instead added all the products to a session variable when the customer logs in







                share|improve this answer













                I found a solution that seems to work.
                On the customer_login event I loop through all the products and add all the products that the customer are not allowed to see into an array that I then save in a customer session variable.



                I then create a function called removeZeroPriceProducts that catches onto the catalog_product_collection_load_before event. In this function I've excluded the products by doing the following:



                /* Remove all products from the category list where the (group) price is zero */
                public function removeZeroPriceProducts($observer)

                if (! Mage::app()->getStore()->isAdmin())

                //Get all disallowed products for the user
                if($disallowed = Mage::getSingleton('checkout/session')->getDisallowedProducts())
                //Add a filter for the product collection that removes all the disallowed products
                $observer->getEvent()->getCollection()->addFieldToFilter('entity_id', array('nin' => $disallowed));





                Instead of using removeItemByKey which removed the product but left a gap I now instead add a filter which removes all products that can be found in my session variable.




                Note. I first tried to loop through all the products in the removeZeroPriceProducts fonction. This however broke the page which is why I instead added all the products to a session variable when the customer logs in








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                Natalie HedströmNatalie Hedström

                1115




                1115



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267254%2fremoving-a-product-from-the-collection-on-a-category%23new-answer', 'question_page');

                    );

                    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







                    Popular posts from this blog

                    Sum ergo cogito? 1 nng

                    三茅街道4182Guuntc Dn precexpngmageondP