getRequest()->getParam('product'); if ($productId) { $product = Mage::getModel('catalog/product') ->setStoreId(Mage::app()->getStore()->getId()) ->load($productId); if ($product->getId()) { return $product; } } return false; } /** * Set back redirect url to response * * @return Mage_Checkout_CartController * @throws Mage_Exception */ protected function _goBack() { $returnUrl = $this->getRequest()->getParam('return_url'); if ($returnUrl) { if (!$this->_isUrlInternal($returnUrl)) { throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!'); } $this->_getSession()->getMessages(true); $this->getResponse()->setRedirect($returnUrl); } elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart') && !$this->getRequest()->getParam('in_cart') && $backUrl = $this->_getRefererUrl() ) { $this->getResponse()->setRedirect($backUrl); } else { if ((strtolower($this->getRequest()->getActionName()) == 'add') && !$this->getRequest()->getParam('in_cart')) { $this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl()); } $this->_redirect('checkout/cart'); } return $this; } /** * * Add product with multicolor attribute to shopping cart * * @return Mage_Core_Controller_Varien_Action * @throws Exception */ public function addAction() { if (!$this->_validateFormKey()) { $this->_goBack(); return; } $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); $_productUrl = Mage::getModel('catalog/product')->load($params['product'])->getUrlPath(); $namesOfAddedProducts = array(); $optionsAreChosen = false; $super_attribute_id = $params['super_attribute']; foreach ($params as $color_id => $color_quantity) { try { if (!is_numeric($color_id)) { continue; } else { $params['qty'] = $color_quantity; if ($color_quantity == 0) { continue; } else { $optionsAreChosen = true; $params['super_attribute'] = array( $super_attribute_id => $color_id ); $product = $this->_initProduct(); //getting simple product $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product); $related = $this->getRequest()->getParam('related_product'); // Check product availability if (!$product) { $this->_goBack(); return; } if (Mage::helper('orange35_colorpicker')->productIsAvailableForSale($child)) { $cart->addProduct($product, $params); array_push($namesOfAddedProducts, $child->getName()); } else { $this->_getSession()->addError(Mage::helper('core')->escapeHtml("Sorry, product " . $child->getName() . " is currently out of stock or not available")); } if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } } } } catch (Mage_Core_Exception $e) { if ($this->_getSession()->getUseNotice(true)) { $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage())); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message)); } } } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('Cannot add the '. $child->getName() .' to shopping cart.')); } } $cart->save(); $this->_getSession()->setCartWasUpdated(true); if (!$this->_getSession()->getNoCartRedirect(true)) { // if (!$cart->getQuote()->getHasError()) { if (sizeof($namesOfAddedProducts) >= 1) { $message = implode(", ",$namesOfAddedProducts); if (sizeof($namesOfAddedProducts) > 1) { $message = $this->__('%s were added to your shopping cart.', Mage::helper('core')->escapeHtml($message)); } else { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($message)); } $this->_getSession()->addSuccess($message); $message = ""; } if (!$optionsAreChosen) { $message = $this->__('Please specify product\'s option(s)'); $this->_getSession()->addNotice($message); $this->_redirect($_productUrl); return; } //} $this->_goBack(); } } }