Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0"?> <config>
- <modules>
- <MyCommentBox_CommentBox>
- <active>true</active>
- <codePool>local</codePool>
- <depends>
- <Mage_Checkout/>
- </depends>
- </MyCommentBox_CommentBox>
- </modules> </config>
- <?xml version="1.0" encoding="UTF-8"?><config>
- <modules>
- <MyExtensions_CommentBox>
- <version>0.1.0</version>
- </MyExtensions_CommentBox>
- </modules>
- <frontend>
- <routers>
- <checkout>
- <args>
- <modules>
- <MyExtensions_CommentBox before="Mage_Checkout">MyExtensions_CommentBox</MyExtensions_CommentBox
- </modules>
- </args>
- </checkout>
- </routers>
- </frontend>
- </config>
- require_once 'Mage/Checkout/controllers/CartController.php';
- class MyCommentBox_CommentBox_CartController extends Mage_Checkout_CartController {
- public function addAction()
- {
- if (!$this->_validateFormKey()) {
- $this->_goBack();
- return;
- }
- $cart = $this->_getCart();
- $params = $this->getRequest()->getParams();
- try {
- if (isset($params['qty'])) {
- $filter = new Zend_Filter_LocalizedToNormalized(
- array('locale' => Mage::app()->getLocale()->getLocaleCode())
- );
- $params['qty'] = $filter->filter($params['qty']);
- }
- $product = $this->_initProduct();
- $related = $this->getRequest()->getParam('related_product');
- /**
- * Check product availability
- */
- if (!$product) {
- $this->_goBack();
- return;
- }
- /****************/
- /* Custom Params*/
- /****************/
- //Create custom option
- $additionalOptions = array(array(
- 'code' => 'my_code',
- 'label' => 'This text is displayed through additional options',
- 'value' => $this->getRequest()->getParam('textOpt');
- ));
- //Add Custom Option to product
- $product->addOption($item->addOption(array(
- 'code' => 'additional_options',
- 'value' => serialize($additionalOptions),
- ));
- /****************/
- $cart->addProduct($product, $params);
- if (!empty($related)) {
- $cart->addProductsByIds(explode(',', $related));
- }
- $cart->save();
- $this->_getSession()->setCartWasUpdated(true);
- /**
- * @todo remove wishlist observer processAddToCart
- */
- Mage::dispatchEvent('checkout_cart_add_product_complete',
- array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
- );
- if (!$this->_getSession()->getNoCartRedirect(true)) {
- if (!$cart->getQuote()->getHasError()) {
- $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
- $this->_getSession()->addSuccess($message);
- }
- $this->_goBack();
- }
- } 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));
- }
- }
- $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 add the item to shopping cart.'));
- Mage::logException($e);
- $this->_goBack();
- }
- }
- }
- /****************/
- /* Custom Params*/
- /****************/
- //Create custom option
- $additionalOptions = array(array(
- 'code' => 'my_code',
- 'label' => 'This text is displayed through additional options',
- 'value' => $this->getRequest()->getParam('textOpt');
- ));
- //Add Custom Option to product
- $product->addOption($item->addOption(array(
- 'code' => 'additional_options',
- 'value' => serialize($additionalOptions),
- ));
- /****************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement