当前位置: 首页>>代码示例>>PHP>>正文


PHP Discount::update方法代码示例

本文整理汇总了PHP中Discount::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::update方法的具体用法?PHP Discount::update怎么用?PHP Discount::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discount的用法示例。


在下文中一共展示了Discount::update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
     // Totals are stored in the order currency (or at least should be)
     $total = $order->getTotalProductsWithTaxes($products);
     $discounts = $order->getDiscounts(true);
     $total_tmp = $total;
     foreach ($discounts as $discount) {
         if ($discount['id_discount_type'] == 1) {
             $total -= $total_tmp * ($discount['value'] / 100);
         } elseif ($discount['id_discount_type'] == 2) {
             $total -= $discount['value'] * ($total_tmp / $order->total_products_wt);
         }
     }
     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) . (int) $order->id;
     }
     $voucher->value = (double) $total;
     $voucher->name = 'V0C' . (int) $order->id_customer . 'O' . (int) $order->id;
     $voucher->id_customer = (int) $order->id_customer;
     $voucher->id_currency = (int) $order->id_currency;
     $voucher->quantity = 1;
     $voucher->quantity_per_user = 1;
     $voucher->cumulable = 1;
     $voucher->cumulable_reduction = 1;
     $voucher->minimal = (double) $voucher->value;
     $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);
     /* 1 year */
     if (!$voucher->validateFieldsLang(false) or !$voucher->add()) {
         return false;
     }
     // set correct name
     $voucher->name = 'V' . (int) $voucher->id . 'C' . (int) $order->id_customer . 'O' . $order->id;
     if (!$voucher->update()) {
         return false;
     }
     return $voucher;
 }
开发者ID:greench,项目名称:prestashop,代码行数:49,代码来源:Discount.php

