Jump to content

Edit History

bedford

bedford


change title topic

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

image.thumb.png.5412068372f3cafe4e1a9c85038331cc.png

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.

 

 

image.png

bedford

bedford

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

image.thumb.png.5412068372f3cafe4e1a9c85038331cc.png

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.

 

 

image.png

×
×
  • Create New...