magento 2 add to cart observer modify priceSet custom price of product when adding to cart code not workingMagento 2 - custom price can not add to subtotal and grand total after add to cartChange product price in cart each page loaded with observerHow to get quote item id in checkout_cart_product_add_after observer in magento2Set item price added to cartMagento-2 : How to set product custom price after add to cartMagento 2: I Want to add multiple product using checkboxRemoving Cart items - ObserverI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options
Schwa-less Polysyllabic German Noun Stems of Germanic Origin
Gambler's Fallacy Dice
Farthing / Riding
How could the B-29 bomber back up under its own power?
Requirement for splicing neutrals in a switch
Do seaplanes need to get clearance for takeoff?
How did Jean Parisot de Valette, 49th Grand Master of the Order of Malta, die?
Separate the element after every 2nd ',' and push into next row in bash
Simple Arithmetic Puzzle 7. Or is it?
Germany rejected my entry to Schengen countries
If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?
Why is this python script running in background consuming 100 % CPU?
Are there historical examples of audiences drawn to a work that was "so bad it's good"?
US F1 Visa grace period attending a conference
Removing Doubles Destroy Topology
Which one of these Isp's for the Dawn spacecraft is wrong?
Vehemently against code formatting
Is it wise to pay off mortgage with 401k?
What Species of Trees are These?
Does science define life as "beginning at conception"?
How do we properly manage transitions within a descriptive section?
Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario?
How to tease a romance without a cat and mouse chase?
Ribbon Cable Cross Talk - Is there a fix after the fact?
magento 2 add to cart observer modify price
Set custom price of product when adding to cart code not workingMagento 2 - custom price can not add to subtotal and grand total after add to cartChange product price in cart each page loaded with observerHow to get quote item id in checkout_cart_product_add_after observer in magento2Set item price added to cartMagento-2 : How to set product custom price after add to cartMagento 2: I Want to add multiple product using checkboxRemoving Cart items - ObserverI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Wel i have plugin which shows price in frontend from custom attribute.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
return $price;
Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before
public function execute(
MagentoFrameworkEventObserver $observer
)
$item = $observer->getEvent()->getData('product');
if($item->getData('price_per_area'))
$item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));
and here i have issue:
product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price
as you can see from screenshots the price which is shown in summary is correct in both cases.
also tried my observer with checkout_cart_product_add_after
result was same. tried with custom theme and luma
is it magento/template bug or there is some work around ?
magento2 magento2.3.1
add a comment |
Wel i have plugin which shows price in frontend from custom attribute.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
return $price;
Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before
public function execute(
MagentoFrameworkEventObserver $observer
)
$item = $observer->getEvent()->getData('product');
if($item->getData('price_per_area'))
$item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));
and here i have issue:
product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price
as you can see from screenshots the price which is shown in summary is correct in both cases.
also tried my observer with checkout_cart_product_add_after
result was same. tried with custom theme and luma
is it magento/template bug or there is some work around ?
magento2 magento2.3.1
add a comment |
Wel i have plugin which shows price in frontend from custom attribute.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
return $price;
Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before
public function execute(
MagentoFrameworkEventObserver $observer
)
$item = $observer->getEvent()->getData('product');
if($item->getData('price_per_area'))
$item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));
and here i have issue:
product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price
as you can see from screenshots the price which is shown in summary is correct in both cases.
also tried my observer with checkout_cart_product_add_after
result was same. tried with custom theme and luma
is it magento/template bug or there is some work around ?
magento2 magento2.3.1
Wel i have plugin which shows price in frontend from custom attribute.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
return $price;
Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before
public function execute(
MagentoFrameworkEventObserver $observer
)
$item = $observer->getEvent()->getData('product');
if($item->getData('price_per_area'))
$item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));
and here i have issue:
product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price
as you can see from screenshots the price which is shown in summary is correct in both cases.
also tried my observer with checkout_cart_product_add_after
result was same. tried with custom theme and luma
is it magento/template bug or there is some work around ?
magento2 magento2.3.1
magento2 magento2.3.1
asked May 14 at 11:49
Naberd ZendiNaberd Zendi
626
626
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Found out what caused this bug.
it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.
modified my plugin code so it will not affect checkout prices.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) //per meter
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
$moduleName = $requestInterface->getModuleName();
if($product->getData('price_per_area'))
if($moduleName != 'checkout')
$price = $product->getData('price_per_area');
return $price;
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%2f274537%2fmagento-2-add-to-cart-observer-modify-price%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Found out what caused this bug.
it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.
modified my plugin code so it will not affect checkout prices.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) //per meter
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
$moduleName = $requestInterface->getModuleName();
if($product->getData('price_per_area'))
if($moduleName != 'checkout')
$price = $product->getData('price_per_area');
return $price;
add a comment |
Found out what caused this bug.
it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.
modified my plugin code so it will not affect checkout prices.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) //per meter
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
$moduleName = $requestInterface->getModuleName();
if($product->getData('price_per_area'))
if($moduleName != 'checkout')
$price = $product->getData('price_per_area');
return $price;
add a comment |
Found out what caused this bug.
it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.
modified my plugin code so it will not affect checkout prices.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) //per meter
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
$moduleName = $requestInterface->getModuleName();
if($product->getData('price_per_area'))
if($moduleName != 'checkout')
$price = $product->getData('price_per_area');
return $price;
Found out what caused this bug.
it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.
modified my plugin code so it will not affect checkout prices.
public function afterGetPrice(MagentoCatalogModelProduct $product, $price)
if($product->getData('price_per_area')) //per meter
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
$moduleName = $requestInterface->getModuleName();
if($product->getData('price_per_area'))
if($moduleName != 'checkout')
$price = $product->getData('price_per_area');
return $price;
answered May 14 at 13:32
Naberd ZendiNaberd Zendi
626
626
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%2f274537%2fmagento-2-add-to-cart-observer-modify-price%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