示例2: 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 cart')
     * @param string $message Message to attach to order
     */
    function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false)
    {
        global $cart;
        $cart = new Cart(intval($id_cart));
        // Does order already exists ?
        if (Validate::isLoadedObject($cart) and $cart->OrderExists() === 0) {
            // Copying data from cart
            $order = new Order();
            $order->id_carrier = intval($cart->id_carrier);
            $order->id_customer = intval($cart->id_customer);
            $order->id_address_invoice = intval($cart->id_address_invoice);
            $order->id_address_delivery = intval($cart->id_address_delivery);
            $vat_address = new Address(intval($order->id_address_delivery));
            $id_zone = Address::getZoneById(intval($vat_address->id));
            $order->id_currency = $currency_special ? intval($currency_special) : intval($cart->id_currency);
            $order->id_lang = intval($cart->id_lang);
            $order->id_cart = intval($cart->id);
            $customer = new Customer(intval($order->id_customer));
            $order->secure_key = pSQL($customer->secure_key);
            $order->payment = Tools::substr($paymentMethod, 0, 32);
            if (isset($this->name)) {
                $order->module = $this->name;
            }
            $order->recyclable = $cart->recyclable;
            $order->gift = intval($cart->gift);
            $order->gift_message = $cart->gift_message;
            $currency = new Currency($order->id_currency);
            $amountPaid = !$dont_touch_amount ? Tools::ps_round(floatval($amountPaid), 2) : $amountPaid;
            $order->total_paid_real = $amountPaid;
            $order->total_products = floatval($cart->getOrderTotal(false, 1));
            $order->total_products_wt = floatval($cart->getOrderTotal(true, 1));
            $order->total_discounts = floatval(abs($cart->getOrderTotal(true, 2)));
            $order->total_shipping = floatval($cart->getOrderShippingCost());
            $order->total_wrapping = floatval(abs($cart->getOrderTotal(true, 6)));
            $order->total_paid = floatval(Tools::ps_round(floatval($cart->getOrderTotal(true, 3)), 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
            if ($order->total_paid != $order->total_paid_real) {
                $id_order_state = _PS_OS_ERROR_;
            }
            // Creating order
            if ($cart->OrderExists() === 0) {
                $result = $order->add();
            } else {
                die(Tools::displayError('An order has already been placed using this cart'));
            }
            // Next !
            if ($result and isset($order->id)) {
                // 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)) {
                        $message = $this->l('Payment message is not valid, please check your module!');
                    }
                    $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`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `discount_quantity_applied`, `download_deadline`, `download_hash`)
				VALUES ';
                $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart));
                Product::addCustomizationPrice($products, $customizedDatas);
                foreach ($products as $key => $product) {
                    $outOfStock = false;
                    $productQuantity = intval(Product::getQuantity(intval($product['id_product']), $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL));
                    $quantityInStock = $productQuantity - intval($product['cart_quantity']) < 0 ? $productQuantity : intval($product['cart_quantity']);
                    if ($id_order_state != _PS_OS_CANCELED_ and $id_order_state != _PS_OS_ERROR_) {
                        if (($updateResult = Product::updateQuantity($product)) === false or $updateResult === -1) {
                            $outOfStock = true;
                        }
                        if (!$outOfStock) {
                            $product['stock_quantity'] -= $product['cart_quantity'];
                        }
                        Hook::updateQuantity($product, $order);
                    }
                    $price = Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 6, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery));
                    $price_wt = Product::getPriceStatic(intval($product['id_product']), true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery));
                    // Add some informations for virtual products
                    $deadline = '0000-00-00 00:00:00';
                    $download_hash = NULL;
                    if ($id_product_download = ProductDownload::getIdFromIdProduct(intval($product['id_product']))) {
                        $productDownload = new ProductDownload(intval($id_product_download));
//.........这里部分代码省略.........
开发者ID:vincent,项目名称:theinvertebrates,代码行数:101,代码来源:PaymentModule.php

示例3: validateOrder


//.........这里部分代码省略.........
                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')) {
                        if (Product::updateQuantity($product, (int) $order->id)) {
                            $product['stock_quantity'] -= $product['cart_quantity'];
                        }
                        if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) {
                            $outOfStock = true;
                        }
                        Product::updateDefaultAttribute($product['id_product']);
                    }
                    $price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 6, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
                    $price_wt = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 2, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
                    /* Store tax info */
                    $id_country = (int) Country::getDefaultCountryId();
                    $id_state = 0;
                    $id_county = 0;
                    $rate = 0;
                    $id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
                    $address_infos = Address::getCountryAndState($id_address);
                    if ($address_infos['id_country']) {
                        $id_country = (int) $address_infos['id_country'];
                        $id_state = (int) $address_infos['id_state'];
                        $id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
                    }
                    $allTaxes = TaxRulesGroup::getTaxes((int) Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product']), $id_country, $id_state, $id_county);
                    // If its a freeOrder, there will be no calculation
                    if ($order->total_products > 0) {
                        // remove order discount quotepart on product price in order to obtain the real tax
                        $ratio = $price / $order->total_products;
                        $order_reduction_amount = (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS)) * $ratio;
                        $tmp_price = $price - $order_reduction_amount;
                        foreach ($allTaxes as $res) {
                            if (!isset($store_all_taxes[$res->id])) {
                                $store_all_taxes[$res->id] = array();
                                $store_all_taxes[$res->id]['amount'] = 0;
开发者ID:Evil1991,项目名称:PrestaShop-1.4,代码行数:67,代码来源:PaymentModule.php

示例4: 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');
         }
//.........这里部分代码省略.........
开发者ID:priyankajsr19,项目名称:indusdiva2,代码行数:101,代码来源:ParentOrderController.php

示例5: 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;
 }
开发者ID:sealence,项目名称:local,代码行数:36,代码来源:Discount.php

示例6: validateOrder


//.........这里部分代码省略.........
                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`, `customization`)
				VALUES ';
                $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
                Product::addCustomizationPrice($products, $customizedDatas);
                $outOfStock = false;
                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 != _PS_OS_CANCELED_ and $id_order_state != _PS_OS_ERROR_) {
                        if (Product::updateQuantity($product, (int) $order->id)) {
                            $product['stock_quantity'] -= $product['cart_quantity'];
                        }
                        if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) {
                            $outOfStock = true;
                        }
                        if ($product['stock_quantity'] < 1) {
                            SolrSearch::updateProduct((int) $product['id_product']);
                        }
                        Product::updateDefaultAttribute($product['id_product']);
                    }
                    $price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 6, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
                    $price_wt = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 2, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
                    // Add some informations for virtual products
                    $deadline = '0000-00-00 00:00:00';
                    $download_hash = NULL;
                    if ($id_product_download = ProductDownload::getIdFromIdProduct((int) $product['id_product'])) {
                        $productDownload = new ProductDownload((int) $id_product_download);
                        $deadline = $productDownload->getDeadLine();
                        $download_hash = $productDownload->getHash();
                    }
                    // Exclude VAT
                    if (Tax::excludeTaxeOption()) {
                        $product['tax'] = 0;
                        $product['rate'] = 0;
                        $tax_rate = 0;
                    } else {
                        $tax_rate = Tax::getProductTaxRate((int) $product['id_product'], $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
                    }
                    $ecotaxTaxRate = 0;
                    if (!empty($product['ecotax'])) {
                        $ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
                    }
开发者ID:priyankajsr19,项目名称:indusdiva2,代码行数:67,代码来源:PaymentModule.php


注:本文中的Discount::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。