本文整理汇总了PHP中Discount::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::getValue方法的具体用法?PHP Discount::getValue怎么用?PHP Discount::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discount
的用法示例。
在下文中一共展示了Discount::getValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDiscounts
/**
* Return cart discounts
*
* @param bool true will return discounts with basic informations
* @param bool true will erase the cache
* @result array Discounts
*/
public function getDiscounts($lite = false, $refresh = false)
{
if (!$this->id) {
return array();
}
if (!$refresh) {
if (!$lite and isset(self::$_discounts[$this->id])) {
return self::$_discounts[$this->id];
}
if ($lite and isset(self::$_discountsLite[$this->id])) {
return self::$_discountsLite[$this->id];
}
}
$result = Db::getInstance()->ExecuteS('
SELECT d.*, `id_cart`
FROM `' . _DB_PREFIX_ . 'cart_discount` c
LEFT JOIN `' . _DB_PREFIX_ . 'discount` d ON c.`id_discount` = d.`id_discount`
WHERE `id_cart` = ' . (int) $this->id);
$products = $this->getProducts();
foreach ($result as $k => $discount) {
$categories = Discount::getCategories((int) $discount['id_discount']);
$in_category = false;
foreach ($products as $product) {
if (Product::idIsOnCategoryId((int) $product['id_product'], $categories)) {
$in_category = true;
break;
}
}
if (!$in_category) {
unset($result[$k]);
}
}
if ($lite) {
self::$_discountsLite[$this->id] = $result;
return $result;
}
$total_products_wt = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$total_products = $this->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$shipping_wt = $this->getOrderShippingCost();
$shipping = $this->getOrderShippingCost(NULL, false);
self::$_discounts[$this->id] = array();
foreach ($result as $row) {
$discount = new Discount($row['id_discount'], (int) $this->id_lang);
$row['description'] = $discount->description ? $discount->description : $discount->name;
$row['value_real'] = $discount->getValue(sizeof($result), $total_products_wt, $shipping_wt, $this->id);
$row['value_tax_exc'] = $discount->getValue(sizeof($result), $total_products, $shipping, $this->id, false);
if ($row['value_real'] !== 0) {
self::$_discounts[$this->id][] = $row;
} else {
$this->deleteDiscount($row['id_discount']);
}
}
return isset(self::$_discounts[$this->id]) ? self::$_discounts[$this->id] : NULL;
}
示例2: validateOrder
//.........这里部分代码省略.........
if (!isset($store_all_taxes[$res->id])) {
$store_all_taxes[$res->id] = array();
$store_all_taxes[$res->id]['amount'] = 0;
}
$store_all_taxes[$res->id]['name'] = $res->name[(int) $order->id_lang];
$store_all_taxes[$res->id]['rate'] = $res->rate;
$unit_tax_amount = $tmp_price * ($res->rate * 0.01);
$tmp_price = $tmp_price + $unit_tax_amount;
$store_all_taxes[$res->id]['amount'] += $unit_tax_amount * $product['cart_quantity'];
}
}
/* End */
// 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 (!_PS_TAX_) {
$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')});
}
$product_price = (double) Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specificPrice, false, false);
$group_reduction = (double) GroupReduction::getValueForProduct((int) $product['id_product'], $customer->id_default_group) * 100;
if (!$group_reduction) {
$group_reduction = (double) Group::getReduction((int) $order->id_customer);
}
$quantityDiscount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], Shop::getCurrentShop(), (int) $cart->id_currency, (int) $vat_address->id_country, (int) $customer->id_default_group, (int) $product['cart_quantity']);
$unitPrice = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, 1, false, (int) $order->id_customer, NULL, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$quantityDiscountValue = $quantityDiscount ? (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100) : 0.0;
$query .= '(' . (int) $order->id . ',
' . (int) $product['id_product'] . ',
' . (isset($product['id_product_attribute']) ? (int) $product['id_product_attribute'] : 'NULL') . ',
\'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\',
' . (int) $product['cart_quantity'] . ',
' . $quantityInStock . ',
' . $product_price . ',
' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.0) . ',
' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'amount') ? !$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction'] : 0.0) . ',
' . $group_reduction . ',
' . $quantityDiscountValue . ',
' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ',
' . (empty($product['upc']) ? 'NULL' : '\'' . pSQL($product['upc']) . '\'') . ',
' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ',
' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ',
' . (double) ($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ',
\'' . (empty($tax_rate) ? '' : pSQL($product['tax'])) . '\',
' . (double) $tax_rate . ',
' . (double) Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency)) . ',
' . (double) $ecotaxTaxRate . ',
' . (($specificPrice and $specificPrice['from_quantity'] > 1) ? 1 : 0) . ',
\'' . pSQL($deadline) . '\',
\'' . pSQL($download_hash) . '\'),';
$customizationQuantity = 0;
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) {
$customizationText = '';
示例3: validateOrder
//.........这里部分代码省略.........
$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));
$deadline = $productDownload->getDeadLine();
$download_hash = $productDownload->getHash();
}
// Exclude VAT
if (Tax::excludeTaxeOption()) {
$product['tax'] = 0;
$product['rate'] = 0;
$tax = 0;
} else {
$tax = Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']), intval($order->id_address_delivery));
}
$currentDate = date('Y-m-d H:m:i');
if ($product['reduction_from'] != $product['reduction_to'] and ($currentDate > $product['reduction_to'] or $currentDate < $product['reduction_from'])) {
$reduction_percent = 0.0;
$reduction_amount = 0.0;
} else {
$reduction_percent = floatval($product['reduction_percent']);
$reduction_amount = Tools::ps_round(floatval($product['reduction_price']) / (1 + floatval($tax) / 100), 6);
}
// Quantity discount
$reduc = 0.0;
if ($product['cart_quantity'] > 1 and $qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['cart_quantity'])) {
$reduc = QuantityDiscount::getValue($price_wt, $qtyD->id_discount_type, $qtyD->value, new Currency(intval($order->id_currency)));
}
$query .= '(' . intval($order->id) . ',
' . intval($product['id_product']) . ',
' . (isset($product['id_product_attribute']) ? intval($product['id_product_attribute']) : 'NULL') . ',
\'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\',
' . intval($product['cart_quantity']) . ',
' . $quantityInStock . ',
' . floatval(Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, Product::getTaxCalculationMethod(intval($order->id_customer)) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery))) . ',
' . floatval($reduction_percent) . ',
' . floatval($reduction_amount) . ',
' . floatval($reduc) . ',
' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ',
' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ',
' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ',
' . floatval($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ',
\'' . (!$tax ? '' : pSQL($product['tax'])) . '\',
' . floatval($tax) . ',
' . floatval($product['ecotax']) . ',
' . (int) QuantityDiscount::getDiscountFromQuantity(intval($product['id_product']), intval($product['cart_quantity'])) . ',
\'' . pSQL($deadline) . '\',
\'' . pSQL($download_hash) . '\'),';
$priceWithTax = number_format($price * (($tax + 100) / 100), 2, '.', '');
$customizationQuantity = 0;
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) {
$customizationText = '';
foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) {
if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) {
foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) {
$customizationText .= $text['name'] . $this->l(':') . ' ' . $text['value'] . ', ';
}
}
}
示例4: validateOrder
//.........这里部分代码省略.........
$voucher->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365);
/* 365 days */
$voucher->add();
$productObj = new Product($product['id_product'], true, 1);
$idImage = $productObj->getCoverWs();
if ($idImage) {
$idImage = $productObj->id . '-' . $idImage;
} else {
$idImage = Language::getIsoById(1) . '-default';
}
$params = array();
$params['{voucher_code}'] = $voucher->name;
$params['{freinds_name}'] = $friendsName;
$params['{gift_message}'] = $giftMessage;
$params['{product_name}'] = $product['name'];
$params['{voucher_value}'] = $voucher->value;
$params['{image_url}'] = _PS_BASE_URL_ . _PS_IMG_ . 'banners/' . $productObj->location;
$params['{sender_name}'] = $customer->firstname . ' ' . $customer->lastname;
$subject = $friendsName . ', You Have Received A $' . $voucher->value . ' IndusDiva Gift Card';
@Mail::Send(1, 'gift_card', $subject, $params, $friendsEmail, $friendsName, 'care@indusdiva.com', 'Indusdiva.com', NULL, NULL, _PS_MAIL_DIR_, true);
@Mail::Send(1, 'gift_card', $subject, $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, 'care@indusdiva.com', 'Indusdiva.com', NULL, NULL, _PS_MAIL_DIR_, true);
}
}
// end foreach ($products)
$query = rtrim($query, ',');
$result = $db->Execute($query);
// Insert discounts from cart into order_discount table
$discounts = $cart->getDiscounts();
$discountsList = '';
$total_discount_value = 0;
$shrunk = false;
foreach ($discounts as $discount) {
$objDiscount = new Discount((int) $discount['id_discount'], $order->id_lang);
$value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $order->total_shipping, $cart->id);
if ($objDiscount->id_discount_type == 2 || $objDiscount->id_discount_type == 4 and in_array($objDiscount->behavior_not_exhausted, array(1, 2))) {
$shrunk = true;
}
if ($shrunk and $total_discount_value + $value > $order->total_products + $order->total_shipping + $order->total_wrapping) {
$amount_to_add = $order->total_products + $order->total_shipping + $order->total_wrapping - $total_discount_value;
if ($objDiscount->id_discount_type == 2 || $objDiscount->id_discount_type == 4 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;
@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