本文整理汇总了PHP中OrderCarrier::add方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderCarrier::add方法的具体用法?PHP OrderCarrier::add怎么用?PHP OrderCarrier::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderCarrier
的用法示例。
在下文中一共展示了OrderCarrier::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_cart_by_junglee_xml
public function update_cart_by_junglee_xml($order_id, $data)
{
$xml = simplexml_load_string($data);
$prefix = _DB_PREFIX_;
$tablename = $prefix . 'orders';
$total_amount = 0;
$total_principal = 0;
$shipping_amount = 0;
$total_promo = 0;
foreach ($xml->ProcessedOrder->ProcessedOrderItems->ProcessedOrderItem as $item) {
$product_id = (string) $item->SKU;
$product = new Product((int) $product_id);
$SKU = $product->reference;
$Title = (string) $item->Title;
$Amount = (double) $item->Price->Amount;
$other_promo = 0;
foreach ($item->ItemCharges->Component as $amount_type) {
$item_charge_type = (string) $amount_type->Type;
if ($item_charge_type == 'Principal') {
$principal = (string) $amount_type->Charge->Amount;
}
if ($item_charge_type == 'Shipping') {
$Shipping = (string) $amount_type->Charge->Amount;
}
if ($item_charge_type == 'PrincipalPromo') {
$principal_promo = (string) $amount_type->Charge->Amount;
}
if ($item_charge_type == 'ShippingPromo') {
$shipping_promo = (string) $amount_type->Charge->Amount;
}
if ($item_charge_type == 'OtherPromo') {
$other_promo = (string) $amount_type->Charge->Amount;
}
}
$CurrencyCode = (string) $item->Price->CurrencyCode;
$Quantity = (int) $item->Quantity;
$total_principal += $principal;
$total_amount += $principal - $principal_promo + ($Shipping - $shipping_promo);
$shipping_amount += $Shipping;
$total_promo += $principal_promo + $shipping_promo + $other_promo;
}
$ShippingServiceLevel = (string) $xml->ProcessedOrder->ShippingServiceLevel;
$sql = 'UPDATE `' . $prefix . 'pwa_orders` set `shipping_service` = "' . $ShippingServiceLevel . '" , `order_type` = "junglee" where `prestashop_order_id` = "' . $order_id . '" ';
Db::getInstance()->Execute($sql);
$email = (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress;
$sql = 'SELECT * from `' . $prefix . 'customer` where email = "' . $email . '" ';
$results = Db::getInstance()->ExecuteS($sql);
if (empty($results)) {
$name = (string) $xml->ProcessedOrder->BuyerInfo->BuyerName;
$name_arr = explode(' ', $name);
if (count($name_arr) > 1) {
$firstname = '';
for ($i = 0; $i <= count($name_arr) - 2; $i++) {
$firstname = $firstname . ' ' . $name_arr[$i];
}
$lastname = $name_arr[count($name_arr) - 1];
} else {
$firstname = $name;
$lastname = '.';
}
$password = Tools::passwdGen();
$customer = new Customer();
$customer->firstname = trim($firstname);
$customer->lastname = $lastname;
$customer->email = (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress;
$customer->passwd = md5($password);
$customer->active = 1;
if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
$customer->is_guest = 1;
} else {
$customer->is_guest = 0;
}
$customer->add();
$customer_id = $customer->id;
if (Configuration::get('PS_CUSTOMER_CREATION_EMAIL') && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
Mail::Send($this->context->language->id, 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $password), $customer->email, $customer->firstname . ' ' . $customer->lastname);
}
} else {
$customer_id = $results[0]['id_customer'];
}
$id_country = Country::getByIso((string) $xml->ProcessedOrder->ShippingAddress->CountryCode);
if ($id_country == 0 || $id_country == '') {
$id_country = 110;
}
$name = (string) $xml->ProcessedOrder->ShippingAddress->Name;
$name_arr = explode(' ', $name);
if (count($name_arr) > 1) {
$firstname = '';
for ($i = 0; $i <= count($name_arr) - 2; $i++) {
$firstname = $firstname . ' ' . $name_arr[$i];
}
$lastname = $name_arr[count($name_arr) - 1];
} else {
$firstname = $name;
$lastname = '.';
}
$address = new Address();
$address->id_country = $id_country;
$address->id_state = 0;
$address->id_customer = $customer_id;
//.........这里部分代码省略.........
示例2: validateOrder
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null)
{
if (self::DEBUG_MODE) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Function called', 1, null, 'Cart', (int) $id_cart, true);
}
if (!isset($this->context)) {
$this->context = Context::getContext();
}
$this->context->cart = new Cart($id_cart);
$this->context->customer = new Customer($this->context->cart->id_customer);
// The tax cart is loaded before the customer so re-cache the tax calculation method
$this->context->cart->setTaxCalculationMethod();
$this->context->language = new Language($this->context->cart->id_lang);
$this->context->shop = $shop ? $shop : new Shop($this->context->cart->id_shop);
ShopUrl::resetMainDomainCache();
$id_currency = $currency_special ? (int) $currency_special : (int) $this->context->cart->id_currency;
$this->context->currency = new Currency($id_currency, null, $this->context->shop->id);
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$context_country = $this->context->country;
}
$order_status = new OrderState((int) $id_order_state, (int) $this->context->language->id);
if (!Validate::isLoadedObject($order_status)) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $id_cart, true);
throw new PrestaShopException('Can\'t load Order status');
}
if (!$this->active) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Module is not active', 3, null, 'Cart', (int) $id_cart, true);
die(Tools::displayError());
}
// Does order already exists ?
if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists() == false) {
if ($secure_key !== false && $secure_key != $this->context->cart->secure_key) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Secure key does not match', 3, null, 'Cart', (int) $id_cart, true);
die(Tools::displayError());
}
// For each package, generate an order
$delivery_option_list = $this->context->cart->getDeliveryOptionList();
$package_list = $this->context->cart->getPackageList();
$cart_delivery_option = $this->context->cart->getDeliveryOption();
// If some delivery options are not defined, or not valid, use the first valid option
foreach ($delivery_option_list as $id_address => $package) {
if (!isset($cart_delivery_option[$id_address]) || !array_key_exists($cart_delivery_option[$id_address], $package)) {
foreach ($package as $key => $val) {
$cart_delivery_option[$id_address] = $key;
break;
}
}
}
$order_list = array();
$order_detail_list = array();
do {
$reference = Order::generateReference();
} while (Order::getByReference($reference)->count());
$this->currentOrderReference = $reference;
$order_creation_failed = false;
$cart_total_paid = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(true, Cart::BOTH), 2);
foreach ($cart_delivery_option as $id_address => $key_carriers) {
foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data) {
foreach ($data['package_list'] as $id_package) {
// Rewrite the id_warehouse
$package_list[$id_address][$id_package]['id_warehouse'] = (int) $this->context->cart->getPackageIdWarehouse($package_list[$id_address][$id_package], (int) $id_carrier);
$package_list[$id_address][$id_package]['id_carrier'] = $id_carrier;
}
}
}
// Make sure CartRule caches are empty
CartRule::cleanCache();
$cart_rules = $this->context->cart->getCartRules();
foreach ($cart_rules as $cart_rule) {
if (($rule = new CartRule((int) $cart_rule['obj']->id)) && Validate::isLoadedObject($rule)) {
if ($error = $rule->checkValidity($this->context, true, true)) {
$this->context->cart->removeCartRule((int) $rule->id);
if (isset($this->context->cookie) && isset($this->context->cookie->id_customer) && $this->context->cookie->id_customer && !empty($rule->code)) {
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
Tools::redirect('index.php?controller=order-opc&submitAddDiscount=1&discount_name=' . urlencode($rule->code));
}
Tools::redirect('index.php?controller=order&submitAddDiscount=1&discount_name=' . urlencode($rule->code));
} else {
$rule_name = isset($rule->name[(int) $this->context->cart->id_lang]) ? $rule->name[(int) $this->context->cart->id_lang] : $rule->code;
$error = Tools::displayError(sprintf('CartRule ID %1s (%2s) used in this cart is not valid and has been withdrawn from cart', (int) $rule->id, $rule_name));
PrestaShopLogger::addLog($error, 3, '0000002', 'Cart', (int) $this->context->cart->id);
}
}
}
}
foreach ($package_list as $id_address => $packageByAddress) {
foreach ($packageByAddress as $id_package => $package) {
$order = new Order();
$order->product_list = $package['product_list'];
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$address = new Address($id_address);
$this->context->country = new Country($address->id_country, $this->context->cart->id_lang);
if (!$this->context->country->active) {
throw new PrestaShopException('The delivery address country is not active.');
}
}
$carrier = null;
if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) {
$carrier = new Carrier($package['id_carrier'], $this->context->cart->id_lang);
$order->id_carrier = (int) $carrier->id;
//.........这里部分代码省略.........
示例3: validateOrder
/**
* Validate an order in database
* Function called from a payment module
*
* @param integer $id_cart Value
* @param integer $id_order_state Value
* @param float $amount_paid Amount really paid by customer (in the default currency)
* @param string $payment_method Payment method (eg. 'Credit card')
* @param string $message Message to attach to order
*/
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null)
{
$this->context->cart = new Cart($id_cart);
$this->context->customer = new Customer($this->context->cart->id_customer);
$this->context->language = new Language($this->context->cart->id_lang);
$this->context->shop = $shop ? $shop : new Shop($this->context->cart->id_shop);
$id_currency = $currency_special ? (int) $currency_special : (int) $this->context->cart->id_currency;
$this->context->currency = new Currency($id_currency, null, $this->context->shop->id);
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$context_country = $this->context->country;
}
$order_status = new OrderState((int) $id_order_state, (int) $this->context->language->id);
if (!Validate::isLoadedObject($order_status)) {
throw new PrestaShopException('Can\'t load Order state status');
}
if (!$this->active) {
die(Tools::displayError());
}
// Does order already exists ?
if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists() == false) {
if ($secure_key !== false && $secure_key != $this->context->cart->secure_key) {
die(Tools::displayError());
}
// For each package, generate an order
$delivery_option_list = $this->context->cart->getDeliveryOptionList();
$package_list = $this->context->cart->getPackageList();
$cart_delivery_option = $this->context->cart->getDeliveryOption();
// If some delivery options are not defined, or not valid, use the first valid option
foreach ($delivery_option_list as $id_address => $package) {
if (!isset($cart_delivery_option[$id_address]) || !array_key_exists($cart_delivery_option[$id_address], $package)) {
foreach ($package as $key => $val) {
$cart_delivery_option[$id_address] = $key;
break;
}
}
}
$order_list = array();
$order_detail_list = array();
$reference = Order::generateReference();
$this->currentOrderReference = $reference;
$order_creation_failed = false;
$cart_total_paid = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(true, Cart::BOTH), 2);
foreach ($cart_delivery_option as $id_address => $key_carriers) {
foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data) {
foreach ($data['package_list'] as $id_package) {
// Rewrite the id_warehouse
$package_list[$id_address][$id_package]['id_warehouse'] = (int) $this->context->cart->getPackageIdWarehouse($package_list[$id_address][$id_package], (int) $id_carrier);
$package_list[$id_address][$id_package]['id_carrier'] = $id_carrier;
}
}
}
// Make sure CarRule caches are empty
CartRule::cleanCache();
foreach ($package_list as $id_address => $packageByAddress) {
foreach ($packageByAddress as $id_package => $package) {
$order = new Order();
$order->product_list = $package['product_list'];
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$address = new Address($id_address);
$this->context->country = new Country($address->id_country, $this->context->cart->id_lang);
}
$carrier = null;
if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) {
$carrier = new Carrier($package['id_carrier'], $this->context->cart->id_lang);
$order->id_carrier = (int) $carrier->id;
$id_carrier = (int) $carrier->id;
} else {
$order->id_carrier = 0;
$id_carrier = 0;
}
$order->id_customer = (int) $this->context->cart->id_customer;
$order->id_address_invoice = (int) $this->context->cart->id_address_invoice;
$order->id_address_delivery = (int) $id_address;
$order->id_currency = $this->context->currency->id;
$order->id_lang = (int) $this->context->cart->id_lang;
$order->id_cart = (int) $this->context->cart->id;
$order->reference = $reference;
$order->id_shop = (int) $this->context->shop->id;
$order->id_shop_group = (int) $this->context->shop->id_shop_group;
$order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($this->context->customer->secure_key);
$order->payment = $payment_method;
if (isset($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_theme = $this->context->cart->mobile_theme;
$order->conversion_rate = $this->context->currency->conversion_rate;
$amount_paid = !$dont_touch_amount ? Tools::ps_round((double) $amount_paid, 2) : $amount_paid;
//.........这里部分代码省略.........
示例4: cronOrdersSync
function cronOrdersSync()
{
$orders = $this->client->getOrders(array(7));
foreach ($orders as $order) {
$channelOrderId = $order->getId();
$billingAddress = $order->getBillingAddress();
$shippingAddress = $order->getShippingAddress();
if (empty($billingAddress)) {
continue;
}
$id_customer = $this->createPrestashopCustomer($billingAddress, $order->getEmail());
$lines = $order->getLines();
$AddressObject = new Address();
$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 = Country::getByIso($billingAddress->getCountryIso());
$AddressObject->alias = $billingAddress->getcompanyName() != "" ? "Company" : "Home";
$AddressObject->add();
$CarrierObject = new Carrier();
$CarrierObject->delay[1] = "2-4";
$CarrierObject->active = 1;
$CarrierObject->name = "ChannelEngine Order";
$CarrierObject->add();
$id_carrier = $CarrierObject->id;
$currency_object = new Currency();
$default_currency_object = $currency_object->getDefaultCurrency();
$id_currency = $default_currency_object->id;
$id_address = $AddressObject->id;
// Create Cart Object
$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 = $id_carrier;
$cart->recyclable = 0;
$cart->id_shop_group = 1;
$cart->gift = 0;
$cart->add();
if (!empty($lines)) {
foreach ($lines as $item) {
$quantity = $item->getQuantity();
if (strpos($item->getmerchantProductNo(), '-') !== false) {
$getMerchantProductNo = explode("-", $item->getMerchantProductNo());
$cart->updateQty($quantity, $getMerchantProductNo[0], $getMerchantProductNo[1]);
} else {
$cart->updateQty($quantity, $item->getmerchantProductNo());
}
}
}
$cart->update();
$order_object = new Order();
$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;
$order_object->id_carrier = $id_carrier;
$order_object->payment = "ChannelEngine Order";
$order_object->module = "1";
$order_object->valid = 1;
$order_object->total_paid_tax_excl = $order->getTotalInclVat();
$order_object->total_discounts_tax_incl = 0;
$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->total_paid_tax_incl = $order->getSubTotalInclVat();
$order_object->conversion_rate = 1;
$order_object->id_shop = 1;
$order_object->id_lang = 1;
$order_object->id_shop_group = 1;
$order_object->secure_key = md5(uniqid(rand(), true));
$order_id = $order_object->add();
// Insert new Order detail list using cart for the current order
$order_detail = new OrderDetail();
$orderClass = new Order();
$order_detail->createList($order_object, $cart, 1, $cart->getProducts(), 1);
$order_detail_list[] = $order_detail;
// Adding an entry in order_carrier table
if (!is_null($CarrierObject)) {
$order_carrier = new OrderCarrier();
$order_carrier->id_order = (int) $order_object->id;
$order_carrier->id_carrier = (int) $id_carrier;
$order_carrier->weight = (double) $order_object->getTotalWeight();
$order_carrier->shipping_cost_tax_excl = (double) $order_object->total_shipping_tax_excl;
$order_carrier->shipping_cost_tax_incl = (double) $order_object->total_shipping_tax_incl;
$order_carrier->add();
}
foreach ($lines as $item) {
$getMerchantProductNo = explode("-", $item->getMerchantProductNo());
//.........这里部分代码省略.........
示例5: update_cart_by_junglee_xml
public function update_cart_by_junglee_xml($order_id, $orderdetail)
{
$prefix = _DB_PREFIX_;
$tablename = $prefix . 'orders';
$total_amount = 0;
$total_principal = 0;
$shipping_amount = 0;
$total_promo = 0;
$ClientRequestId = 0;
$AmazonOrderID = (string) $orderdetail->OrderReport->AmazonOrderID;
foreach ($orderdetail->OrderReport->Item as $item) {
$SKU = (string) $item->SKU;
$Title = (string) $item->Title;
$Quantity = (int) $item->Quantity;
$Principal_Promotions = 0;
$Shipping_Promotions = 0;
foreach ($item->ItemPrice->Component as $amount_type) {
$item_charge_type = (string) $amount_type->Type;
if ($item_charge_type == 'Principal') {
$Principal = abs((double) $amount_type->Amount);
}
if ($item_charge_type == 'Shipping') {
$Shipping = abs((double) $amount_type->Amount);
}
if ($item_charge_type == 'Tax') {
$Tax = abs((double) $amount_type->Amount);
}
if ($item_charge_type == 'ShippingTax') {
$ShippingTax = abs((double) $amount_type->Amount);
}
}
if (!empty($item->Promotion)) {
foreach ($item->Promotion as $promotions) {
foreach ($promotions->Component as $promotion_amount_type) {
$promotion_type = (string) $promotion_amount_type->Type;
if ($promotion_type == 'Shipping') {
$Shipping_Promotions += abs((double) $promotion_amount_type->Amount);
}
if ($promotion_type == 'Principal') {
$Principal_Promotions += abs((double) $promotion_amount_type->Amount);
}
}
}
}
$total_principal += $Principal;
$total_amount += $Principal - $Principal_Promotions + ($Shipping - $Shipping_Promotions);
$shipping_amount += $Shipping + $Shipping_Promotions;
$total_promo += $Principal_Promotions + $Shipping_Promotions;
foreach ($item->CustomizationInfo as $info) {
$info_type = (string) $info->Type;
if ($info_type == 'url') {
$info_array = explode(',', $info->Data);
$customerId_array = explode('=', $info_array[0]);
$ClientRequestId = $customerId_array[1];
}
}
}
$ShippingServiceLevel = (string) $orderdetail->OrderReport->FulfillmentData->FulfillmentServiceLevel;
$sql = 'UPDATE `' . $prefix . 'pwa_orders` set `shipping_service` = "' . $ShippingServiceLevel . '" , `order_type` = "junglee" where `prestashop_order_id` = "' . $order_id . '" ';
Db::getInstance()->Execute($sql);
$cust_name = (string) $orderdetail->OrderReport->BillingData->BuyerName;
$name_arr = explode(' ', $cust_name);
if (count($name_arr) > 1) {
$firstname = '';
for ($i = 0; $i < count($name_arr) - 2; $i++) {
$firstname = $firstname . ' ' . $name_arr[$i];
}
$lastname = $name_arr[count($name_arr) - 1];
} else {
$firstname = $cust_name;
$lastname = ' ';
}
$email = (string) $orderdetail->OrderReport->BillingData->BuyerEmailAddress;
$sql = 'SELECT * from `' . $prefix . 'customer` where email = "' . $email . '" ';
$results = Db::getInstance()->ExecuteS($sql);
if (empty($results)) {
$password = Tools::passwdGen();
$customer = new Customer();
$customer->firstname = trim($firstname);
$customer->lastname = $lastname;
$customer->email = (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress;
$customer->passwd = md5($password);
$customer->active = 1;
if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
$customer->is_guest = 1;
} else {
$customer->is_guest = 0;
}
$customer->add();
$customer_id = $customer->id;
if (Configuration::get('PS_CUSTOMER_CREATION_EMAIL') && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
Mail::Send($this->context->language->id, 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $password), $customer->email, $customer->firstname . ' ' . $customer->lastname);
}
} else {
$customer_id = $results[0]['id_customer'];
}
$id_country = Country::getByIso((string) $orderdetail->OrderReport->FulfillmentData->Address->CountryCode);
if ($id_country == 0 || $id_country == '') {
$id_country = 110;
}
//.........这里部分代码省略.........