magento-configurable-simple icon indicating copy to clipboard operation
magento-configurable-simple copied to clipboard

Cannot edit configurable item in cart

Open barryvdh opened this issue 10 years ago • 5 comments

Original issue: https://github.com/organicinternet/magento-configurable-simple/issues/124 Suggested patch (not tested/tried): https://github.com/dfelton/FirstScribe_SimpleConfigurableProducts

Do you think you can merge/test that?

barryvdh avatar May 15 '14 12:05 barryvdh

@barryvdh Yes I will try to fix this problem. 12 Jun 2014 : I work on it.

obigroup avatar May 16 '14 12:05 obigroup

There is any update for this issue?

Richardmaximun avatar Aug 11 '15 13:08 Richardmaximun

@obigroup can I help/test/do something in order to get this one fixed?

dannevang avatar Sep 23 '15 12:09 dannevang

i have fixed the Problem, now it works on my Magento 1.9.2.4 not the Best sulution but it works, i have moddified the code from FirstScribe and added to the CartController from @obigroup

here is the code hope that helps.

`public function updateItemOptionsAction() {

    $cart   = $this->_getCart();
    $params = $this->getRequest()->getParams();
    $product = $this->_initProduct();

    //$id = (int)$this->getRequest()->getParam('id');
    $id = $product->getId();
    $quoteItem = $cart->getQuote()->getItemById($id);

    $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($id);
    if (is_array($parentIds) && count($parentIds))
    {
        $id = current($parentIds);
    }
    $_product= Mage::getModel('catalog/product')->load($id);

    if ($_product->getTypeId() == 'configurable')
    {
        $old_product_item_id = (int) $params['id'];
        unset($params['id']);
        $new_product = $this->_initProduct();
        try 
        {

            $cart->removeItem($old_product_item_id);
            $cart->addProduct($new_product, $params);
            $cart->save();
            $this->_getSession()->setCartWasUpdated(true);
            $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($new_product->getName()));
            $this->_getSession()->addSuccess($message);
        } 
        catch (Exception $e) { }
    }

    else {

    $cart   = $this->_getCart();
    $id = (int) $this->getRequest()->getParam('id');
    $params = $this->getRequest()->getParams();

    if (!isset($params['options'])) {
        $params['options'] = array();
    }
    try {
        if (isset($params['qty'])) {
            $filter = new Zend_Filter_LocalizedToNormalized(
                array('locale' => Mage::app()->getLocale()->getLocaleCode())
            );
            $params['qty'] = $filter->filter($params['qty']);
        }

        $quoteItem = $cart->getQuote()->getItemById($id);
        if (!$quoteItem) {
            Mage::throwException($this->__('Quote item is not found.'));
        }

        $item = $cart->updateItem($id, new Varien_Object($params));
        if (is_string($item)) {
            Mage::throwException($item);
        }
        if ($item->getHasError()) {
            Mage::throwException($item->getMessage());
        }

        $related = $this->getRequest()->getParam('related_product');
        if (!empty($related)) {
            $cart->addProductsByIds(explode(',', $related));
        }

        $cart->save();

        $this->_getSession()->setCartWasUpdated(true);

        Mage::dispatchEvent('checkout_cart_update_item_complete',
            array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())
        );
        if (!$this->_getSession()->getNoCartRedirect(true)) {
            if (!$cart->getQuote()->getHasError()) {
                $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
                $this->_getSession()->addSuccess($message);
            }
            $this->_goBack();
        }
    } catch (Mage_Core_Exception $e) {
        if ($this->_getSession()->getUseNotice(true)) {
            $this->_getSession()->addNotice($e->getMessage());
        } else {
            $messages = array_unique(explode("\n", $e->getMessage()));
            foreach ($messages as $message) {
                $this->_getSession()->addError($message);
            }
        }

        $url = $this->_getSession()->getRedirectUrl(true);
        if ($url) {
            $this->getResponse()->setRedirect($url);
        } else {
            $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
        }
    } catch (Exception $e) {
        $this->_getSession()->addException($e, $this->__('Cannot update the item.'));
        Mage::logException($e);
        $this->_goBack();
    }

    }

    $this->_redirect('checkout/cart');

}`

scretchy avatar Mar 21 '16 18:03 scretchy

@scretchy couldn't you make a pull request with your modification?

dannevang avatar Aug 30 '16 13:08 dannevang