my question is about importing order via orderRepository, and calculating price.

I've made a script that automatically import order from another webshop into our Magento backend. Now, because there is a cronjob on that script (runs every 5 minutes), the same order gets imported every time the cronjob runs. What is the best way to check if the order is already imported?!

I've add those order via the orderRepository, but when I save one order, all price fields are empty (including Tax column). Now, the QuoteFactory has the collectTotals() method to calculate that automatically for you, but the orderRepository hasn't. Is there some way I can calculate the price and tax automatically, but still use the orderRepository?!

  • 1
    Create a new quote, then try to place the order using offline payment. Also check similarity between new order with Magento order that will protect duplicate order. – Sohel Rana Mar 8 '19 at 15:29
  • To check similarity I thought to create a new order Attribute which stores a unique ID for each order. But I haven't found a way to store a value to a custom order attribute. I tried $order-setData(), but that doesn't work. – Etiën Ruhl Mar 8 '19 at 16:46
  • you have a field ext_order_id in the order table, you might use that for your unique id. For order creation I would also recommend the procedure proposed by Sohel Rana. – HelgeB Mar 8 '19 at 17:15
  • Thanks.. Tomorrow i'll go and make the orders via a quote. I didn't know there was a column called ext_order_id, so I indeed use that as a unique field for each order. A guy said to me that i'll have to use the orderRepository for saving orders, so that's why I'd gone for that procedure. – Etiën Ruhl Mar 8 '19 at 22:13
  • As I said, today I made the orders via a quote, and it works. But now I can't save data to a custom attribute like ext_order_id.. I've made a custom attribute myself, called Is Imported, but I can't store data in them. Do you know how I can store custom data to the custom attribute via QuoteFactory? – Etiën Ruhl Mar 9 '19 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.