bedford Posted October 13, 2022 Share Posted October 13, 2022 Bonjour, j'essaye de créer une commande par script mais le total est à 0.00Chf Le total produit est envoyé par Script mais je ne trouve pas comment définir le total de la commande. Si je rentre ensuite un paiement, il me dit que la commande est à 0 donc ça me fausse tout. Voici mon code ($data = ligne d'un fichier CSV que j'essaye d'importer): $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 = $data[10]; $cart->total = $data[10]; $cart->total_products_wt = $data[11]; $cart->id_shop = 1; $idOrderState= STATE[$data[12]]; $cart->add();//save in DB Merci pour votre aide. Link to comment Share on other sites More sharing options...
Eolia Posted October 13, 2022 Share Posted October 13, 2022 Votre script montre la création du panier ($cart) mais pas de la commande. Il faut utiliser la méthode ValidateOrder() avec le paiement utilisé pour créer et valider la commande. validateOrder( $id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = [], $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null ) 1 Link to comment Share on other sites More sharing options...
bedford Posted October 17, 2022 Author Share Posted October 17, 2022 On 10/13/2022 at 11:53 AM, Eolia said: Votre script montre la création du panier ($cart) mais pas de la commande. Il faut utiliser la méthode ValidateOrder() avec le paiement utilisé pour créer et valider la commande. validateOrder( $id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = [], $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null ) Merci pour le message et l'aide Eolia. J'ai essayé ceci: $bankwire = Module::getInstanceByName('ps_wirepayment'); $bankwire->validateOrder( $cart->id_cart, $idOrderState, $cart->total_paid, $payment_method = 'bank', $message = "import from old shop", $extra_vars = [] ); mais un code d'erreur m'indique que le panier a déjà été utilisé dans une autre commande. Voici l'ancien code que j'avais pour créer la commande: ...$this->createOrder($cart,$idOrderState); //only one order or last order public function createOrder($cart,$idOrderState){ $bank_wire_status = Configuration::get('PS_OS_BANKWIRE'); $accepted_payment_status = Configuration::get('PS_OS_PAYMENT'); $order_status = null; $order = new Order(); $order->id_cart = $cart->id_cart; $order->id_customer = $cart->id_customer; $order->id_address_invoice = $cart->id_address_invoice; $order->id_address_delivery = $cart->id_address_delivery; $order->id_currency = $cart->id_currency; $order->id_carrier = $cart->id_carrier; $order->id_payment = $cart->id_payment; $order->id_shop = $cart->id_shop; $order->invoice_date = $cart->date_add; $order->total_paid = $cart->total_paid; $order->total_products = $cart->total_paid; $order->total_paid_real = $cart->total_paid_real; $order->total_products_wt = $cart->total_products_wt; $order->conversion_rate = 1; //TODO ? $order->secure_key = md5(uniqid(rand(), true)); $order->payment = "BANK"; $order->module = "XImportOrders"; $order->current_state = $idOrderState; $order->product_list = $cart->getProducts(); $order->valid = 1; $order->total_products = (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $cart->id_carrier); $order_id = $order->add(); // Insert new Order detail list using cart for the current order $order_detail = new OrderDetail(null, null, null); $order_detail->createList($order, $cart, 1, $order->product_list, 0, true); $order_detail_list[] = $order_detail; $order->setInvoice(true); $cart->delete(); exit; } ça me crée bien une commande, ça supprime le panier dont je n'ai plus besoin, mais c'est avec cette fonction que j'ai l'erreur sur le total, qui reste à 0 Est-ce que quelqu'un aurait une solution ? Link to comment Share on other sites More sharing options...
bedford Posted October 17, 2022 Author Share Posted October 17, 2022 Ok trouvé ! Il faut remplir les champs $order->total_paid_tax_incl = $cart->total_paid_real; $order->total_paid_tax_excl = $cart->total_paid_real; et le total est à la valeur définie. 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