How to override cartaddcontroller in magento 2?How to override cartcontroller in magento 2?How to get rid of Add All To Cart from WishlistHow to Override or Extend protected or parent function in Magento 2 using PluginCart page not Working in magento2Trouble with cart add moduleOverriding add cart moduleMagento 2: How to override newsletter Subscriber modelProceed to checkout redirects to empty cart pageMagento 2: I Want to add multiple product using checkboxMagento 1 with Php 7.2, add to cart error if product have option
Possible to set `foldexpr` using a function reference?
Lock in SQL Server and Oracle
How can I get precisely a certain cubic cm by changing the following factors?
Reverse the word in a string with the same order in javascript
Binary Numbers Magic Trick
Past Perfect Tense
What does "rf" mean in "rfkill"?
What is the range of this combined function?
Is it possible to measure lightning discharges as Nikola Tesla?
Do I have an "anti-research" personality?
Why do computer-science majors learn calculus?
Pressure to defend the relevance of one's area of mathematics
Sci-fi novel series with instant travel between planets through gates. A river runs through the gates
What does YCWCYODFTRFDTY mean?
How to replace the "space symbol" (squat-u) in listings?
What's the metal clinking sound at the end of credits in Avengers: Endgame?
A non-technological, repeating, visible object in the sky, holding its position in the sky for hours
How to determine the actual or "true" resolution of a digital photograph?
Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?
You look catfish vs You look like a catfish
In the time of the mishna, were there Jewish cities without courts?
What is the difference between `a[bc]d` (brackets) and `ab,cd` (braces)?
A question regarding using the definite article
Is it cheaper to drop cargo drop than to land it?
How to override cartaddcontroller in magento 2?
How to override cartcontroller in magento 2?How to get rid of Add All To Cart from WishlistHow to Override or Extend protected or parent function in Magento 2 using PluginCart page not Working in magento2Trouble with cart add moduleOverriding add cart moduleMagento 2: How to override newsletter Subscriber modelProceed to checkout redirects to empty cart pageMagento 2: I Want to add multiple product using checkboxMagento 1 with Php 7.2, add to cart error if product have option
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want this function in code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
(this is written in magento 1.9, I want to convert it into magento 2). But I cant add any new function in add controller. Any help will be appreciated.
public function buyXgetYfree()
$cart = $this->_getCart();
/* check if cart is empty */
if (!$this->_getCart()->getQuote()->getItemsCount())
return;
$buyProductXID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_product_id'));
$buyProductYID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_product_id'));
$buyProductXminQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_required_qty'));
$buyProductXmaxQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_limit_qty'));
$buyProductYDescription = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_description'));
$error="A BuyXGetY Extension cart error was detected!";
try
for($i = 0; $i < count($buyProductXID); $i++)
if (empty($buyProductYDescription[$i]))
$buyProductYDescription[$i]="free gift";
if (empty($buyProductXID[$i]))
$buyProductXID[$i]="0";
if (empty($buyProductYID[$i]))
$buyProductYID[$i]="0";
if (empty($buyProductXminQty[$i]))
$buyProductXminQty[$i]="999";
if (empty($buyProductXmaxQty[$i]))
$buyProductXmaxQty[$i]="0";
if ($buyProductXID[$i] !="0" && $buyProductYID[$i] !="0")
if ($this->isProductYUnique())
$this->buyXgetYfreeCartUpdate((int)$buyProductXID[$i],(int)$buyProductXminQty[$i],(int)$buyProductYID[$i],$buyProductYDescription[$i],(int)$buyProductXmaxQty[$i]);
else
$error = "Error in Buy X configuration - Product Y is not unique across all extension settings.";
throw new Exception($error);
break;
catch (Exception $ex)
$cart->getCheckoutSession()->addError($this->__($error));
$this->sendErrorEmail($error);
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="buy-x-get-y" type="StwBuyXGetYBuyXGetYPluginControllerCheckoutCartAdd" sortOrder="1" />
</type>
</config>
code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
namespace StwBuyXGetYBuyXGetYPluginControllerCheckoutCart;
class Add
public function aroundExecute(MagentoCheckoutControllerCartAdd $add, callable $proceed, OutputInterface $output)
$this->buyXgetYfree();
$returnValue = $proceed();
return $returnValue;
public function buyXgetYfree()
echo "buyXgetYfree"; // this is dummy content
magento2 cart overrides controllers addtocart
add a comment |
I want this function in code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
(this is written in magento 1.9, I want to convert it into magento 2). But I cant add any new function in add controller. Any help will be appreciated.
public function buyXgetYfree()
$cart = $this->_getCart();
/* check if cart is empty */
if (!$this->_getCart()->getQuote()->getItemsCount())
return;
$buyProductXID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_product_id'));
$buyProductYID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_product_id'));
$buyProductXminQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_required_qty'));
$buyProductXmaxQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_limit_qty'));
$buyProductYDescription = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_description'));
$error="A BuyXGetY Extension cart error was detected!";
try
for($i = 0; $i < count($buyProductXID); $i++)
if (empty($buyProductYDescription[$i]))
$buyProductYDescription[$i]="free gift";
if (empty($buyProductXID[$i]))
$buyProductXID[$i]="0";
if (empty($buyProductYID[$i]))
$buyProductYID[$i]="0";
if (empty($buyProductXminQty[$i]))
$buyProductXminQty[$i]="999";
if (empty($buyProductXmaxQty[$i]))
$buyProductXmaxQty[$i]="0";
if ($buyProductXID[$i] !="0" && $buyProductYID[$i] !="0")
if ($this->isProductYUnique())
$this->buyXgetYfreeCartUpdate((int)$buyProductXID[$i],(int)$buyProductXminQty[$i],(int)$buyProductYID[$i],$buyProductYDescription[$i],(int)$buyProductXmaxQty[$i]);
else
$error = "Error in Buy X configuration - Product Y is not unique across all extension settings.";
throw new Exception($error);
break;
catch (Exception $ex)
$cart->getCheckoutSession()->addError($this->__($error));
$this->sendErrorEmail($error);
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="buy-x-get-y" type="StwBuyXGetYBuyXGetYPluginControllerCheckoutCartAdd" sortOrder="1" />
</type>
</config>
code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
namespace StwBuyXGetYBuyXGetYPluginControllerCheckoutCart;
class Add
public function aroundExecute(MagentoCheckoutControllerCartAdd $add, callable $proceed, OutputInterface $output)
$this->buyXgetYfree();
$returnValue = $proceed();
return $returnValue;
public function buyXgetYfree()
echo "buyXgetYfree"; // this is dummy content
magento2 cart overrides controllers addtocart
add a comment |
I want this function in code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
(this is written in magento 1.9, I want to convert it into magento 2). But I cant add any new function in add controller. Any help will be appreciated.
public function buyXgetYfree()
$cart = $this->_getCart();
/* check if cart is empty */
if (!$this->_getCart()->getQuote()->getItemsCount())
return;
$buyProductXID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_product_id'));
$buyProductYID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_product_id'));
$buyProductXminQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_required_qty'));
$buyProductXmaxQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_limit_qty'));
$buyProductYDescription = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_description'));
$error="A BuyXGetY Extension cart error was detected!";
try
for($i = 0; $i < count($buyProductXID); $i++)
if (empty($buyProductYDescription[$i]))
$buyProductYDescription[$i]="free gift";
if (empty($buyProductXID[$i]))
$buyProductXID[$i]="0";
if (empty($buyProductYID[$i]))
$buyProductYID[$i]="0";
if (empty($buyProductXminQty[$i]))
$buyProductXminQty[$i]="999";
if (empty($buyProductXmaxQty[$i]))
$buyProductXmaxQty[$i]="0";
if ($buyProductXID[$i] !="0" && $buyProductYID[$i] !="0")
if ($this->isProductYUnique())
$this->buyXgetYfreeCartUpdate((int)$buyProductXID[$i],(int)$buyProductXminQty[$i],(int)$buyProductYID[$i],$buyProductYDescription[$i],(int)$buyProductXmaxQty[$i]);
else
$error = "Error in Buy X configuration - Product Y is not unique across all extension settings.";
throw new Exception($error);
break;
catch (Exception $ex)
$cart->getCheckoutSession()->addError($this->__($error));
$this->sendErrorEmail($error);
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="buy-x-get-y" type="StwBuyXGetYBuyXGetYPluginControllerCheckoutCartAdd" sortOrder="1" />
</type>
</config>
code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
namespace StwBuyXGetYBuyXGetYPluginControllerCheckoutCart;
class Add
public function aroundExecute(MagentoCheckoutControllerCartAdd $add, callable $proceed, OutputInterface $output)
$this->buyXgetYfree();
$returnValue = $proceed();
return $returnValue;
public function buyXgetYfree()
echo "buyXgetYfree"; // this is dummy content
magento2 cart overrides controllers addtocart
I want this function in code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
(this is written in magento 1.9, I want to convert it into magento 2). But I cant add any new function in add controller. Any help will be appreciated.
public function buyXgetYfree()
$cart = $this->_getCart();
/* check if cart is empty */
if (!$this->_getCart()->getQuote()->getItemsCount())
return;
$buyProductXID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_product_id'));
$buyProductYID = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_product_id'));
$buyProductXminQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_required_qty'));
$buyProductXmaxQty = explode (",",Mage::getStoreConfig('buyxgety_section1/general/productx_limit_qty'));
$buyProductYDescription = explode (",",Mage::getStoreConfig('buyxgety_section1/general/producty_description'));
$error="A BuyXGetY Extension cart error was detected!";
try
for($i = 0; $i < count($buyProductXID); $i++)
if (empty($buyProductYDescription[$i]))
$buyProductYDescription[$i]="free gift";
if (empty($buyProductXID[$i]))
$buyProductXID[$i]="0";
if (empty($buyProductYID[$i]))
$buyProductYID[$i]="0";
if (empty($buyProductXminQty[$i]))
$buyProductXminQty[$i]="999";
if (empty($buyProductXmaxQty[$i]))
$buyProductXmaxQty[$i]="0";
if ($buyProductXID[$i] !="0" && $buyProductYID[$i] !="0")
if ($this->isProductYUnique())
$this->buyXgetYfreeCartUpdate((int)$buyProductXID[$i],(int)$buyProductXminQty[$i],(int)$buyProductYID[$i],$buyProductYDescription[$i],(int)$buyProductXmaxQty[$i]);
else
$error = "Error in Buy X configuration - Product Y is not unique across all extension settings.";
throw new Exception($error);
break;
catch (Exception $ex)
$cart->getCheckoutSession()->addError($this->__($error));
$this->sendErrorEmail($error);
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="buy-x-get-y" type="StwBuyXGetYBuyXGetYPluginControllerCheckoutCartAdd" sortOrder="1" />
</type>
</config>
code StwBuyXGetY BuyXGetY ControllerCheckoutCartAdd.php
namespace StwBuyXGetYBuyXGetYPluginControllerCheckoutCart;
class Add
public function aroundExecute(MagentoCheckoutControllerCartAdd $add, callable $proceed, OutputInterface $output)
$this->buyXgetYfree();
$returnValue = $proceed();
return $returnValue;
public function buyXgetYfree()
echo "buyXgetYfree"; // this is dummy content
magento2 cart overrides controllers addtocart
magento2 cart overrides controllers addtocart
edited Aug 17 '16 at 6:59
Keerthana
asked Aug 17 '16 at 6:32
KeerthanaKeerthana
169319
169319
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Change your plugin controller to following
class Add
public function aroundExecute(
MagentoCheckoutControllerCartAdd $subject,
Closure $proceed
)
$this->buyXgetYfree();
return $proceed();
public function buyXgetYfree()
error_log('buyXgetYfree');
When you press addtocart button, basically it's not return any 'echo' content. So you can use error_log or magento 2 log system for checking.
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
add a comment |
$writer = new ZendLogWriterStream(BP . '/var/log/addToCart.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->debug(__METHOD__);
Sohel is right, it does not show your echo if you try to add to cart. You can try this one and check your log at var/log/addToCart.log
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f131716%2fhow-to-override-cart-addcontroller-in-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change your plugin controller to following
class Add
public function aroundExecute(
MagentoCheckoutControllerCartAdd $subject,
Closure $proceed
)
$this->buyXgetYfree();
return $proceed();
public function buyXgetYfree()
error_log('buyXgetYfree');
When you press addtocart button, basically it's not return any 'echo' content. So you can use error_log or magento 2 log system for checking.
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
add a comment |
Change your plugin controller to following
class Add
public function aroundExecute(
MagentoCheckoutControllerCartAdd $subject,
Closure $proceed
)
$this->buyXgetYfree();
return $proceed();
public function buyXgetYfree()
error_log('buyXgetYfree');
When you press addtocart button, basically it's not return any 'echo' content. So you can use error_log or magento 2 log system for checking.
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
add a comment |
Change your plugin controller to following
class Add
public function aroundExecute(
MagentoCheckoutControllerCartAdd $subject,
Closure $proceed
)
$this->buyXgetYfree();
return $proceed();
public function buyXgetYfree()
error_log('buyXgetYfree');
When you press addtocart button, basically it's not return any 'echo' content. So you can use error_log or magento 2 log system for checking.
Change your plugin controller to following
class Add
public function aroundExecute(
MagentoCheckoutControllerCartAdd $subject,
Closure $proceed
)
$this->buyXgetYfree();
return $proceed();
public function buyXgetYfree()
error_log('buyXgetYfree');
When you press addtocart button, basically it's not return any 'echo' content. So you can use error_log or magento 2 log system for checking.
answered Aug 17 '16 at 13:21
Sohel RanaSohel Rana
23.7k34461
23.7k34461
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
add a comment |
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
this solution is not working for me, error log is not displaying.
– Keerthana
Aug 22 '16 at 6:09
add a comment |
$writer = new ZendLogWriterStream(BP . '/var/log/addToCart.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->debug(__METHOD__);
Sohel is right, it does not show your echo if you try to add to cart. You can try this one and check your log at var/log/addToCart.log
add a comment |
$writer = new ZendLogWriterStream(BP . '/var/log/addToCart.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->debug(__METHOD__);
Sohel is right, it does not show your echo if you try to add to cart. You can try this one and check your log at var/log/addToCart.log
add a comment |
$writer = new ZendLogWriterStream(BP . '/var/log/addToCart.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->debug(__METHOD__);
Sohel is right, it does not show your echo if you try to add to cart. You can try this one and check your log at var/log/addToCart.log
$writer = new ZendLogWriterStream(BP . '/var/log/addToCart.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->debug(__METHOD__);
Sohel is right, it does not show your echo if you try to add to cart. You can try this one and check your log at var/log/addToCart.log
answered Jul 18 '18 at 6:23
Adrian PaulAdrian Paul
145
145
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f131716%2fhow-to-override-cart-addcontroller-in-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown