Adding products to cart programmatically, sets item's price to zero. First time OnlyAdding First Product ProgrammaticallyChange the price in cart on the flyAdding a product to cart with different custom attributes inherits attributes of first itemWhen Adding a product to cart programatically ,the price of the product becomes zero ($0.00)Adding products to cart programmatically with custom price in controller: Magento 2adding and removing product from the cart at the same timeAdding product to magento 2 cart programmatically makes its price zeroMagento 2: Add a product to the cart programmaticallyRemoving Cart items - ObserverAdd product to quote in admin programmatically magento 2
How to discourage/prevent PCs from using door choke-points?
Gravity alteration as extermination tool viable?
Does splitting a potentially monolithic application into several smaller ones help prevent bugs?
BitNot does not flip bits in the way I expected
Single word request: Harming the benefactor
Replacing Windows 7 security updates with anti-virus?
Time-reversing a quantum computation: what does this mean for the future of physics and is it considered to be time travel?
What is the blue range indicating on this manifold pressure gauge?
What is the dot in “1.2.4."
When were linguistics departments first established
Is it true that real estate prices mainly go up?
Is this animal really missing?
Straight line with arrows and dots
Potentiometer like component
Confusion with the nameplate of an induction motor
Touchscreen-controlled dentist office snowman collector game
Unreachable code, but reachable with exception
Excess Zinc in garden soil
US to Europe trip with Canada layover- is 52 minutes enough?
Should I tell my boss the work he did was worthless
Best approach to update all entries in a list that is paginated?
If the Captain's screens are out, does he switch seats with the co-pilot?
Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?
How could our ancestors have domesticated a solitary predator?
Adding products to cart programmatically, sets item's price to zero. First time Only
Adding First Product ProgrammaticallyChange the price in cart on the flyAdding a product to cart with different custom attributes inherits attributes of first itemWhen Adding a product to cart programatically ,the price of the product becomes zero ($0.00)Adding products to cart programmatically with custom price in controller: Magento 2adding and removing product from the cart at the same timeAdding product to magento 2 cart programmatically makes its price zeroMagento 2: Add a product to the cart programmaticallyRemoving Cart items - ObserverAdd product to quote in admin programmatically magento 2
Certain products I have in my store have an attribute called setup_fee_sku.
If the product has this attribute I grab the value (which is a sku) load it, and add it to the cart programatically.
But the price is always set to 0 the first time its added, no matter what kind of sku it is.
https://imgur.com/a/WpXD8GH
After the item is in the cart for the first time, any other time it is added it contains the correct price.
https://imgur.com/a/5TqPfpL
I am doing my logic in an observer for event checkout_cart_add_product_complete
This is what my codes looks like
$setupSku = $product->getSetupFeeSku();
//Add setup fee to cart if it exists
if($setupSku != null)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$setupProduct = $objectManager->create('MagentoCatalogApiProductRepositoryInterface')->get($setupSku);
$formKey = $objectManager->create('MagentoFrameworkDataFormFormKey')->getFormKey();
$params = array(
'formKey' => $formKey,
'product' => $setupProduct->getId(),
'qty' => 100
);
$this->cart->addProduct($setupProduct, $params);
$this->cart->save();
magento2 addtocart quote
add a comment |
Certain products I have in my store have an attribute called setup_fee_sku.
If the product has this attribute I grab the value (which is a sku) load it, and add it to the cart programatically.
But the price is always set to 0 the first time its added, no matter what kind of sku it is.
https://imgur.com/a/WpXD8GH
After the item is in the cart for the first time, any other time it is added it contains the correct price.
https://imgur.com/a/5TqPfpL
I am doing my logic in an observer for event checkout_cart_add_product_complete
This is what my codes looks like
$setupSku = $product->getSetupFeeSku();
//Add setup fee to cart if it exists
if($setupSku != null)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$setupProduct = $objectManager->create('MagentoCatalogApiProductRepositoryInterface')->get($setupSku);
$formKey = $objectManager->create('MagentoFrameworkDataFormFormKey')->getFormKey();
$params = array(
'formKey' => $formKey,
'product' => $setupProduct->getId(),
'qty' => 100
);
$this->cart->addProduct($setupProduct, $params);
$this->cart->save();
magento2 addtocart quote
add a comment |
Certain products I have in my store have an attribute called setup_fee_sku.
If the product has this attribute I grab the value (which is a sku) load it, and add it to the cart programatically.
But the price is always set to 0 the first time its added, no matter what kind of sku it is.
https://imgur.com/a/WpXD8GH
After the item is in the cart for the first time, any other time it is added it contains the correct price.
https://imgur.com/a/5TqPfpL
I am doing my logic in an observer for event checkout_cart_add_product_complete
This is what my codes looks like
$setupSku = $product->getSetupFeeSku();
//Add setup fee to cart if it exists
if($setupSku != null)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$setupProduct = $objectManager->create('MagentoCatalogApiProductRepositoryInterface')->get($setupSku);
$formKey = $objectManager->create('MagentoFrameworkDataFormFormKey')->getFormKey();
$params = array(
'formKey' => $formKey,
'product' => $setupProduct->getId(),
'qty' => 100
);
$this->cart->addProduct($setupProduct, $params);
$this->cart->save();
magento2 addtocart quote
Certain products I have in my store have an attribute called setup_fee_sku.
If the product has this attribute I grab the value (which is a sku) load it, and add it to the cart programatically.
But the price is always set to 0 the first time its added, no matter what kind of sku it is.
https://imgur.com/a/WpXD8GH
After the item is in the cart for the first time, any other time it is added it contains the correct price.
https://imgur.com/a/5TqPfpL
I am doing my logic in an observer for event checkout_cart_add_product_complete
This is what my codes looks like
$setupSku = $product->getSetupFeeSku();
//Add setup fee to cart if it exists
if($setupSku != null)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$setupProduct = $objectManager->create('MagentoCatalogApiProductRepositoryInterface')->get($setupSku);
$formKey = $objectManager->create('MagentoFrameworkDataFormFormKey')->getFormKey();
$params = array(
'formKey' => $formKey,
'product' => $setupProduct->getId(),
'qty' => 100
);
$this->cart->addProduct($setupProduct, $params);
$this->cart->save();
magento2 addtocart quote
magento2 addtocart quote
asked 3 hours ago
Alex DonnellyAlex Donnelly
163
163
add a comment |
add a comment |
0
active
oldest
votes
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%2f265761%2fadding-products-to-cart-programmatically-sets-items-price-to-zero-first-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f265761%2fadding-products-to-cart-programmatically-sets-items-price-to-zero-first-time%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