本文整理汇总了PHP中Discount::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::add方法的具体用法?PHP Discount::add怎么用?PHP Discount::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discount
的用法示例。
在下文中一共展示了Discount::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerDiscount
public function registerDiscount($id_customer, $register = false)
{
$configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_DISCOUNT_VALUE'));
$discount = new Discount();
$discount->id_discount_type = intval($configurations['REFERRAL_DISCOUNT_TYPE']);
$discount->value = floatval($configurations['REFERRAL_DISCOUNT_VALUE']);
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->date_from = date('Y-m-d H:i:s', time());
$discount->date_to = date('Y-m-d H:i:s', time() + 31536000);
// + 1 year
$discount->name = $this->getDiscountPrefix() . Tools::passwdGen(6);
$discount->description = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION');
$discount->id_customer = intval($id_customer);
if ($discount->add()) {
if ($register != false) {
if ($register == 'sponsor') {
$this->id_discount_sponsor = $discount->id;
} elseif ($register == 'sponsored') {
$this->id_discount = $discount->id;
}
return $this->save();
}
return true;
}
return false;
}
示例2: createDefaultBcashDiscounts
public function createDefaultBcashDiscounts()
{
foreach ($this->names as $name) {
$coupon = new Discount();
$coupon->name = $this->getLangsForName($name);
$coupon->quantity = self::billion;
$coupon->quantity_per_user = self::billion;
$coupon->date_from = date('Y-m-d H:i:s');
$coupon->date_to = date('Y-m-d', strtotime('+30 year'));
$coupon->partial_use = 0;
$coupon->code = 'gerenciado_pelo_modulo_' . Tools::passwdGen(8);
$coupon->active = 0;
//Invisivel
$coupon->highlight = 0;
//Envio excluido
$coupon->minimum_amount_shipping = 0;
//Acoes
$coupon->free_shipping = 0;
$coupon->reduction_percent = 0;
if ($coupon->add()) {
Configuration::updateValue(self::prefix . self::bcash . $name, (int) $coupon->id);
}
}
return true;
}
示例3: createTodaysVouchers
public function createTodaysVouchers()
{
$users = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT DISTINCT c.id_customer, firstname, lastname, email
FROM ' . _DB_PREFIX_ . 'customer c
LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (c.id_customer = o.id_customer)
WHERE o.valid = 1
AND c.birthday LIKE \'%' . date('-m-d') . '\'');
foreach ($users as $user) {
$voucher = new Discount();
$voucher->id_customer = (int) $user['id_customer'];
$voucher->id_discount_type = (int) Configuration::get('BIRTHDAY_DISCOUNT_TYPE');
$voucher->name = 'BIRTHDAY-' . (int) $voucher->id_customer . '-' . date('Y');
$voucher->description[(int) Configuration::get('PS_LANG_DEFAULT')] = $this->l('Your birthday present !');
$voucher->value = Configuration::get('BIRTHDAY_DISCOUNT_VALUE');
$voucher->id_currency = Configuration::get('PS_CURRENCY_DEFAULT');
$voucher->quantity = 1;
$voucher->quantity_per_user = 1;
$voucher->cumulable = 1;
$voucher->cumulable_reduction = 1;
$voucher->date_from = date('Y-m-d');
$voucher->date_to = strftime('%Y-%m-%d', strtotime('+1 month'));
$voucher->minimal = Configuration::get('BIRTHDAY_MINIMAL_ORDER');
$voucher->active = true;
if ($voucher->add()) {
Mail::Send((int) Configuration::get('PS_LANG_DEFAULT'), 'birthday', Mail::l('Happy birthday!', (int) Configuration::get('PS_LANG_DEFAULT')), array('{firstname}' => $user['firstname'], '{lastname}' => $user['lastname']), $user['email'], NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/');
} else {
echo Db::getInstance()->getMsgError();
}
}
}
示例4: dirname
$voucher->minimal = (double) Configuration::get('PS_LOYALTY_MINIMAL');
$voucher->active = 1;
$categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
if ($categories != '' and $categories != 0) {
$categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
} else {
die(Tools::displayError());
}
$languages = Language::getLanguages(true);
$default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) Configuration::get('PS_LANG_DEFAULT'));
foreach ($languages as $language) {
$text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) $language['id_lang']);
$voucher->description[(int) $language['id_lang']] = $text ? strval($text) : strval($default_text);
}
if (is_array($categories) and sizeof($categories)) {
$voucher->add(true, false, $categories);
} else {
$voucher->add();
}
/* Register order(s) which contributed to create this voucher */
LoyaltyModule::registerDiscount($voucher);
Tools::redirect('modules/loyalty/loyalty-program.php');
}
include dirname(__FILE__) . '/../../header.php';
$orders = LoyaltyModule::getAllByIdCustomer((int) $cookie->id_customer, (int) $cookie->id_lang);
$displayorders = LoyaltyModule::getAllByIdCustomer((int) $cookie->id_customer, (int) $cookie->id_lang, false, true, (int) Tools::getValue('n') > 0 ? (int) Tools::getValue('n') : 10, (int) Tools::getValue('p') > 0 ? (int) Tools::getValue('p') : 1);
$smarty->assign(array('orders' => $orders, 'displayorders' => $displayorders, 'pagination_link' => __PS_BASE_URI__ . 'modules/loyalty/loyalty-program.php', 'totalPoints' => (int) $customerPoints, 'voucher' => LoyaltyModule::getVoucherValue($customerPoints, (int) $cookie->id_currency), 'validation_id' => LoyaltyStateModule::getValidationId(), 'transformation_allowed' => $customerPoints > 0, 'page' => (int) Tools::getValue('p') > 0 ? (int) Tools::getValue('p') : 1, 'nbpagination' => (int) (Tools::getValue('n') > 0) ? (int) Tools::getValue('n') : 10, 'nArray' => array(10, 20, 50), 'max_page' => floor(sizeof($orders) / ((int) (Tools::getValue('n') > 0) ? (int) Tools::getValue('n') : 10))));
/* Discounts */
$nbDiscounts = 0;
$discounts = array();
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int) $cookie->id_customer)) {
示例5: createDiscount
private function createDiscount($id_email_type, $amount, $id_customer, $dateValidity, $description)
{
$discount = new Discount();
$discount->id_discount_type = 1;
$discount->value = (double) $amount;
$discount->id_customer = (int) $id_customer;
$discount->date_to = $dateValidity;
$discount->date_from = date('Y-m-d H:i:s');
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->cumulable = 0;
$discount->cumulable_reduction = 1;
$discount->minimal = 0;
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
$discount->description[(int) $language['id_lang']] = $description;
}
$name = 'FLW-' . (int) $id_email_type . '-' . strtoupper(Tools::passwdGen(10));
$discount->name = $name;
$discount->active = 1;
$result = $discount->add();
if (!$result) {
return false;
}
return $discount;
}
示例6: 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 $amountPaid Amount really paid by customer (in the default currency)
* @param string $paymentMethod Payment method (eg. 'Credit card')
* @param string $message Message to attach to order
*/
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false)
{
global $cart;
$cart = new Cart((int) $id_cart);
// Does order already exists ?
if (!$this->active) {
die(Tools::displayError());
}
if (Validate::isLoadedObject($cart) && $cart->OrderExists() == false) {
if ($secure_key !== false && $secure_key != $cart->secure_key) {
die(Tools::displayError());
}
// Copying data from cart
$order = new Order();
$order->id_carrier = (int) $cart->id_carrier;
$order->id_customer = (int) $cart->id_customer;
$order->id_address_invoice = (int) $cart->id_address_invoice;
$order->id_address_delivery = (int) $cart->id_address_delivery;
$vat_address = new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$order->id_currency = $currency_special ? (int) $currency_special : (int) $cart->id_currency;
$order->id_lang = (int) $cart->id_lang;
$order->id_cart = (int) $cart->id;
$customer = new Customer((int) $order->id_customer);
$order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($customer->secure_key);
$order->payment = $paymentMethod;
if (isset($this->name)) {
$order->module = $this->name;
}
$order->recyclable = $cart->recyclable;
$order->gift = (int) $cart->gift;
$order->gift_message = $cart->gift_message;
$currency = new Currency($order->id_currency);
$order->conversion_rate = $currency->conversion_rate;
$amountPaid = !$dont_touch_amount ? Tools::ps_round((double) $amountPaid, 2) : $amountPaid;
$order->total_paid_real = $amountPaid;
$order->total_products = (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order->total_products_wt = (double) $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$order->total_discounts = (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
$order->total_shipping = (double) $cart->getOrderShippingCost();
$order->carrier_tax_rate = (double) Tax::getCarrierTaxRate($cart->id_carrier, (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$order->total_wrapping = (double) abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING));
$order->total_paid = (double) Tools::ps_round((double) $cart->getOrderTotal(true, Cart::BOTH), 2);
$order->invoice_date = '0000-00-00 00:00:00';
$order->delivery_date = '0000-00-00 00:00:00';
// Amount paid by customer is not the right one -> Status = payment error
// We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php
// if ($order->total_paid != $order->total_paid_real)
// We use number_format in order to compare two string
if (number_format($order->total_paid, 2) != number_format($order->total_paid_real, 2)) {
$id_order_state = Configuration::get('PS_OS_ERROR');
}
// Creating order
if ($cart->OrderExists() == false) {
$result = $order->add();
} else {
$errorMessage = Tools::displayError('An order has already been placed using this cart.');
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart));
die($errorMessage);
}
// Next !
if ($result and isset($order->id)) {
if (!$secure_key) {
$message .= $this->l('Warning : the secure key is empty, check your payment account before validation');
}
// Optional message to attach to this order
if (isset($message) and !empty($message)) {
$msg = new Message();
$message = strip_tags($message, '<br>');
if (Validate::isCleanHtml($message)) {
$msg->message = $message;
$msg->id_order = intval($order->id);
$msg->private = 1;
$msg->add();
}
}
// Insert products from cart into order_detail table
$products = $cart->getProducts();
$productsList = '';
$db = Db::getInstance();
$query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail`
(`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `group_reduction`, `product_quantity_discount`, `product_ean13`, `product_upc`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `ecotax_tax_rate`, `discount_quantity_applied`, `download_deadline`, `download_hash`)
VALUES ';
$customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
Product::addCustomizationPrice($products, $customizedDatas);
$outOfStock = false;
$store_all_taxes = array();
foreach ($products as $key => $product) {
$productQuantity = (int) Product::getQuantity((int) $product['id_product'], $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL);
$quantityInStock = $productQuantity - (int) $product['cart_quantity'] < 0 ? $productQuantity : (int) $product['cart_quantity'];
if ($id_order_state != Configuration::get('PS_OS_CANCELED') and $id_order_state != Configuration::get('PS_OS_ERROR')) {
//.........这里部分代码省略.........
示例7: preProcess
public function preProcess()
{
global $isVirtualCart, $cookie;
parent::preProcess();
// Redirect to the good order process
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and (strpos($_SERVER['PHP_SELF'], 'order.php') === false and strpos($_SERVER['PHP_SELF'], 'cart-summary-large.php') === false)) {
Tools::redirect('order.php');
}
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) {
if (isset($_GET['step']) and $_GET['step'] == 3) {
Tools::redirect('order-opc.php?isPaymentStep=true');
}
Tools::redirect('order-opc.php');
}
if (Configuration::get('PS_CATALOG_MODE')) {
$this->errors[] = Tools::displayError('This store has not accepted your new order.');
}
if (Tools::isSubmit('submitReorder') and $id_order = (int) Tools::getValue('id_order')) {
$oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer));
$duplication = $oldCart->duplicate();
if (!$duplication or !Validate::isLoadedObject($duplication['cart'])) {
$this->errors[] = Tools::displayError('Sorry, we cannot renew your order.');
} elseif (!$duplication['success']) {
$this->errors[] = Tools::displayError('Missing items - we are unable to renew your order');
} else {
self::$cookie->id_cart = $duplication['cart']->id;
self::$cookie->write();
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
Tools::redirect('order-opc.php');
}
Tools::redirect('order.php');
}
}
if (Tools::isSubmit('submit_instructions')) {
$instructions = Tools::getValue('special_instructions');
self::$cart->gift_message = pSQL($instructions);
self::$cart->update();
Tools::redirect('order?step=3');
}
if ($this->nbProducts) {
/* check discount validity */
$cartDiscounts = self::$cart->getDiscounts();
$discountInvalid = false;
foreach ($cartDiscounts as $k => $cartDiscount) {
if ($error = self::$cart->checkDiscountValidity(new Discount((int) $cartDiscount['id_discount']), $cartDiscounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING), self::$cart->getProducts())) {
self::$cart->deleteDiscount((int) $cartDiscount['id_discount']);
$discountInvalid = true;
}
}
if ($discountInvalid) {
Tools::redirect('order-opc.php');
}
if (Tools::getValue('redeem_points')) {
$points = (int) Tools::getValue('redeem_points');
if ($points < 1) {
self::$smarty->assign('redeem_points', $points);
$this->errors[] = Tools::displayError('You can redeem minimum of 1 coin in an order.');
}
$orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$redemption_status = VBRewards::checkPointsValidity($cookie->id_customer, $points + self::$cart->getPoints(), $orderTotal);
if ($redemption_status === CAN_REDEEM_COINS) {
self::$cart->addPoints($points);
self::$smarty->assign('redeem_points', (int) self::$cart->getPoints());
} else {
if ($redemption_status === INSUFFICIENT_VALID_ORDERS) {
$this->errors[] = Tools::displayError('Coins can be redeemed from second purchase onwards.');
} else {
if ($redemption_status === MIN_CRITERIA_NOT_MET) {
$this->errors[] = Tools::displayError('Order value should be more than 100 USD to redeem coins');
}
}
}
$this->adjustPoints();
} elseif (Tools::getValue('deletePoints')) {
self::$cart->deletePoints();
}
if (Tools::isSubmit('submitAddDiscount') and Tools::getValue('discount_name')) {
$discountName = Tools::getValue('discount_name');
if (!Validate::isDiscountName($discountName)) {
$this->errors[] = Tools::displayError('Voucher name invalid.');
} else {
$discount = new Discount((int) Discount::getIdByName($discountName));
if (Validate::isLoadedObject($discount)) {
if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true)) {
$this->errors[] = $tmpError;
}
} else {
$this->errors[] = Tools::displayError('Voucher name invalid.');
}
if (!sizeof($this->errors)) {
self::$cart->addDiscount((int) $discount->id);
Tools::redirect('order-opc.php');
}
}
self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName)));
$this->adjustPoints();
} elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) {
self::$cart->deleteDiscount((int) $_GET['deleteDiscount']);
Tools::redirect('order-opc.php');
}
//.........这里部分代码省略.........
示例8: 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 $amountPaid Amount really paid by customer (in the default currency)
* @param string $paymentMethod Payment method (eg. 'Credit card')
* @param string $message Message to attach to order
*/
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false)
{
global $cart, $link, $cookie;
$id_payment_state = _PS_PS_NOT_PAID_;
$cart = new Cart((int) $id_cart);
// Does order already exists ?
if (Validate::isLoadedObject($cart) and $cart->OrderExists() == false) {
if ($secure_key !== false and $secure_key != $cart->secure_key) {
die(Tools::displayError());
}
// Copying data from cart
$order = new Order();
$order->id_carrier = (int) $cart->id_carrier;
$order->id_customer = (int) $cart->id_customer;
$order->id_address_invoice = (int) $cart->id_address_invoice;
$order->id_address_delivery = (int) $cart->id_address_delivery;
$vat_address = new Address((int) $order->id_address_delivery);
$order->id_currency = $currency_special ? (int) $currency_special : (int) $cart->id_currency;
$order->id_lang = (int) $cart->id_lang;
$order->id_cart = (int) $cart->id;
$customer = new Customer((int) $order->id_customer);
$order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($customer->secure_key);
$order->payment = $paymentMethod;
if (isset($this->name)) {
$order->module = $this->name;
}
$order->recyclable = $cart->recyclable;
$order->gift = (int) $cart->gift;
$order->gift_message = $cart->gift_message;
$currency = new Currency($order->id_currency);
$order->conversion_rate = $currency->conversion_rate;
$amountPaid = !$dont_touch_amount ? Tools::ps_round((double) $amountPaid, 2) : $amountPaid;
$order->total_paid_real = $amountPaid;
$order->total_products = (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order->total_products_wt = (double) $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$order->total_customization = $cart->getCartCustomizationCost();
$order->total_donation = round($cookie->donation_amount);
unset($cookie->donation_amount);
if (strpos($order->payment, 'COD') === false) {
$order->total_discounts = (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, true));
$order->total_paid = (double) Tools::ps_round((double) $cart->getOrderTotal(true, Cart::BOTH, true));
} else {
$order->total_discounts = (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, false));
$order->total_paid = (double) Tools::ps_round((double) $cart->getOrderTotal(true, Cart::BOTH, false));
$order->total_cod = COD_CHARGE;
}
$order->total_shipping = (double) $cart->getOrderShippingCost();
$order->carrier_tax_rate = (double) Tax::getCarrierTaxRate($cart->id_carrier, (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$order->total_wrapping = (double) abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING));
$order->invoice_date = '0000-00-00 00:00:00';
$order->delivery_date = '0000-00-00 00:00:00';
$shippingdate = $cart->getExpectedShippingDate();
$order->expected_shipping_date = pSQL($shippingdate->format('Y-m-d H:i:s'));
$order->actual_expected_shipping_date = pSQL($shippingdate->format('Y-m-d H:i:s'));
// Amount paid by customer is not the right one -> Status = payment error
// We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php
// if ($order->total_paid != $order->total_paid_real)
// We use number_format in order to compare two string
if (number_format(round($order->total_paid)) != number_format(round($order->total_paid_real))) {
$id_order_state = _PS_OS_ERROR_;
$id_payment_state = _PS_PS_NOT_PAID_;
} else {
if (strpos($order->payment, 'COD') === false) {
$id_payment_state = _PS_PS_PAID_;
}
}
//update payment status
// Creating order
if ($cart->OrderExists() == false) {
$cart_value = $cart->getOrderTotal();
if ($cart_value >= 1000) {
//if(!$cart->containsProduct(FREE_GIFT_ID, NULL, NULL))
//$cart->updateQty(1, FREE_GIFT_ID, NULL, false, 'up', TRUE);
}
$result = $order->add();
} else {
$errorMessage = Tools::displayError('An order has already been placed using this cart.');
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart));
die($errorMessage);
}
// Next !
if ($result and isset($order->id)) {
if (!$secure_key) {
$message .= $this->l('Warning : the secure key is empty, check your payment account before validation');
}
// Optional message to attach to this order
if (isset($message) and !empty($message)) {
$msg = new Message();
$message = strip_tags($message, '<br>');
if (Validate::isCleanHtml($message)) {
//.........这里部分代码省略.........
示例9: date
$voucher->description[$lang['id_lang']] = $name[$sel];
}
$voucher->name = $code;
if ($trigger[$sel]['discountType'] == 'amount') {
$voucher->id_discount_type = 2;
} else {
$voucher->id_discount_type = 1;
}
$voucher->value = $trigger[$sel]['discount'];
$voucher->quantity = 1;
$voucher->quantity_per_user = 1;
}
$voucher->id_customer = $customer['id_customer'];
$voucher->date_from = date('Y-m-d');
$voucher->date_to = date('Y-m-d', time() + 31 * 24 * 3600);
$voucher->active = 1;
$voucher->add();
}
/* mail sending */
if ($res = $mailjet->sendMail($subject, $temp, $customer['email'])) {
DB::getInstance()->execute('
INSERT INTO `' . _DB_PREFIX_ . 'mj_trigger`(id_customer,id_target,type,date)
VALUES(' . $customer['id_customer'] . ',' . $customer[$sql_target[$sel]] . ',' . $sel . ',\'' . date('Y-m-d') . '\')');
}
}
}
}
echo 'OK';
} else {
echo 'KO';
}
示例10: postProcess
/**
* @global object $cookie Employee cookie necessary to keep trace of his/her actions
*/
public function postProcess()
{
global $currentIndex, $cookie;
/* Update shipping number */
if (Tools::isSubmit('submitShippingNumber') and $id_order = (int) Tools::getValue('id_order') and Validate::isLoadedObject($order = new Order($id_order))) {
if ($this->tabAccess['edit'] === '1') {
if (!$order->hasBeenShipped()) {
die(Tools::displayError('The shipping number can only be set once the order has been shipped.'));
}
$_GET['view' . $this->table] = true;
$shipping_number = pSQL(Tools::getValue('shipping_number'));
$order->shipping_number = $shipping_number;
$order->update();
if ($shipping_number) {
global $_LANGMAIL;
$customer = new Customer((int) $order->id_customer);
$carrier = new Carrier((int) $order->id_carrier);
if (!Validate::isLoadedObject($customer) or !Validate::isLoadedObject($carrier)) {
die(Tools::displayError());
}
$templateVars = array('{order_amount}' => Tools::displayPrice($order->total_paid, $currency, false), '{carrier_name}' => $carrier->name, '{tracking_number}' => $order->shipping_number, '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => (int) $order->id);
if (strpos($order->payment, 'COD') === false) {
@Mail::Send((int) $order->id_lang, 'in_transit', Mail::l('Your order #' . $order->id . ' with IndusDiva.com has been shipped'), $templateVars, $customer->email, $customer->firstname . ' ' . $customer->lastname);
} else {
@Mail::Send((int) $order->id_lang, 'in_transit_cod', Mail::l('Your order #' . $order->id . ' with IndusDiva.com has been shipped'), $templateVars, $customer->email, $customer->firstname . ' ' . $customer->lastname);
}
//Send SMS
$delivery = new Address((int) $order->id_address_delivery);
if (strpos($order->payment, 'COD') === false) {
$smsText = 'Dear customer, your order #' . $order->id . ' at IndusDiva.com has been shipped via ' . $carrier->name . '. The airway bill no is ' . $order->shipping_number . '. www.indusdiva.com';
} else {
$smsText = 'Dear customer, your order #' . $order->id . ' at IndusDiva.com has been shipped. Carrier: ' . $carrier->name . ', AWB No. : ' . $order->shipping_number . ', Amount payable:' . Tools::displayPrice($order->total_paid, $currency, false) . '. www.indusdiva.com';
}
Tools::sendSMS($delivery->phone_mobile, $smsText);
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
} elseif (Tools::isSubmit('submitExpectedShippingDate') and $id_order = (int) Tools::getValue('id_order') and Validate::isLoadedObject($order = new Order($id_order))) {
$dateshipping = new DateTime(Tools::getValue('expected_shipping_date'));
$order->expected_shipping_date = pSQL($dateshipping->format('Y-m-d H:i:s'));
$order->update();
$order = new Order($id_order);
} elseif (Tools::isSubmit('submitCarrier') and $id_order = (int) Tools::getValue('id_order') and Validate::isLoadedObject($order = new Order($id_order))) {
$order->shipping_number = '';
$order->id_carrier = (int) Tools::getValue('id_carrier');
$order->update();
$order = new Order($id_order);
} elseif (Tools::isSubmit('submitState') and $id_order = (int) Tools::getValue('id_order') and Validate::isLoadedObject($order = new Order($id_order))) {
if ($this->tabAccess['edit'] === '1') {
$_GET['view' . $this->table] = true;
if (!($newOrderStatusId = (int) Tools::getValue('id_order_state'))) {
$this->_errors[] = Tools::displayError('Invalid new order status');
} else {
if ($newOrderStatusId == _PS_OS_DELIVERED_ && strpos($order->payment, 'COD')) {
$paymentHistory = new OrderPaymentHistory();
$paymentHistory->id_order = (int) $id_order;
$paymentHistory->id_employee = (int) $cookie->id_employee;
$paymentHistory->changeIdOrderPaymentState(_PS_PS_PAYMENT_WITH_CARRIER_, (int) $id_order);
$paymentHistory->addState();
}
$history = new OrderHistory();
$history->id_order = (int) $id_order;
$history->id_employee = (int) $cookie->id_employee;
$history->changeIdOrderState((int) $newOrderStatusId, (int) $id_order);
$order = new Order((int) $order->id);
$carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang);
$templateVars = array();
if ($history->id_order_state == _PS_OS_SHIPPING_ and $order->shipping_number) {
$templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
} elseif ($history->id_order_state == _PS_OS_CHEQUE_) {
$templateVars = array('{cheque_name}' => Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : '', '{cheque_address_html}' => Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : '');
} elseif ($history->id_order_state == _PS_OS_BANKWIRE_) {
$templateVars = array('{bankwire_owner}' => Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : '', '{bankwire_details}' => Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : '', '{bankwire_address}' => Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : '');
}
if ($history->id_order_state == _PS_OS_CANCELED_) {
$this->cancelOrder($id_order);
}
if ($history->addWithemail(true, $templateVars)) {
Tools::redirectAdmin($currentIndex . '&id_order=' . $id_order . '&vieworder' . '&token=' . $this->token);
}
$this->_errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.');
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
} elseif (isset($_POST['submitMessage'])) {
$_GET['view' . $this->table] = true;
if ($this->tabAccess['edit'] === '1') {
if (!($id_order = (int) Tools::getValue('id_order')) or !($id_customer = (int) Tools::getValue('id_customer'))) {
$this->_errors[] = Tools::displayError('An error occurred before sending message');
} elseif (!Tools::getValue('message')) {
$this->_errors[] = Tools::displayError('Message cannot be blank');
} else {
/* Get message rules and and check fields validity */
$rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
foreach ($rules['required'] as $field) {
//.........这里部分代码省略.........
示例11: createDiscount
private function createDiscount($id_email_type, $amount, $id_customer, $dateValidity, $description)
{
$discount = new Discount();
$discount->id_discount_type = 1;
$discount->value = floatval($amount);
$discount->id_customer = intval($id_customer);
$discount->date_to = $dateValidity;
$discount->date_from = date('Y-m-d H:i:s');
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->cumulable = 0;
$discount->cumulable_reduction = 1;
$discount->minimal = 0;
$discount->description[1] = $description;
$discount->description[2] = $description;
$name = 'FLW-' . intval($id_email_type) . '-' . strtoupper(Tools::passwdGen(10));
$discount->name = $name;
$discount->active = 1;
$result = $discount->add();
if (!$result) {
return false;
}
return $discount;
}
示例12: createOrderDiscount
public static function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0)
{
$languages = Language::getLanguages($order);
$products = $order->getProducts(false, $productList, $qtyList);
$total = $order->getTotalProductsWithTaxes($products);
if ($shipping_cost) {
$total += $order->total_shipping;
}
// create discount
$voucher = new Discount();
$voucher->id_discount_type = 2;
foreach ($languages as $language) {
$voucher->description[$language['id_lang']] = strval($name) . intval($order->id);
}
$voucher->value = floatval($total);
$voucher->name = 'V0C' . intval($order->id_customer) . 'O' . intval($order->id);
$voucher->id_customer = intval($order->id_customer);
$voucher->quantity = 1;
$voucher->quantity_per_user = 1;
$voucher->cumulable = 1;
$voucher->cumulable_reduction = 1;
$voucher->minimal = floatval($voucher->value);
$voucher->active = 1;
$now = time();
$voucher->date_from = date('Y-m-d H:i:s', $now);
$voucher->date_to = date('Y-m-d H:i:s', $now + 60 * 60 * 24 * 184);
if (!$voucher->validateFieldsLang(false) or !$voucher->add()) {
return false;
}
// set correct name
$voucher->name = 'V' . intval($voucher->id) . 'C' . intval($order->id_customer) . 'O' . $order->id;
if (!$voucher->update()) {
return false;
}
return $voucher;
}
示例13: addDotpayDiscount
/**
* Added Dotpay discount for reducing shipping cost
* @return bool
*/
private function addDotpayDiscount()
{
if (!Validate::isInt($this->config->getDotpayDiscountId())) {
$voucher = new Discount();
$voucher->id_discount_type = Discount::AMOUNT;
$voucher->name = array((int) Configuration::get('PS_LANG_DEFAULT') => 'Discount for online shopping');
$voucher->description = array((int) Configuration::get('PS_LANG_DEFAULT') => 'Online payment');
$voucher->value = 0;
$voucher->code = md5(date("d-m-Y H-i-s"));
$voucher->quantity = 9999999;
$voucher->quantity_per_user = 9999999;
$voucher->cumulable = 1;
$voucher->cumulable_reduction = 1;
$voucher->active = 1;
$voucher->cart_display = 1;
$now = time();
$voucher->date_from = date('Y-m-d H:i:s', $now);
$voucher->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365.25 * 50);
if (!$voucher->add()) {
return false;
}
$this->config->setDotpayDiscountId($voucher->id);
}
return true;
}
示例14: registerDiscount
public function registerDiscount($id_customer, $register = false, $id_currency = 0)
{
$configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_PERCENTAGE', 'REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency));
$discount = new Discount();
$discount->id_discount_type = (int) $configurations['REFERRAL_DISCOUNT_TYPE'];
/* % */
if ($configurations['REFERRAL_DISCOUNT_TYPE'] == 1) {
$discount->value = (double) $configurations['REFERRAL_PERCENTAGE'];
} elseif ($configurations['REFERRAL_DISCOUNT_TYPE'] == 2 and isset($configurations['REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency])) {
$discount->value = (double) $configurations['REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency];
} else {
$discount->value = 0;
}
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->date_from = date('Y-m-d H:i:s', time());
$discount->date_to = date('Y-m-d H:i:s', time() + 31536000);
// + 1 year
$discount->name = $this->getDiscountPrefix() . Tools::passwdGen(6);
$discount->description = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION');
$discount->id_customer = (int) $id_customer;
$discount->id_currency = (int) $id_currency;
if ($discount->add()) {
if ($register != false) {
if ($register == 'sponsor') {
$this->id_discount_sponsor = (int) $discount->id;
} elseif ($register == 'sponsored') {
$this->id_discount = (int) $discount->id;
}
return $this->save();
}
return true;
}
return false;
}
示例15: Discount
}
$cart->addCartRule($voucher->id);
} else {
$voucher = new Discount();
$voucher->id_discount_type = 2;
$voucher->value = $amount;
$languages = Language::getLanguages(true);
$voucher->name = 'Fid\'Bag';
$voucher->description = 'Discount Fid\'Bag';
$voucher->id_customer = (int) $cart->id_customer;
$voucher->id_currency = (int) $cart->id_currency;
$voucher->quantity = 1;
$voucher->quantity_per_user = 1;
$voucher->cumulable = 1;
$voucher->cumulable_reduction = 1;
$voucher->minimal = (double) $voucher->value;
$voucher->include_tax = 1;
$voucher->active = 1;
$voucher->cart_display = 1;
$now = time();
$voucher->date_from = date('Y-m-d H:i:s', $now);
$voucher->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365.25);
if (!$voucher->validateFieldsLang(false) || !$voucher->add()) {
die('0');
}
$cart->addDiscount($voucher->id);
Discount::getVouchersToCartDisplay(1, $cart->id_customer);
}
}
$values = array('total' => Tools::ps_round($cart->getOrderTotal(), $currency->decimals), 'discount' => $amount);
die(Tools::jsonEncode($values));