以编程方式在prestashop中创建订单

以编程方式在prestashop中创建订单,prestashop,prestashop-1.6,Prestashop,Prestashop 1.6,我试图以编程方式在prestashop中创建订单 以下是我将遵循的步骤: $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); if (empty($billingAddress)) { continue; } $id_customer = $this->

我试图以编程方式在prestashop中创建订单

以下是我将遵循的步骤:

$billingAddress = $order->getBillingAddress();
        $shippingAddress = $order->getShippingAddress();
        if (empty($billingAddress)) {
            continue;
        }
        $id_customer = $this->createPrestashopCustomer($billingAddress, $order->getEmail());
        $lines = $order->getLines();

        $AddressObject = new AddressCore();
        $AddressObject->id_customer = $id_customer;
        $AddressObject->firstname = $billingAddress->getfirstName();
        $AddressObject->lastname = $billingAddress->getlastName();
        $AddressObject->address1 = " " . $billingAddress->getHouseNr();
        $AddressObject->address1.= " " . $billingAddress->getHouseNrAddition();
        $AddressObject->address1.= " " . $billingAddress->getStreetName();
        $AddressObject->address1.= " " . $billingAddress->getZipCode();
        $AddressObject->address1.= " " . $billingAddress->getCity();
        $AddressObject->city = $billingAddress->getCity();
        $AddressObject->id_customer = $id_customer;
        $AddressObject->id_country = CountryCore::getByIso($billingAddress->getCountryIso());
        $AddressObject->alias = ($billingAddress->getcompanyName() != "") ? "Company" : "Home";
        $AddressObject->add();
        $currency_object = new CurrencyCore();
        $default_currency_object = $currency_object->getDefaultCurrency();
        $id_currency = $default_currency_object->id;
        $id_address = $AddressObject->id;

        $cart = new Cart();
        $cart->id_customer = (int) $id_customer;
        $cart->id_address_delivery = $id_address;
        $cart->id_address_invoice = $id_address;
        $cart->id_lang = 1;
        $cart->id_currency = (int) $id_address;
        $cart->id_carrier = 1;
        $cart->recyclable = 0;
        $cart->gift = 0;
        $cart->add();
        if (!empty($lines)) {
            foreach ($lines as $item) {
                $cart->updateQty(1, 5, 19);
            }
        } 
        $cart->update();
        $order_object = new OrderCore();
        $order_object->id_address_delivery = $id_address;
        $order_object->id_address_invoice = $id_address;
        $order_object->id_cart = $cart->id;

        $order_object->id_currency = $id_currency;
        $order_object->id_customer = $id_customer;
        $CarrierObject = new CarrierCore();
        $CarrierObject->delay[1] = "2-4";
        $CarrierObject->active = 1;
        $CarrierObject->name = "ChannelEngine Order2";
        $CarrierObject->add();
        $id_carrier = $CarrierObject->id;
        $order_object->id_carrier = $id_carrier;
        $order_object->payment = "Channel Engine Order";
        $order_object->module = "1";
        echo $order->getTotalInclVat();
        $order_object->valid = 1;
        $order_object->total_paid_tax_excl = $order->getTotalInclVat();
        $order_object->total_discounts_tax_incl = $order->getTotalInclVat();
        $order_object->total_paid = $order->getTotalInclVat();
        $order_object->total_paid_real = $order->getTotalInclVat();
        $order_object->total_products = $order->getSubTotalInclVat() - $order->getSubTotalVat();
        $order_object->total_products_wt = $order->getSubTotalInclVat();
        $order_object->conversion_rate = 1;
        $order_object->id_shop = 1;
        $order_object->id_lang = 1;
        $order_object->secure_key = md5(uniqid(rand(), true));
        $order_id = $order_object->add();
订单正在添加到管理,但不知何故,我无法看到订单中的产品,任何人都可以检查,让我知道我在这里做错了什么。
此外,订单总数也为0。

您还应该为此订单的每个产品创建
OrderDetail
对象

查看
PaymentModule
类的
validateOrder()
方法

以下是此方法的摘录:

