本文整理汇总了PHP中Hook::newOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::newOrder方法的具体用法?PHP Hook::newOrder怎么用?PHP Hook::newOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hook
的用法示例。
在下文中一共展示了Hook::newOrder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateOrder
//.........这里部分代码省略.........
}
if ($shrunk and $total_discount_value + $value > $order->total_products_wt + $order->total_shipping + $order->total_wrapping) {
$amount_to_add = $order->total_products_wt + $order->total_shipping + $order->total_wrapping - $total_discount_value;
if ($objDiscount->id_discount_type == 2 and $objDiscount->behavior_not_exhausted == 2) {
$voucher = new Discount();
foreach ($objDiscount as $key => $discountValue) {
$voucher->{$key} = $discountValue;
}
$voucher->name = 'VSRK' . (int) $order->id_customer . 'O' . (int) $order->id;
$voucher->value = (double) $value - $amount_to_add;
$voucher->add();
$params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
$params['{voucher_num}'] = $voucher->name;
$params['{firstname}'] = $customer->firstname;
$params['{lastname}'] = $customer->lastname;
$params['{id_order}'] = $order->id;
$params['{order_name}'] = sprintf("#%06d", (int) $order->id);
@Mail::Send((int) $order->id_lang, 'voucher', Mail::l('New voucher regarding your order #', (int) $order->id_lang) . sprintf("%06d", (int) $order->id), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname);
}
} else {
$amount_to_add = $value;
}
$order->addDiscount($objDiscount->id, $objDiscount->name, $amount_to_add);
$total_discount_value += $amount_to_add;
if ($id_order_state != Configuration::get('PS_OS_ERROR') and $id_order_state != Configuration::get('PS_OS_CANCELED')) {
$objDiscount->quantity = $objDiscount->quantity - 1;
}
$objDiscount->update();
$discountsList .= '<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td>
<td style="padding: 0.6em 0.4em; text-align: right;">' . ($value != 0.0 ? '-' : '') . Tools::displayPrice($value, $currency, false) . '</td>
</tr>';
}
// Specify order id for message
$oldMessage = Message::getMessageByCartId((int) $cart->id);
if ($oldMessage) {
$message = new Message((int) $oldMessage['id_message']);
$message->id_order = (int) $order->id;
$message->update();
}
// Hook new order
$orderStatus = new OrderState((int) $id_order_state, (int) $order->id_lang);
if (Validate::isLoadedObject($orderStatus)) {
Hook::newOrder($cart, $order, $customer, $currency, $orderStatus);
foreach ($cart->getProducts() as $product) {
if ($orderStatus->logable) {
ProductSale::addProductSale((int) $product['id_product'], (int) $product['cart_quantity']);
}
}
}
if (isset($outOfStock) && $outOfStock && Configuration::get('PS_STOCK_MANAGEMENT')) {
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), (int) $order->id);
$history->addWithemail();
}
// Set order state in order history ONLY even if the "out of stock" status has not been yet reached
// So you migth have two order states
$new_history = new OrderHistory();
$new_history->id_order = (int) $order->id;
$new_history->changeIdOrderState((int) $id_order_state, (int) $order->id);
$new_history->addWithemail(true, $extraVars);
// Order is reloaded because the status just changed
$order = new Order($order->id);
// Send an e-mail to customer
if ($id_order_state != Configuration::get('PS_OS_ERROR') and $id_order_state != Configuration::get('PS_OS_CANCELED') and $customer->id) {
$invoice = new Address((int) $order->id_address_invoice);
$delivery = new Address((int) $order->id_address_delivery);
$carrier = new Carrier((int) $order->id_carrier, $order->id_lang);
$delivery_state = $delivery->id_state ? new State((int) $delivery->id_state) : false;
$invoice_state = $invoice->id_state ? new State((int) $invoice->id_state) : false;
$data = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => $this->_getFormatedAddress($delivery, "<br />", array('firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')), '{invoice_block_html}' => $this->_getFormatedAddress($invoice, "<br />", array('firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_vat_number}' => $invoice->vat_number, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("#%06d", (int) $order->id), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), (int) $order->id_lang, 1), '{carrier}' => $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false));
if (is_array($extraVars)) {
$data = array_merge($data, $extraVars);
}
// Join PDF invoice
if ((int) Configuration::get('PS_INVOICE') and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) {
$fileAttachment['content'] = PDF::invoice($order, 'S');
$fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int) $order->id_lang) . sprintf('%06d', $order->invoice_number) . '.pdf';
$fileAttachment['mime'] = 'application/pdf';
} else {
$fileAttachment = null;
}
if (Validate::isEmail($customer->email)) {
Mail::Send((int) $order->id_lang, 'order_conf', Mail::l('Order confirmation', (int) $order->id_lang), $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment);
}
}
$this->currentOrder = (int) $order->id;
return true;
} else {
$errorMessage = Tools::displayError('Order creation failed');
Logger::addLog($errorMessage, 4, '0000002', 'Cart', intval($order->id_cart));
die($errorMessage);
}
} else {
$errorMessage = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart');
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id));
die($errorMessage);
}
}
示例2: validateOrder
//.........这里部分代码省略.........
$productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';">
<td style="padding: 0.6em 0.4em;">' . $product['reference'] . '</td>
<td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . ' - ' . $this->l('Customized') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td>
<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td>
<td style="padding: 0.6em 0.4em; text-align: center;">' . $customizationQuantity . '</td>
<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td>
</tr>';
}
if (!$customizationQuantity or intval($product['cart_quantity']) > $customizationQuantity) {
$productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';">
<td style="padding: 0.6em 0.4em;">' . $product['reference'] . '</td>
<td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . '</strong></td>
<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td>
<td style="padding: 0.6em 0.4em; text-align: center;">' . (intval($product['cart_quantity']) - $customizationQuantity) . '</td>
<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice((intval($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td>
</tr>';
}
}
// end foreach ($products)
$query = rtrim($query, ',');
$result = $db->Execute($query);
// Insert discounts from cart into order_discount table
$discounts = $cart->getDiscounts();
$discountsList = '';
foreach ($discounts as $discount) {
$objDiscount = new Discount(intval($discount['id_discount']));
$value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, 1), $order->total_shipping, $cart->id);
$order->addDiscount($objDiscount->id, $objDiscount->name, $value);
if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_) {
$objDiscount->quantity = $objDiscount->quantity - 1;
}
$objDiscount->update();
$discountsList .= '<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td>
<td style="padding: 0.6em 0.4em; text-align: right;">-' . Tools::displayPrice($value, $currency, false, false) . '</td>
</tr>';
}
// Specify order id for message
$oldMessage = Message::getMessageByCartId(intval($cart->id));
if ($oldMessage) {
$message = new Message(intval($oldMessage['id_message']));
$message->id_order = intval($order->id);
$message->update();
}
// Hook new order
$orderStatus = new OrderState(intval($id_order_state));
if (Validate::isLoadedObject($orderStatus)) {
Hook::newOrder($cart, $order, $customer, $currency, $orderStatus);
foreach ($cart->getProducts() as $product) {
if ($orderStatus->logable) {
ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity']));
}
}
}
if (isset($outOfStock) and $outOfStock) {
$history = new OrderHistory();
$history->id_order = intval($order->id);
$history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, intval($order->id));
$history->addWithemail();
}
// Set order state in order history ONLY even if the "out of stock" status has not been yet reached
// So you migth have two order states
$new_history = new OrderHistory();
$new_history->id_order = intval($order->id);
$new_history->changeIdOrderState(intval($id_order_state), intval($order->id));
$new_history->addWithemail(true, $extraVars);
// Send an e-mail to customer
if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_ and $customer->id) {
$invoice = new Address(intval($order->id_address_invoice));
$delivery = new Address(intval($order->id_address_delivery));
$carrier = new Carrier(intval($order->id_carrier));
$delivery_state = $delivery->id_state ? new State(intval($delivery->id_state)) : false;
$invoice_state = $invoice->id_state ? new State(intval($invoice->id_state)) : false;
$data = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("#%06d", intval($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), intval($order->id_lang), 1), '{carrier}' => strval($carrier->name) != '0' ? $carrier->name : Configuration::get('PS_SHOP_NAME'), '{payment}' => $order->payment, '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false, false));
if (is_array($extraVars)) {
$data = array_merge($data, $extraVars);
}
// Join PDF invoice
if (intval(Configuration::get('PS_INVOICE')) and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) {
$fileAttachment['content'] = PDF::invoice($order, 'S');
$fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)) . sprintf('%06d', $order->invoice_number) . '.pdf';
$fileAttachment['mime'] = 'application/pdf';
} else {
$fileAttachment = NULL;
}
if ($orderStatus->send_email and Validate::isEmail($customer->email)) {
Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment);
}
$this->currentOrder = intval($order->id);
return true;
}
$this->currentOrder = intval($order->id);
return true;
} else {
die(Tools::displayError('Order creation failed'));
}
} else {
die(Tools::displayError('An order has already been placed using this cart'));
}
}
示例3: validateOrder
//.........这里部分代码省略.........
$voucher->{$key} = $discountValue;
}
$voucher->name = 'VSRK' . (int) $order->id_customer . 'O' . (int) $order->id;
$voucher->value = (double) $value - $amount_to_add;
$voucher->add();
$params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
$params['{voucher_num}'] = $voucher->name;
@Mail::Send((int) $order->id_lang, 'voucher', Mail::l('New voucher regarding your order #') . $order->id, $params, $customer->email, $customer->firstname . ' ' . $customer->lastname);
}
} else {
$amount_to_add = $value;
}
$order->addDiscount($objDiscount->id, $objDiscount->name, $amount_to_add);
$total_discount_value += $amount_to_add;
if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_) {
$objDiscount->quantity = $objDiscount->quantity - 1;
}
$objDiscount->update();
$discountsList .= '<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td>
<td style="padding: 0.6em 0.4em; text-align: right;">' . ($value != 0.0 ? '-' : '') . Tools::displayPrice($value, $currency, false) . '</td>
</tr>';
}
// Specify order id for message
$oldMessage = Message::getMessageByCartId((int) $cart->id);
if ($oldMessage) {
$message = new Message((int) $oldMessage['id_message']);
$message->id_order = (int) $order->id;
$message->update();
}
// Hook new order
$orderStatus = new OrderState((int) $id_order_state, (int) $order->id_lang);
if (Validate::isLoadedObject($orderStatus)) {
Hook::newOrder($cart, $order, $customer, $currency, $orderStatus);
foreach ($cart->getProducts() as $product) {
if ($orderStatus->logable) {
ProductSale::addProductSale((int) $product['id_product'], (int) $product['cart_quantity']);
}
}
}
if (isset($outOfStock) and $outOfStock) {
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, (int) $order->id);
$history->addWithemail();
}
// Set order state in order history ONLY even if the "out of stock" status has not been yet reached
// So you migth have two order states
$new_history = new OrderHistory();
$new_history->id_order = (int) $order->id;
$new_history->changeIdOrderState((int) $id_order_state, (int) $order->id);
$new_history->addWithemail(true, $extraVars);
//Payment status
$paymentHistory = new OrderPaymentHistory();
$paymentHistory->id_order = (int) $order->id;
$paymentHistory->changeIdOrderPaymentState($id_payment_state, (int) $order->id);
$paymentHistory->addState();
// Order is reloaded because the status just changed
$order = new Order($order->id);
//Update tracking code for quantium
if ($order->id_carrier == QUANTIUM) {
if (strpos($order->payment, 'COD') === false) {
$order->shipping_number = 'VBN' . $order->id;
} else {
$order->shipping_number = 'VBC' . $order->id;
}