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













0















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();










share|improve this question


























    0















    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();










    share|improve this question
























      0












      0








      0








      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();










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      Alex DonnellyAlex Donnelly

      163




      163




















          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
          );



          );













          draft saved

          draft discarded


















          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















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Best approach to update all entries in a list that is paginated?Best way to add items to a paginated listChoose Your Country: Best Usability approachUpdate list when a user is viewing the list without annoying themWhen would the best day to update your webpage be?What should happen when I add a Row to a paginated, sorted listShould I adopt infinite scrolling or classical pagination?How to show user that page objects automatically updateWhat is the best location to locate the comments section in a list pageBest way to combine filtering and selecting items in a listWhen one of two inputs must be updated to satisfy a consistency criteria, which should you update (if at all)?

          Вунгтау (аеропорт) Загальні відомості | Див. також | Посилання | Навігаційне меню10°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.0833310°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.083337731608Vinh AirportVinh airport facelift improves serviceвиправивши або дописавши їївиправивши або дописавши їїр

          Тонконіг бульбистий Зміст Опис | Поширення | Екологія | Господарське значення | Примітки | Див. також | Література | Джерела | Посилання | Навігаційне меню1114601320038-241116202404kew-435458Poa bulbosaЭлектронный каталог сосудистых растений Азиатской России [Електронний каталог судинних рослин Азіатської Росії]Малышев Л. Л. Дикие родичи культурных растений. Poa bulbosa L. - Мятлик луковичный. [Малишев Л. Л. Дикі родичи культурних рослин. Poa bulbosa L. - Тонконіг бульбистий.]Мятлик (POA) Сем. Злаки (Мятликовые) [Тонконіг (POA) Род. Злаки (Тонконогові)]Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Description from Flora of China) [Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Опис від Флора Китаю)]Poa bulbosa L. – lipnice cibulkatá / lipnica cibulkatáPoa bulbosa в базі даних Poa bulbosa на сайті Poa bulbosa в базі даних «Global Biodiversity Information Facility» (GBIF)Poa bulbosa в базі даних «Euro + Med PlantBase» — інформаційному ресурсі для Євро-середземноморського розмаїття рослинPoa bulbosa L. на сайті «Плантариум»