Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. <?xml version="1.0"?> <config>
  2. <modules>
  3. <MyCommentBox_CommentBox>
  4. <active>true</active>
  5. <codePool>local</codePool>
  6. <depends>
  7. <Mage_Checkout/>
  8. </depends>
  9. </MyCommentBox_CommentBox>
  10. </modules> </config>
  11.  
  12. <?xml version="1.0" encoding="UTF-8"?><config>
  13. <modules>
  14. <MyExtensions_CommentBox>
  15. <version>0.1.0</version>
  16. </MyExtensions_CommentBox>
  17. </modules>
  18.  
  19. <frontend>
  20. <routers>
  21. <checkout>
  22. <args>
  23. <modules>
  24. <MyExtensions_CommentBox before="Mage_Checkout">MyExtensions_CommentBox</MyExtensions_CommentBox
  25. </modules>
  26. </args>
  27. </checkout>
  28. </routers>
  29. </frontend>
  30. </config>
  31.  
  32. require_once 'Mage/Checkout/controllers/CartController.php';
  33. class MyCommentBox_CommentBox_CartController extends Mage_Checkout_CartController {
  34.  
  35. public function addAction()
  36. {
  37. if (!$this->_validateFormKey()) {
  38. $this->_goBack();
  39. return;
  40. }
  41. $cart = $this->_getCart();
  42. $params = $this->getRequest()->getParams();
  43. try {
  44. if (isset($params['qty'])) {
  45. $filter = new Zend_Filter_LocalizedToNormalized(
  46. array('locale' => Mage::app()->getLocale()->getLocaleCode())
  47. );
  48. $params['qty'] = $filter->filter($params['qty']);
  49. }
  50.  
  51. $product = $this->_initProduct();
  52. $related = $this->getRequest()->getParam('related_product');
  53.  
  54. /**
  55. * Check product availability
  56. */
  57. if (!$product) {
  58. $this->_goBack();
  59. return;
  60. }
  61. /****************/
  62. /* Custom Params*/
  63. /****************/
  64. //Create custom option
  65. $additionalOptions = array(array(
  66. 'code' => 'my_code',
  67. 'label' => 'This text is displayed through additional options',
  68. 'value' => $this->getRequest()->getParam('textOpt');
  69. ));
  70. //Add Custom Option to product
  71. $product->addOption($item->addOption(array(
  72. 'code' => 'additional_options',
  73. 'value' => serialize($additionalOptions),
  74. ));
  75. /****************/
  76. $cart->addProduct($product, $params);
  77. if (!empty($related)) {
  78. $cart->addProductsByIds(explode(',', $related));
  79. }
  80.  
  81. $cart->save();
  82.  
  83. $this->_getSession()->setCartWasUpdated(true);
  84.  
  85. /**
  86. * @todo remove wishlist observer processAddToCart
  87. */
  88. Mage::dispatchEvent('checkout_cart_add_product_complete',
  89. array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
  90. );
  91.  
  92. if (!$this->_getSession()->getNoCartRedirect(true)) {
  93. if (!$cart->getQuote()->getHasError()) {
  94. $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
  95. $this->_getSession()->addSuccess($message);
  96. }
  97. $this->_goBack();
  98. }
  99. } catch (Mage_Core_Exception $e) {
  100. if ($this->_getSession()->getUseNotice(true)) {
  101. $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
  102. } else {
  103. $messages = array_unique(explode("n", $e->getMessage()));
  104. foreach ($messages as $message) {
  105. $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
  106. }
  107. }
  108.  
  109. $url = $this->_getSession()->getRedirectUrl(true);
  110. if ($url) {
  111. $this->getResponse()->setRedirect($url);
  112. } else {
  113. $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
  114. }
  115. } catch (Exception $e) {
  116. $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
  117. Mage::logException($e);
  118. $this->_goBack();
  119. }
  120. }
  121.  
  122. }
  123.  
  124. /****************/
  125. /* Custom Params*/
  126. /****************/
  127. //Create custom option
  128. $additionalOptions = array(array(
  129. 'code' => 'my_code',
  130. 'label' => 'This text is displayed through additional options',
  131. 'value' => $this->getRequest()->getParam('textOpt');
  132. ));
  133. //Add Custom Option to product
  134. $product->addOption($item->addOption(array(
  135. 'code' => 'additional_options',
  136. 'value' => serialize($additionalOptions),
  137. ));
  138. /****************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement