Order “non-existant” productSuggestions needed: Adding fake product to cart and bring it to order

Why did the World Bank set the global poverty line at $1.90?

If there's something that implicates the president why is there then a national security issue? (John Dowd)

Why Does Mama Coco Look Old After Going to the Other World?

Analogy between an unknown in an argument, and a contradiction in the principle of explosion

Can the removal of a duty-free sales trolley result in a measurable reduction in emissions?

What STL algorithm can determine if exactly one item in a container satisfies a predicate?

What would be the way to say "just saying" in German? (Not the literal translation)

Was planting UN flag on Moon ever discussed?

How to avoid typing 'git' at the begining of every Git command

Do you have to have figures when playing D&D?

TicTacToe classic in C

Do you need to let the DM know when you are multiclassing?

Why do radiation hardened IC packages often have long leads?

Did Apple bundle a specific monitor with the Apple II+ for schools?

Amplitude of a crest and trough in a sound wave?

Grep Match and extract

Increase speed altering column on large table to NON NULL

Can we completely replace inheritance using strategy pattern and dependency injection?

Who is "He that flies" in Lord of the Rings?

Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?

Why is Na5 not played in this line of the French Defense, Advance Variation?

Can I utilise a baking stone to make crepes?

Getting UPS Power from One Room to Another

How can one's career as a reviewer be ended?



Order “non-existant” product


Suggestions needed: Adding fake product to cart and bring it to order






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have my products repository externally and only use Magento 2 to actually order these items. Similar to this question here but unfortunaly that does not have an answer or specifics about implementation. Magento should not have access to the entire repository so I do not want to create a provider for that.



Currently I have my controller implemented to add a generic product to the cart and then differenciate them using an "sku" option.



The generic "order" object Magento is getting is as follows:



[

"sku": "EV4-HI-TML90180",
"options": [...],
"price": 213.00
,

"sku": "ETM-SGR-2010",
"options": [...],
"price": 321.00
,
]


I am adding this to the cart as follows:



private function addItemToCart(CartItem $item)

$product = $this->getProductBySku("simpleproduct");

// Set the name and the price of the product.
// TODO: Fix name being "Simple product" in the cart.
$product->setName($item->getSku());
$product->setPrice($item->getPrice());

// Fetch the SKU option for the generic product
$option = $this->getOptionBySku($product, 'eg-sku');
$product->addCustomOption('option_ids', $option->getData('option_id'));
$product->addCustomOption('option_'.$option->getData('option_id'),
$item->getSku()); // Set the SKU option value.

$cartItem = $this->itemFactory->create();
$cartItem->setName($item->getSku());
$cartItem->setCustomPrice($item->getPrice());
$cartItem->setOriginalCustomPrice($item->getPrice());
$cartItem->setProduct($product);

$this->cart->getQuote()->addItem($cartItem);



But it is complaining about dividing by 0 (WTF?)



Warning: Division by zero in /var/www/html/vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php on line 158









share|improve this question




























    0















    I have my products repository externally and only use Magento 2 to actually order these items. Similar to this question here but unfortunaly that does not have an answer or specifics about implementation. Magento should not have access to the entire repository so I do not want to create a provider for that.



    Currently I have my controller implemented to add a generic product to the cart and then differenciate them using an "sku" option.



    The generic "order" object Magento is getting is as follows:



    [

    "sku": "EV4-HI-TML90180",
    "options": [...],
    "price": 213.00
    ,

    "sku": "ETM-SGR-2010",
    "options": [...],
    "price": 321.00
    ,
    ]


    I am adding this to the cart as follows:



    private function addItemToCart(CartItem $item)

    $product = $this->getProductBySku("simpleproduct");

    // Set the name and the price of the product.
    // TODO: Fix name being "Simple product" in the cart.
    $product->setName($item->getSku());
    $product->setPrice($item->getPrice());

    // Fetch the SKU option for the generic product
    $option = $this->getOptionBySku($product, 'eg-sku');
    $product->addCustomOption('option_ids', $option->getData('option_id'));
    $product->addCustomOption('option_'.$option->getData('option_id'),
    $item->getSku()); // Set the SKU option value.

    $cartItem = $this->itemFactory->create();
    $cartItem->setName($item->getSku());
    $cartItem->setCustomPrice($item->getPrice());
    $cartItem->setOriginalCustomPrice($item->getPrice());
    $cartItem->setProduct($product);

    $this->cart->getQuote()->addItem($cartItem);



    But it is complaining about dividing by 0 (WTF?)



    Warning: Division by zero in /var/www/html/vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php on line 158









    share|improve this question
























      0












      0








      0








      I have my products repository externally and only use Magento 2 to actually order these items. Similar to this question here but unfortunaly that does not have an answer or specifics about implementation. Magento should not have access to the entire repository so I do not want to create a provider for that.



      Currently I have my controller implemented to add a generic product to the cart and then differenciate them using an "sku" option.



      The generic "order" object Magento is getting is as follows:



      [

      "sku": "EV4-HI-TML90180",
      "options": [...],
      "price": 213.00
      ,

      "sku": "ETM-SGR-2010",
      "options": [...],
      "price": 321.00
      ,
      ]


      I am adding this to the cart as follows:



      private function addItemToCart(CartItem $item)

      $product = $this->getProductBySku("simpleproduct");

      // Set the name and the price of the product.
      // TODO: Fix name being "Simple product" in the cart.
      $product->setName($item->getSku());
      $product->setPrice($item->getPrice());

      // Fetch the SKU option for the generic product
      $option = $this->getOptionBySku($product, 'eg-sku');
      $product->addCustomOption('option_ids', $option->getData('option_id'));
      $product->addCustomOption('option_'.$option->getData('option_id'),
      $item->getSku()); // Set the SKU option value.

      $cartItem = $this->itemFactory->create();
      $cartItem->setName($item->getSku());
      $cartItem->setCustomPrice($item->getPrice());
      $cartItem->setOriginalCustomPrice($item->getPrice());
      $cartItem->setProduct($product);

      $this->cart->getQuote()->addItem($cartItem);



      But it is complaining about dividing by 0 (WTF?)



      Warning: Division by zero in /var/www/html/vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php on line 158









      share|improve this question














      I have my products repository externally and only use Magento 2 to actually order these items. Similar to this question here but unfortunaly that does not have an answer or specifics about implementation. Magento should not have access to the entire repository so I do not want to create a provider for that.



      Currently I have my controller implemented to add a generic product to the cart and then differenciate them using an "sku" option.



      The generic "order" object Magento is getting is as follows:



      [

      "sku": "EV4-HI-TML90180",
      "options": [...],
      "price": 213.00
      ,

      "sku": "ETM-SGR-2010",
      "options": [...],
      "price": 321.00
      ,
      ]


      I am adding this to the cart as follows:



      private function addItemToCart(CartItem $item)

      $product = $this->getProductBySku("simpleproduct");

      // Set the name and the price of the product.
      // TODO: Fix name being "Simple product" in the cart.
      $product->setName($item->getSku());
      $product->setPrice($item->getPrice());

      // Fetch the SKU option for the generic product
      $option = $this->getOptionBySku($product, 'eg-sku');
      $product->addCustomOption('option_ids', $option->getData('option_id'));
      $product->addCustomOption('option_'.$option->getData('option_id'),
      $item->getSku()); // Set the SKU option value.

      $cartItem = $this->itemFactory->create();
      $cartItem->setName($item->getSku());
      $cartItem->setCustomPrice($item->getPrice());
      $cartItem->setOriginalCustomPrice($item->getPrice());
      $cartItem->setProduct($product);

      $this->cart->getQuote()->addItem($cartItem);



      But it is complaining about dividing by 0 (WTF?)



      Warning: Division by zero in /var/www/html/vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php on line 158






      magento2 addtocart products






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 3 at 12:43









      tvanrieltvanriel

      208




      208




















          1 Answer
          1






          active

          oldest

          votes


















          0














          I ended up solving it using an Observer that listens for products being added to the cart, and then update the item. Rather than the controller.



          etc/event.xml



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
          <event name="checkout_cart_product_add_after">
          <observer name="customprice" instance="VendorModuleObserverObserver" />
          </event>
          </config>



          Observer.php



          public function execute(Observer $observer)

          $item = $observer->getEvent()->getData('quote_item');
          $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); // Set the parent item if item is virtual
          $price = $item->getProduct()->getPrice(); // Get the price from the product
          $item->setCustomPrice($price); // Set it over the item
          $item->setOriginalCustomPrice($price); // Forget that it was changed, so magento wont change it back randomly
          $item->getProduct()->setIsSuperMode(true);



          This still shows the name of the "generic" product in the cart, not the SKU of the non-existant product.






          share|improve this answer























            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%2f277084%2forder-non-existant-product%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









            0














            I ended up solving it using an Observer that listens for products being added to the cart, and then update the item. Rather than the controller.



            etc/event.xml



            <?xml version="1.0"?>
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
            <event name="checkout_cart_product_add_after">
            <observer name="customprice" instance="VendorModuleObserverObserver" />
            </event>
            </config>



            Observer.php



            public function execute(Observer $observer)

            $item = $observer->getEvent()->getData('quote_item');
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); // Set the parent item if item is virtual
            $price = $item->getProduct()->getPrice(); // Get the price from the product
            $item->setCustomPrice($price); // Set it over the item
            $item->setOriginalCustomPrice($price); // Forget that it was changed, so magento wont change it back randomly
            $item->getProduct()->setIsSuperMode(true);



            This still shows the name of the "generic" product in the cart, not the SKU of the non-existant product.






            share|improve this answer



























              0














              I ended up solving it using an Observer that listens for products being added to the cart, and then update the item. Rather than the controller.



              etc/event.xml



              <?xml version="1.0"?>
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
              <event name="checkout_cart_product_add_after">
              <observer name="customprice" instance="VendorModuleObserverObserver" />
              </event>
              </config>



              Observer.php



              public function execute(Observer $observer)

              $item = $observer->getEvent()->getData('quote_item');
              $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); // Set the parent item if item is virtual
              $price = $item->getProduct()->getPrice(); // Get the price from the product
              $item->setCustomPrice($price); // Set it over the item
              $item->setOriginalCustomPrice($price); // Forget that it was changed, so magento wont change it back randomly
              $item->getProduct()->setIsSuperMode(true);



              This still shows the name of the "generic" product in the cart, not the SKU of the non-existant product.






              share|improve this answer

























                0












                0








                0







                I ended up solving it using an Observer that listens for products being added to the cart, and then update the item. Rather than the controller.



                etc/event.xml



                <?xml version="1.0"?>
                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
                <event name="checkout_cart_product_add_after">
                <observer name="customprice" instance="VendorModuleObserverObserver" />
                </event>
                </config>



                Observer.php



                public function execute(Observer $observer)

                $item = $observer->getEvent()->getData('quote_item');
                $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); // Set the parent item if item is virtual
                $price = $item->getProduct()->getPrice(); // Get the price from the product
                $item->setCustomPrice($price); // Set it over the item
                $item->setOriginalCustomPrice($price); // Forget that it was changed, so magento wont change it back randomly
                $item->getProduct()->setIsSuperMode(true);



                This still shows the name of the "generic" product in the cart, not the SKU of the non-existant product.






                share|improve this answer













                I ended up solving it using an Observer that listens for products being added to the cart, and then update the item. Rather than the controller.



                etc/event.xml



                <?xml version="1.0"?>
                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
                <event name="checkout_cart_product_add_after">
                <observer name="customprice" instance="VendorModuleObserverObserver" />
                </event>
                </config>



                Observer.php



                public function execute(Observer $observer)

                $item = $observer->getEvent()->getData('quote_item');
                $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); // Set the parent item if item is virtual
                $price = $item->getProduct()->getPrice(); // Get the price from the product
                $item->setCustomPrice($price); // Set it over the item
                $item->setOriginalCustomPrice($price); // Forget that it was changed, so magento wont change it back randomly
                $item->getProduct()->setIsSuperMode(true);



                This still shows the name of the "generic" product in the cart, not the SKU of the non-existant product.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                tvanrieltvanriel

                208




                208



























                    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%2f277084%2forder-non-existant-product%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?