bedford Posted October 12, 2022 Share Posted October 12, 2022 (edited) Hi all, I'm trying to import orders from an old E-commerce website to PS 1.7.8.7 and can't figure out how to set product's prices and total. Here is the screen capture of what I've so far (I removed product's details): Import is done using a CSV files which is generated from old system. So I can create order, the products are correct but I can't set each product price (as you see in capture above) and Total. Here is the code. $firstOrder = true; $headers = fgetcsv($handle, 1000, ";"); //first line fields headers $idOrderState = ''; while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { //first column must be O=ORDER, P=PRODUCT if($data[0]=='O'){ $total = $shipping = 0; if (!$firstOrder){//save existing order $this->createOrder($cart,$idOrderState); } $cart = new Cart(); //reset cart for next order $cart->id_cart = (int)$data[1]; $cart->id_customer = (int)$data[2]; $cart->id_address_invoice = (int)$data[3]; $cart->id_address_delivery = (int)$data[4]; $cart->id_lang = LANG_TRANS[(int)$data[5]]; $cart->id_currency = (int)$data[6]; $cart->id_carrier = CARRIER[(int)$data[7]]; $cart->id_payment = PAYMENT[(int)$data[8]]; $cart->date_add = $data[9]; $cart->total_paid = $data[10]; $cart->total_paid_real = $cart->total_paid; $cart->total_products_wt = $data[11]; $cart->id_shop = 1; $idOrderState= STATE[$data[12]]; $cart->add();//save in DB if (!$cart->id) { $errors[] = 'cart create error'; continue; } $firstOrder = false; }elseif($data[0]=='P'){ if(!$cart->updateQty((int)$data[2], (int)$data[1])){ die('error adding item ID '.(int)$data[1].' to cart'); } $total += $data[2]*$data[3]; }else return('ERROR IN FILE'); $num = count($data); echo "<p> $num champs à la ligne $row: <br /></p>\n"; $row++; } return $this->createOrder($cart,$idOrderState); //only one order or last order Maybe the $cart->updateQty isn't the best method but it's the only I've found so far to add product to cart and then be able to create an order in database. I must import old orders, with details. My product have no price as they are calculated by provider's prices dynamically and price have changed since the order were created. So I must be able to import with old prices. Bonus question: how to avoid the stock count to change when creating the order this way ? Thank you for your help. Edited October 12, 2022 by bedford change title topic (see edit history) Link to comment Share on other sites More sharing options...
bedford Posted October 12, 2022 Author Share Posted October 12, 2022 I found part of the solution by adding this code: if(!$cart->updateQty((int)$data[2], (int)$data[1], 0)){ die('error adding item ID '.(int)$data[1].' to cart'); }else{ $sp = new SpecificPrice(); $sp->id_product = (int)$data[1]; // custom product id you want to add $sp->id_product_attribute = 0; $sp->id_cart = (int)$cart->id; $sp->id_shop = $cart->id_shop; $sp->id_currency = $cart->id_currency; $sp->id_country = 0; $sp->id_group = 0; $sp->id_customer = $cart->id_customer; $sp->from_quantity = 1; $sp->price = $data[3]; $sp->reduction_type = 'amount'; $sp->reduction_tax = 1; $sp->reduction = 0; $sp->from = "0000-00-00 00:00:00"; $sp->to = "0000-00-00 00:00:00"; $sp->add(); } $total += $data[2]*$data[3]; Still have Total to 0.00 and can't find where to set it. Also I see the weight is 0 but this is not so important (even if it may be good to have this info as well) So if anyone can help with setting total, I would appreciate Link to comment Share on other sites More sharing options...
bedford Posted October 13, 2022 Author Share Posted October 13, 2022 Ok I figured out my solution creates new Specific prices in database and it's not what I want. So I found another way to add the product to order with specific price: $data[1] is product's ID, $data[3] is product's price in original order, $data[2] is the purchased quantity $Product = new Product((int)$data[1], null, null, $cart->id_shop); $oldPrice = $Product->price; $Product->price = $data[3]; $Product->update(); $updateResult = $cart->updateQty((int)$data[2], (int)$data[1], 0)); $Product->price = $oldPrice; $Product->update(); Hope this may be of any help to anyone looking at a solution. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now