本文整理汇总了PHP中CartRule::getCustomerCartRules方法的典型用法代码示例。如果您正苦于以下问题:PHP CartRule::getCustomerCartRules方法的具体用法?PHP CartRule::getCustomerCartRules怎么用?PHP CartRule::getCustomerCartRules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CartRule
的用法示例。
在下文中一共展示了CartRule::getCustomerCartRules方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initContent
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
$cart_rules = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, false);
$nb_cart_rules = count($cart_rules);
$this->context->smarty->assign(array('nb_cart_rules' => (int) $nb_cart_rules, 'cart_rules' => $cart_rules));
$this->setTemplate(_PS_THEME_DIR_ . 'discount.tpl');
}
示例2: _assignSummaryInformations
protected function _assignSummaryInformations()
{
$summary = $this->context->cart->getSummaryDetails();
$customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id);
// override customization tax rate with real tax (tax rules)
if ($customizedDatas) {
foreach ($summary['products'] as &$productUpdate) {
$productId = (int) isset($productUpdate['id_product']) ? $productUpdate['id_product'] : $productUpdate['product_id'];
$productAttributeId = (int) isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id'];
if (isset($customizedDatas[$productId][$productAttributeId])) {
$productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
}
}
Product::addCustomizationPrice($summary['products'], $customizedDatas);
}
$cart_product_context = Context::getContext()->cloneContext();
foreach ($summary['products'] as $key => &$product) {
$product['quantity'] = $product['cart_quantity'];
// for compatibility with 1.2 themes
if ($cart_product_context->shop->id != $product['id_shop']) {
$cart_product_context->shop = new Shop((int) $product['id_shop']);
}
$product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], _PS_PRICE_COMPUTE_PRECISION_, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context);
/**
* ABU edit: variable is_discount set à 1 à tord, calcul foireux de presta
* @bugfix: https://github.com/PrestaShop/PrestaShop/commit/379e28b341730ea95c0b2d6567817305ea841b23
* @perso: soustraction de l'ecotax au price_without_specific_price @else
*/
if (Product::getTaxCalculationMethod()) {
// $product['is_discounted'] = $product['price_without_specific_price'] != Tools::ps_round($product['price'], _PS_PRICE_COMPUTE_PRECISION_);
$product['is_discounted'] = Tools::ps_round($product['price_without_specific_price'], _PS_PRICE_COMPUTE_PRECISION_) != Tools::ps_round($product['price'], _PS_PRICE_COMPUTE_PRECISION_);
} else {
// $product['is_discounted'] = $product['price_without_specific_price'] != Tools::ps_round($product['price_wt'], _PS_PRICE_COMPUTE_PRECISION_);
$product['is_discounted'] = Tools::ps_round($product['price_without_specific_price'] - $product['ecotax'], _PS_PRICE_COMPUTE_PRECISION_) != Tools::ps_round($product['price_wt'], _PS_PRICE_COMPUTE_PRECISION_);
}
}
// Get available cart rules and unset the cart rules already in the cart
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart);
$cart_cart_rules = $this->context->cart->getCartRules();
foreach ($available_cart_rules as $key => $available_cart_rule) {
if (!$available_cart_rule['highlight'] || strpos($available_cart_rule['code'], CartRule::BO_ORDER_CODE_PREFIX) === 0) {
unset($available_cart_rules[$key]);
continue;
}
foreach ($cart_cart_rules as $cart_cart_rule) {
if ($available_cart_rule['id_cart_rule'] == $cart_cart_rule['id_cart_rule']) {
unset($available_cart_rules[$key]);
continue 2;
}
}
}
$show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE');
$this->context->smarty->assign($summary);
$this->context->smarty->assign(array('token_cart' => Tools::getToken(false), 'isLogged' => $this->isLogged, 'isVirtualCart' => $this->context->cart->isVirtualCart(), 'productNumber' => $this->context->cart->nbProducts(), 'voucherAllowed' => CartRule::isFeatureActive(), 'shippingCost' => $this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => $this->context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'lastProductAdded' => $this->context->cart->getLastProduct(), 'displayVouchers' => $available_cart_rules, 'show_option_allow_separate_package' => $show_option_allow_separate_package, 'smallSize' => Image::getSize(ImageType::getFormatedName('small'))));
$this->context->smarty->assign(array('HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)));
}
示例3: initContent
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
$cart_rules = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, false);
$nb_cart_rules = count($cart_rules);
foreach ($cart_rules as &$discount) {
$discount['value'] = Tools::convertPriceFull($discount['value'], new Currency((int) $discount['reduction_currency']), new Currency((int) $this->context->cart->id_currency));
}
$this->context->smarty->assign(array('nb_cart_rules' => (int) $nb_cart_rules, 'cart_rules' => $cart_rules, 'discount' => $cart_rules, 'nbDiscounts' => (int) $nb_cart_rules));
$this->setTemplate(_PS_THEME_DIR_ . 'discount.tpl');
}
示例4: initContent
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
$cart_rules = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, true, true);
$nb_cart_rules = count($cart_rules);
foreach ($cart_rules as $key => &$discount) {
if ($discount['quantity_for_user'] === 0) {
unset($cart_rules[$key]);
}
$discount['value'] = Tools::convertPriceFull($discount['value'], new Currency((int) $discount['reduction_currency']), new Currency((int) $this->context->cart->id_currency));
if ($discount['gift_product'] !== 0) {
$product = new Product((int) $discount['gift_product']);
if (isset($product->name)) {
$discount['gift_product_name'] = current($product->name);
}
}
}
$this->context->smarty->assign(array('nb_cart_rules' => (int) $nb_cart_rules, 'cart_rules' => $cart_rules, 'discount' => $cart_rules, 'nbDiscounts' => (int) $nb_cart_rules));
$this->setTemplate(_PS_THEME_DIR_ . 'discount.tpl');
}
示例5: getTemplateVarCartRules
public function getTemplateVarCartRules()
{
$cart_rules = [];
$vouchers = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, false);
foreach ($vouchers as $key => $voucher) {
$cart_rules[$key] = $voucher;
$cart_rules[$key]['voucher_date'] = Tools::displayDate($voucher['date_to'], null, false);
$cart_rules[$key]['voucher_minimal'] = $voucher['minimum_amount'] > 0 ? Tools::displayPrice($voucher['minimum_amount'], (int) $voucher['minimum_amount_currency']) : $this->trans('None', array(), 'Shop.Theme');
$cart_rules[$key]['voucher_cumulable'] = $voucher['cumulable'] ? $this->trans('Yes', array(), 'Shop.Theme') : $this->trans('No', array(), 'Shop.Theme');
if ($voucher['id_discount_type'] == 1) {
$cart_rules[$key]['value'] = sprintf('%s%%', $voucher['value']);
} elseif ($voucher['id_discount_type'] == 2) {
$cart_rules[$key]['value'] = sprintf('%s ' . ($voucher['reduction_tax'] ? $this->trans('Tax included', array(), 'Shop.Theme.Checkout') : $this->trans('Tax excluded', array(), 'Shop.Theme.Checkout')), Tools::displayPrice($voucher['value'], (int) $voucher['reduction_currency']));
} elseif ($voucher['id_discount_type'] == 3) {
$cart_rules[$key]['value'] = $this->trans('Free shipping', array(), 'Shop.Theme.Checkout');
} else {
$cart_rules[$key]['value'] = '-';
}
}
return $cart_rules;
}
示例6: getDeliveryOptionList
//.........这里部分代码省略.........
$best_price_carrier[$id_carrier]['product_list'] = array_merge($best_price_carrier[$id_carrier]['product_list'], $packages[$id_package]['product_list']);
$best_price_carrier[$id_carrier]['instance'] = $carriers_instance[$id_carrier];
}
// Add the delivery option with best price as best price
$delivery_option_list[$id_address][$key] = array('carrier_list' => $best_price_carrier, 'is_best_price' => true, 'is_best_grade' => false, 'unique_carrier' => count($best_price_carrier) <= 1);
// Reset $best_grade_carrier, it's now an array
$best_grade_carrier = array();
$key = '';
// Get the delivery option with the best grade
foreach ($best_grade_carriers as $id_package => $id_carrier) {
$key .= $id_carrier . ',';
if (!isset($best_grade_carrier[$id_carrier])) {
$best_grade_carrier[$id_carrier] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array());
}
$best_grade_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$best_grade_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];
$best_grade_carrier[$id_carrier]['package_list'][] = $id_package;
$best_grade_carrier[$id_carrier]['product_list'] = array_merge($best_grade_carrier[$id_carrier]['product_list'], $packages[$id_package]['product_list']);
$best_grade_carrier[$id_carrier]['instance'] = $carriers_instance[$id_carrier];
}
// Add the delivery option with best grade as best grade
if (!isset($delivery_option_list[$id_address][$key])) {
$delivery_option_list[$id_address][$key] = array('carrier_list' => $best_grade_carrier, 'is_best_price' => false, 'unique_carrier' => count($best_grade_carrier) <= 1);
}
$delivery_option_list[$id_address][$key]['is_best_grade'] = true;
// Get all delivery options with a unique carrier
foreach ($common_carriers as $id_carrier) {
$key = '';
$package_list = array();
$product_list = array();
$price_with_tax = 0;
$price_without_tax = 0;
foreach ($packages as $id_package => $package) {
$key .= $id_carrier . ',';
$price_with_tax += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$price_without_tax += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];
$package_list[] = $id_package;
$product_list = array_merge($product_list, $package['product_list']);
}
if (!isset($delivery_option_list[$id_address][$key])) {
$delivery_option_list[$id_address][$key] = array('is_best_price' => false, 'is_best_grade' => false, 'unique_carrier' => true, 'carrier_list' => array($id_carrier => array('price_with_tax' => $price_with_tax, 'price_without_tax' => $price_without_tax, 'instance' => $carriers_instance[$id_carrier], 'package_list' => $package_list, 'product_list' => $product_list)));
} else {
$delivery_option_list[$id_address][$key]['unique_carrier'] = count($delivery_option_list[$id_address][$key]['carrier_list']) <= 1;
}
}
}
$cart_rules = CartRule::getCustomerCartRules(Context::getContext()->cookie->id_lang, Context::getContext()->cookie->id_customer, true);
$free_carriers_rules = array();
foreach ($cart_rules as $cart_rule) {
if ($cart_rule['free_shipping'] && $cart_rule['carrier_restriction']) {
$cr = new CartRule((int) $cart_rule['id_cart_rule']);
if (Validate::isLoadedObject($cr)) {
$carriers = $cr->getAssociatedRestrictions('carrier', true, false);
if (is_array($carriers) && count($carriers) && isset($carriers['selected'])) {
foreach ($carriers['selected'] as $carrier) {
if (isset($carrier['id_carrier']) && $carrier['id_carrier']) {
$free_carriers_rules[] = (int) $carrier['id_carrier'];
}
}
}
}
}
}
// For each delivery options :
// - Set the carrier list
// - Calculate the price
// - Calculate the average position
foreach ($delivery_option_list as $id_address => $delivery_option) {
foreach ($delivery_option as $key => $value) {
$total_price_with_tax = 0;
$total_price_without_tax = 0;
$position = 0;
foreach ($value['carrier_list'] as $id_carrier => $data) {
$total_price_with_tax += $data['price_with_tax'];
$total_price_without_tax += $data['price_without_tax'];
$total_price_without_tax_with_rules = in_array($id_carrier, $free_carriers_rules) ? 0 : $total_price_without_tax;
if (!isset($carrier_collection[$id_carrier])) {
$carrier_collection[$id_carrier] = new Carrier($id_carrier);
}
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance'] = $carrier_collection[$id_carrier];
if (file_exists(_PS_SHIP_IMG_DIR_ . $id_carrier . '.jpg')) {
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['logo'] = _THEME_SHIP_DIR_ . $id_carrier . '.jpg';
} else {
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['logo'] = false;
}
$position += $carrier_collection[$id_carrier]->position;
}
$delivery_option_list[$id_address][$key]['total_price_with_tax'] = $total_price_with_tax;
$delivery_option_list[$id_address][$key]['total_price_without_tax'] = $total_price_without_tax;
$delivery_option_list[$id_address][$key]['is_free'] = !$total_price_without_tax_with_rules ? true : false;
$delivery_option_list[$id_address][$key]['position'] = $position / count($value['carrier_list']);
}
}
// Sort delivery option list
foreach ($delivery_option_list as &$array) {
uasort($array, array('Cart', 'sortDeliveryOptionList'));
}
$cache = $delivery_option_list;
return $delivery_option_list;
}
示例7: getVouchersToCartDisplay
/**
* @deprecated 1.5.0.1
*/
public static function getVouchersToCartDisplay($id_lang, $id_customer)
{
return CartRule::getCustomerCartRules($id_lang, $id_customer);
}
示例8: _assignSummaryInformations
protected function _assignSummaryInformations()
{
$summary = $this->context->cart->getSummaryDetails();
$customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id);
// override customization tax rate with real tax (tax rules)
if ($customizedDatas) {
foreach ($summary['products'] as &$productUpdate) {
$productId = (int) (isset($productUpdate['id_product']) ? $productUpdate['id_product'] : $productUpdate['product_id']);
$productAttributeId = (int) (isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']);
if (isset($customizedDatas[$productId][$productAttributeId])) {
$productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
}
}
Product::addCustomizationPrice($summary['products'], $customizedDatas);
}
$cart_product_context = Context::getContext()->cloneContext();
foreach ($summary['products'] as $key => &$product) {
$product['quantity'] = $product['cart_quantity'];
// for compatibility with 1.2 themes
if ($cart_product_context->shop->id != $product['id_shop']) {
$cart_product_context->shop = new Shop((int) $product['id_shop']);
}
$product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context);
if (Product::getTaxCalculationMethod()) {
$product['is_discounted'] = $product['price_without_specific_price'] != $product['price'];
} else {
$product['is_discounted'] = $product['price_without_specific_price'] != $product['price_wt'];
}
}
// Get available cart rules and unset the cart rules already in the cart
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart);
$cart_cart_rules = $this->context->cart->getCartRules();
foreach ($available_cart_rules as $key => $available_cart_rule) {
if (!$available_cart_rule['highlight'] || strpos($available_cart_rule['code'], 'BO_ORDER_') === 0) {
unset($available_cart_rules[$key]);
continue;
}
foreach ($cart_cart_rules as $cart_cart_rule) {
if ($available_cart_rule['id_cart_rule'] == $cart_cart_rule['id_cart_rule']) {
unset($available_cart_rules[$key]);
continue 2;
}
}
}
$show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE');
$this->context->smarty->assign($summary);
$this->context->smarty->assign(array('token_cart' => Tools::getToken(false), 'isLogged' => $this->isLogged, 'isVirtualCart' => $this->context->cart->isVirtualCart(), 'productNumber' => $this->context->cart->nbProducts(), 'voucherAllowed' => CartRule::isFeatureActive(), 'shippingCost' => $this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => $this->context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'lastProductAdded' => $this->context->cart->getLastProduct(), 'displayVouchers' => $available_cart_rules, 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'show_option_allow_separate_package' => $show_option_allow_separate_package, 'smallSize' => Image::getSize(ImageType::getFormatedName('small'))));
$this->context->smarty->assign(array('HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)));
}
示例9: processChangeProductInCart
/**
* This process add or update a product in the cart
*/
protected function processChangeProductInCart()
{
$mode = Tools::getIsset('update') && $this->id_product ? 'update' : 'add';
if ($this->qty == 0) {
$this->errors[] = Tools::displayError('Null quantity.', !Tools::getValue('ajax'));
} elseif (!$this->id_product) {
$this->errors[] = Tools::displayError('Product not found', !Tools::getValue('ajax'));
}
$product = new Product($this->id_product, true, $this->context->language->id);
if (!$product->id || !$product->active || !$product->checkAccess($this->context->cart->id_customer)) {
$this->errors[] = Tools::displayError('This product is no longer available.', !Tools::getValue('ajax'));
return;
}
$qty_to_check = $this->qty;
$cart_products = $this->context->cart->getProducts();
if (is_array($cart_products)) {
foreach ($cart_products as $cart_product) {
if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) && (isset($this->id_product) && $cart_product['id_product'] == $this->id_product)) {
$qty_to_check = $cart_product['cart_quantity'];
if (Tools::getValue('op', 'up') == 'down') {
$qty_to_check -= $this->qty;
} else {
$qty_to_check += $this->qty;
}
break;
}
}
}
// Check product quantity availability
if ($this->id_product_attribute) {
if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
$this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax'));
}
} elseif ($product->hasAttributes()) {
$minimumQuantity = $product->out_of_stock == 2 ? !Configuration::get('PS_ORDER_OUT_OF_STOCK') : !$product->out_of_stock;
$this->id_product_attribute = Product::getDefaultAttribute($product->id, $minimumQuantity);
// @todo do something better than a redirect admin !!
if (!$this->id_product_attribute) {
Tools::redirectAdmin($this->context->link->getProductLink($product));
} elseif (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
$this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax'));
}
} elseif (!$product->checkQty($qty_to_check)) {
$this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax'));
}
// If no errors, process product addition
if (!$this->errors && $mode == 'add') {
// Add cart if no cart found
if (!$this->context->cart->id) {
if (Context::getContext()->cookie->id_guest) {
$guest = new Guest(Context::getContext()->cookie->id_guest);
$this->context->cart->mobile_theme = $guest->mobile_theme;
}
$this->context->cart->add();
if ($this->context->cart->id) {
$this->context->cookie->id_cart = (int) $this->context->cart->id;
}
}
// Check customizable fields
if (!$product->hasAllRequiredCustomizableFields() && !$this->customization_id) {
$this->errors[] = Tools::displayError('Please fill in all of the required fields, and then save your customizations.', !Tools::getValue('ajax'));
}
if (!$this->errors) {
$cart_rules = $this->context->cart->getCartRules();
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart, false, true);
$update_quantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, Tools::getValue('op', 'up'), $this->id_address_delivery);
if ($update_quantity < 0) {
// If product has attribute, minimal quantity is set with minimal quantity of attribute
$minimal_quantity = $this->id_product_attribute ? Attribute::getAttributeMinimalQty($this->id_product_attribute) : $product->minimal_quantity;
$this->errors[] = sprintf(Tools::displayError('You must add %d minimum quantity', !Tools::getValue('ajax')), $minimal_quantity);
} elseif (!$update_quantity) {
$this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.', !Tools::getValue('ajax'));
} elseif ((int) Tools::getValue('allow_refresh')) {
// If the cart rules has changed, we need to refresh the whole cart
$cart_rules2 = $this->context->cart->getCartRules();
if (count($cart_rules2) != count($cart_rules)) {
$this->ajax_refresh = true;
} elseif (count($cart_rules2)) {
$rule_list = array();
foreach ($cart_rules2 as $rule) {
$rule_list[] = $rule['id_cart_rule'];
}
foreach ($cart_rules as $rule) {
if (!in_array($rule['id_cart_rule'], $rule_list)) {
$this->ajax_refresh = true;
break;
}
}
} else {
$available_cart_rules2 = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart, false, true);
if (count($available_cart_rules2) != count($available_cart_rules)) {
$this->ajax_refresh = true;
} elseif (count($available_cart_rules2)) {
$rule_list = array();
foreach ($available_cart_rules2 as $rule) {
$rule_list[] = $rule['id_cart_rule'];
}
//.........这里部分代码省略.........
示例10: renderView
//.........这里部分代码省略.........
$sql = 'SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = %d AND valid = 1';
if ($total_customer = Db::getInstance()->getValue(sprintf($sql, $customer->id))) {
$sql = 'SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 AND id_customer != ' . (int) $customer->id . ' GROUP BY id_customer HAVING SUM(total_paid_real) > %d';
Db::getInstance()->getValue(sprintf($sql, (int) $total_customer));
$count_better_customers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1;
} else {
$count_better_customers = '-';
}
$orders = Order::getCustomerOrders($customer->id, true);
$total_orders = count($orders);
for ($i = 0; $i < $total_orders; $i++) {
$orders[$i]['total_paid_real_not_formated'] = $orders[$i]['total_paid_real'];
$orders[$i]['total_paid_real'] = Tools::displayPrice($orders[$i]['total_paid_real'], new Currency((int) $orders[$i]['id_currency']));
}
$messages = CustomerThread::getCustomerMessages((int) $customer->id);
$total_messages = count($messages);
for ($i = 0; $i < $total_messages; $i++) {
$messages[$i]['message'] = substr(strip_tags(html_entity_decode($messages[$i]['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75);
$messages[$i]['date_add'] = Tools::displayDate($messages[$i]['date_add'], null, true);
if (isset(self::$meaning_status[$messages[$i]['status']])) {
$messages[$i]['status'] = self::$meaning_status[$messages[$i]['status']];
}
}
$groups = $customer->getGroups();
$total_groups = count($groups);
for ($i = 0; $i < $total_groups; $i++) {
$group = new Group($groups[$i]);
$groups[$i] = array();
$groups[$i]['id_group'] = $group->id;
$groups[$i]['name'] = $group->name[$this->default_form_language];
}
$total_ok = 0;
$orders_ok = array();
$orders_ko = array();
foreach ($orders as $order) {
if (!isset($order['order_state'])) {
$order['order_state'] = $this->l('There is no status defined for this order.');
}
if ($order['valid']) {
$orders_ok[] = $order;
$total_ok += $order['total_paid_real_not_formated'];
} else {
$orders_ko[] = $order;
}
}
$products = $customer->getBoughtProducts();
$carts = Cart::getCustomerCarts($customer->id);
$total_carts = count($carts);
for ($i = 0; $i < $total_carts; $i++) {
$cart = new Cart((int) $carts[$i]['id_cart']);
$this->context->cart = $cart;
$summary = $cart->getSummaryDetails();
$currency = new Currency((int) $carts[$i]['id_currency']);
$carrier = new Carrier((int) $carts[$i]['id_carrier']);
$carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']);
$carts[$i]['date_add'] = Tools::displayDate($carts[$i]['date_add'], null, true);
$carts[$i]['total_price'] = Tools::displayPrice($summary['total_price'], $currency);
$carts[$i]['name'] = $carrier->name;
}
$sql = 'SELECT DISTINCT cp.id_product, c.id_cart, c.id_shop, cp.id_shop AS cp_id_shop
FROM ' . _DB_PREFIX_ . 'cart_product cp
JOIN ' . _DB_PREFIX_ . 'cart c ON (c.id_cart = cp.id_cart)
JOIN ' . _DB_PREFIX_ . 'product p ON (cp.id_product = p.id_product)
WHERE c.id_customer = ' . (int) $customer->id . '
AND NOT EXISTS (
SELECT 1
FROM ' . _DB_PREFIX_ . 'orders o
JOIN ' . _DB_PREFIX_ . 'order_detail od ON (o.id_order = od.id_order)
WHERE product_id = cp.id_product AND o.valid = 1 AND o.id_customer = ' . (int) $customer->id . '
)';
$interested = Db::getInstance()->executeS($sql);
$total_interested = count($interested);
for ($i = 0; $i < $total_interested; $i++) {
$product = new Product($interested[$i]['id_product'], false, $this->default_form_language, $interested[$i]['id_shop']);
if (!Validate::isLoadedObject($product)) {
continue;
}
$interested[$i]['url'] = $this->context->link->getProductLink($product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, $this->default_form_language), null, null, $interested[$i]['cp_id_shop']);
$interested[$i]['id'] = (int) $product->id;
$interested[$i]['name'] = Tools::htmlentitiesUTF8($product->name);
}
$emails = $customer->getLastEmails();
$connections = $customer->getLastConnections();
if (!is_array($connections)) {
$connections = array();
}
$total_connections = count($connections);
for ($i = 0; $i < $total_connections; $i++) {
$connections[$i]['http_referer'] = $connections[$i]['http_referer'] ? preg_replace('/^www./', '', parse_url($connections[$i]['http_referer'], PHP_URL_HOST)) : $this->l('Direct link');
}
$referrers = Referrer::getReferrers($customer->id);
$total_referrers = count($referrers);
for ($i = 0; $i < $total_referrers; $i++) {
$referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], null, true);
}
$customerLanguage = new Language($customer->id_lang);
$shop = new Shop($customer->id_shop);
$this->tpl_view_vars = array('customer' => $customer, 'gender' => $gender, 'gender_image' => $gender_image, 'registration_date' => Tools::displayDate($customer->date_add, null, true), 'customer_stats' => $customer_stats, 'last_visit' => Tools::displayDate($customer_stats['last_visit'], null, true), 'count_better_customers' => $count_better_customers, 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday), 'last_update' => Tools::displayDate($customer->date_upd, null, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => $customer->id_lang, 'customerLanguage' => $customerLanguage, 'customer_note' => Tools::htmlentitiesUTF8($customer->note), 'messages' => $messages, 'groups' => $groups, 'orders' => $orders, 'orders_ok' => $orders_ok, 'orders_ko' => $orders_ko, 'total_ok' => Tools::displayPrice($total_ok, $this->context->currency->id), 'products' => $products, 'addresses' => $customer->getAddresses($this->default_form_language), 'discounts' => CartRule::getCustomerCartRules($this->default_form_language, $customer->id, false, false), 'carts' => $carts, 'interested' => $interested, 'emails' => $emails, 'connections' => $connections, 'referrers' => $referrers, 'show_toolbar' => true);
return parent::renderView();
}
示例11: getCustomerDiscounts
/**
* @deprecated 1.5.0.1
*/
public static function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $hasStock = false, Cart $cart = null)
{
return parent::getCustomerCartRules($id_lang, $id_customer, $active, $includeGenericOnes, $hasStock, $cart);
}
示例12: hookActionCartSave
public function hookActionCartSave()
{
if (empty($this->context->cookie->discount_message_price)) {
$this->context->cookie->discount_message_price = 0;
$this->context->cookie->discount_message_display = 0;
}
$cart_price = $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
if ($cart_price != $this->context->cookie->discount_message_price) {
$this->context->cookie->discount_message_price = $cart_price;
$discount_message_percent = Configuration::get('PS_BLOCK_CART_DISCOUNT_MESSAGE_PERCENT');
if ($discount_message_percent > 0) {
$discounts = CartRule::getCustomerCartRules($this->context->language->id, $this->context->cutomer->id, true);
$current_discount = 0;
$next_discount = 0;
foreach ($discounts as $discount) {
if ($discount['reduction_percent'] > 0 && $discount['carrier_restriction'] == 0 && $discount['quantity_per-user'] >= 0 && $discount['minimum_amount'] <= $cart_price) {
$current_discount += $discount['reduction_percent'];
}
}
$minimal = 0;
foreach ($discounts as $discount) {
if ($discount['reduction_percent'] > 0 && $discount['carrier_restriction'] == 0 && $discount['quantity_per-user'] >= 0 && $discount['minimum_amount'] > $cart_price && (!$minimal || $discount['minimum_amount'] < $minimal)) {
$minimal = $discount['minimum_amount'];
$next_discount = $discount['reduction_percent'];
}
}
if ($cart_price * 100 / $minimal >= $discount_message_percent) {
$this->context->cookie->discount_message_display = 1;
$this->context->cookie->discount_message_price_display = $minimal - $cart_price;
$this->context->cookie->discount_message_percent_display = $next_discount + $current_discount;
}
}
}
}