$order=新订单();
$order->product_list=$package['product_list'];
if(配置::get('PS\u TAX\u ADDRESS\u TYPE')=='id\u ADDRESS\u delivery'){
$address=新地址((int)$id\u地址);
$this->context->country=新国家((int)$address->id\u country,(int)$this->context->cart->id\u lang);
如果(!$this->context->country->active){
抛出新的PrestashopeException('送达地址国家/地区未激活');
}
}
$carrier=null;
如果(!$this->context->cart->isVirtualCart()&&isset($package['id\u carrier'])){
$carrier=newcarrier((int)$package['id\u carrier',(int)$this->context->cart->id\u lang);
$order->id\u carrier=(int)$carrier->id;
$id_carrier=(int)$carrier->id;
}否则{
$order->id\u carrier=0;
$id_carrier=0;
}
$order->id\u customer=(int)$this->context->cart->id\u customer;
$order->id\u address\u invoice=(int)$this->context->cart->id\u address\u invoice;
$order->id\u address\u delivery=(int)$id\u address;
$order->id\u currency=$this->context->currency->id;
$order->id\u lang=(int)$this->context->cart->id\u lang;
$order->id\u cart=(int)$this->context->cart->id;
$order->reference=$reference;
$order->id\u shop=(int)$this->context->shop->id;
$order->id\u shop\u group=(int)$this->context->shop->id\u shop\u group;
$order->secure_key=($secure_key?pSQL($secure_key):pSQL($this->context->customer->secure_key));
$order->payment=$payment\u方法;
if(设置($this->name)){
$order->module=$this->name;
}
$order->recyclable=$this->context->cart->recyclable;
$order->gift=(int)$this->context->cart->gift;
$order->gift_message=$this->context->cart->gift_message;
$order->mobile\u theme=$this->context->cart->mobile\u theme;
$order->conversion\u rate=$this->context->currency->conversion\u rate;
$amount_paid=$不要碰数量?工具:ps_轮((浮动)$amount_paid,2):$amount_paid;
$order->total\u paid\u real=0;
$order->total\u products=(float)$this->context->cart->getOrderTotal(false,cart::ONLY\u products,$order->products\u list,$id\u carrier);
$order->total\u products\u wt=(float)$this->context->cart->getOrderTotal(true,cart::ONLY\u products,$order->products\u list,$id\u carrier);
$order->total\U DECURS\U tax\U excl=(浮动)abs($this->context->cart->getOrderTotal(false,cart::ONLY\u deCURS,$order->product\U list,$id\u carrier));
$order->total\U DECURS\U tax\U incl=(浮动)abs($this->context->cart->getOrderTotal(true,cart::仅\u折扣,$order->product\u list,$id\u carrier));
$order->总折扣=$order->总折扣\含税;
$order->total\u shipping\u tax\u excl=(float)$this->context->cart->getPackageShippingCost((int)$id\u carrier,false,null,$order->product\u list);
$order->total\u shipping\u tax\u incl=(float)$this->context->cart->getPackageShippingCost((int)$id\u carrier,true,null,$order->product\u list);
$order->total_shipping=$order->total_shipping\u tax\u include;
如果(!is_null($carrier)&&Validate::isLoadedObject($carrier)){
$order->carrier\u tax\u rate=$carrier->gettaxestate(新地址((int)$this->context->cart->{Configuration::get('PS\u tax\u Address\u TYPE')));
}
$order->total\u wrapping\u tax\u excl=(float)abs($this->context->cart->getOrderTotal(false,cart::ONLY\u wrapping,$order->product\u list,$id\u carrier));
$order->total\u wrapping\u tax\u incl=(float)abs($this->context->cart->getOrderTotal(true,cart::ONLY\u wrapping,$order->product\u list,$id\u carrier));
$order->total\u wrapping=$order->total\u wrapping\u tax\u include;
$order->total\u paid\u tax\u excl=(float)Tools::ps\u round((float)$this->context->cart->getOrderTotal(false,cart::BOTH,$order->product\u list,$id\u carrier),\u ps\u PRICE\u COMPUTE\u PRECISION\u);
$order->total\u paid\u incl=(float)Tools::ps\u round((float)$this->context->cart->getOrderTotal(true,cart::tware,$order->product\u list,$id\u carrier),\u ps\u PRICE\u COMPUTE\u PRECISION);
$order->total\u paid=$order->total\u paid\u tax\u include;
$order->round_mode=Configuration::get('PS_PRICE_round_mode');
$order->round_type=Configuration::get('PS_round_type');
$order->invoice_date='0000-00-00:00:00';
$order->delivery_date='0000-00-00:00:00';
if(self::DEBUG_模式){
PrestaShopLogger::addLog('PaymentModule::validateOrder-即将添加订单',1,null,'Cart',(int)$id\u Cart,true);
}
//创建订单
$result=$order->add();
如果(!$result){
PrestaShopLogger::addLog('PaymentModule::validateOrder-无法创建订单',3,null,'Cart',(int)$id\u Cart,true);
抛出新的PrestaShopException('无法保存订单');
}
//客户支付的金额不正确->状态=支付错误
//我们不使用以下条件来避免浮点精度问题:http://www.php.net/manual/en/language.types.float.php
//如果($order->total\u paid!=$order->total\u paid\u real)
//我们使用数字_格式来比较两个字符串
如果($order\u status->logable&&number\u format($cart\u total\u paid,$PS\u PRICE\u COMPUTE\u PRECISION)!=number\u format($amount\u paid,$PS\u PRICE\u COMPUTE\u PRECISION)){
$id_order_state=Configuration::get('PS_OS_ERROR');
}
$order_list[]=$order;
if(self::DEBUG_模式){
PrestaShopLogger::addLog('PaymentModule::validateOrder-OrderDetail即将添加',1,null,'Cart',(int)$id_Cart,true);
}
//使用购物车为当前订单插入新订单明细列表
$order\u detail=neworderdetail(null,null,$this->context);
$order\u detail->createList($order,$this->context->cart,$id\u order\u state,$order->product\u list,0,true,$package\u list[$id\u address][$id\u package]['id\u warehouse']);
$order\u详细信息\u列表