0

When a product, such as those that are children of configurable products, have their visibility attribute set to 'Not Visible Individually' they can be added to the wishlist, however, when another product is added (or the same product is added again) this item is automatically removed from the wishlist.

Anyone with more experience care to ellucidate my understanding as to why this is happening or recommend a workaround? When the product's visibility is changed this functionality goes away and this item can be added to the wishlist without a problem.

2
  • Please provide some input - which Magento version, for example. Also: does this problem look like yours, and maybe provide an answer? magento.stackexchange.com/questions/28865/… Feb 24, 2015 at 21:36
  • 1
    @simonthesorcerer I resolved it -- it's a similar issue to the question you posted. I'll create an answer for this and that one, thanks for reminding me about this open question! Feb 24, 2015 at 21:46

1 Answer 1

0

First, I overwrote how configurable products are added to the wishlist. The parameters for the configured child are stripped and they then replace the configurable product itself to emulate a simple product.

<?php
require_once(Mage::getModuleDir('controllers', 'Enterprise_Wishlist') . DS . 'IndexController.php');
class nameSpace_Wishlist_IndexController extends Enterprise_Wishlist_IndexController
{
    public function addAction()
    {
        $productId = (int)$this->getRequest()->getparam('product');
        $product = Mage::getModel('catalog/product')->load($productId);
        if ($product->getTypeId() == 'configurable') {
            $params = $this->getRequest()->getParams();
            $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
            $product = Mage::getModel('catalog/product')->load($child->getId());
            $this->getRequest()->setParam('product', $product->getId());
            if (isset($_POST['super_attribute'])) {
                unset($_POST['super_attribute']);
            }
        }
        $customerId = $this->_getSession()->getCustomerId();
        $name = $this->getRequest()->getParam('name');
        $visibility = ($this->getRequest()->getParam('visibility', 0) === 'on' ? 1 : 0);
        if ($name !== null) {
            try {
                $wishlist = $this->_editWishlist($customerId, $name, $visibility);
                $this->_getSession()->addSuccess(
Mage::helper('enterprise_wishlist')->__('Wishlist "%s" was successfully saved', Mage::helper('core')->escapeHtml($wishlist->getName())));
                $this->getRequest()->setParam('wishlist_id', $wishlist->getId());
            } catch (Mage_Core_Exception $e) {
                $this->_getSession()->addError($e->getMessage());
            } catch (Exception $e) {
                $this->_getSession()->addException($e, Mage::helper('enterprise_wishlist')->__('Error happened during wishlist creation'));
            }
        }
        if (!$this->_validateFormKey()) {
            return $this->_redirect('*/*');
        }
        $this->_addItemToWishList();
    }
}

Then, I overwrote the wishlist model getItemCollection method to include 'invisible' products in the item collection. This took care of the issue where other products would overwrite the position of the configured 'invisible' product in the data structure.

class nameSpace_Wishlist_Model_Wishlist extends Mage_Wishlist_Model_Wishlist
{
    public function getItemCollection()
    {
        if (is_null($this->_itemCollection)) {
            /** @var $currentWebsiteOnly boolean */
            $currentWebsiteOnly = !Mage::app()->getStore()->isAdmin();
            $this->_itemCollection = Mage::getResourceModel('wishlist/item_collection')
                ->addWishlistFilter($this)
                ->addStoreFilter($this->getSharedStoreIds($currentWebsiteOnly));

             if (Mage::app()->getStore()->isAdmin()) {
                 $customer = Mage::getModel('customer/customer')->load($this->getCustomerId());
                 $this->_itemCollection->setWebsiteId($customer->getWebsiteId());
                 $this->_itemCollection->setCustomerGroupId($customer->getGroupId());
              }
          }
          return $this->_itemCollection;
     }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.