Files
drmaterac.pl/modules/ets_promotion/classes/ets_pr_action_rule.php
2025-01-06 20:47:25 +01:00

2811 lines
118 KiB
PHP

<?php
/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
if (!defined('_PS_VERSION_'))
exit;
class Ets_pr_action_rule extends Ets_pr_obj
{
public static $instance;
public $id_ets_pr_rule;
public $type_action;
public $apply_free_shipping;
public $discount_on_shipping_cost;
public $amount_discount_on_shipping_cost;
public $percent_discount_on_shipping_cost;
public $maximum_discount_on_shipping_cost;
public $carrier_apply_discount_on_shipping_cost;
public $discount_on_total_cart;
public $percent_total_cart;
public $amount_total_cart;
public $maximum_discount_value;
public $exclude_tax_before_cal_discount;
public $exclude_shipping_fee_before_cal_disount;
public $discount_on_product;
public $discount_type;
public $amount_discount_product;
public $percent_discount_proudct;
public $maximum_discount_product;
public $apply_for_discounted_product;
public $applicable_product_categories;
public $include_specific_products;
public $exclude_products;
public $apply_all_attribute;
public $select_attributes;
public $apply_all_features;
public $select_features;
public $apply_all_supplier;
public $select_suppliers;
public $apply_all_manufacturer;
public $select_manufacturers;
public $apply_for_product_price_cal;
public $apply_for_product_price;
public $apply_for_availabled_quantity_stock_cal;
public $apply_for_availabled_quantity_stock;
public $purchase_quantity_more_of_same_product;
public $discount_on_all_quantities;
public $percent_discount_on_all_quantities;
public $amount_discount_on_all_quantities;
public $maximum_discount_on_all_quantities;
public $discount_all_quantities_action_on;
public $product_with_deffierent_attribute;
public $gift_or_with_discount_product;
public $gift_product;
public $quantity_gift_product;
public $apply_action_on;
public $gift_add_selected_product_to_cart;
public $new_product_with_discount_price;
public $percent_new_product_with_discount_price;
public $amount_new_product_with_discount_price;
public $maximum_new_product_with_discount_price;
public $purchase_more_product_quantity;
public $discount_purchase_more_product_quantity;
public $percent_discount_purchase_more_product_quantity;
public $amount_discount_purchase_more_product_quantity;
public $maximum_discount_purchase_more_product_quantity;
public $start_counting_purchase_more_product_quantity;
public $purchase_more_product_amount;
public $discount_purchase_more_product_amount;
public $percent_discount_purchase_more_product_amount;
public $amount_discount_purchase_more_product_amount;
public $maximum_discount_purchase_more_product_amount;
public $start_counting_purchase_more_product_amount;
public $purchase_discount_on_next_same_product;
public $discount_on_next_same_product;
public $percent_discount_on_next_same_product;
public $maximum_discount_on_next_same_product;
public $amount_discount_on_next_same_product;
public $amount_discount_on_next_same_product_tax_incl;
public $apply_on_next_same_product;
public $action_on_next_same_product;
public $repeat_the_action_on_next_same_product;
public $maximum_time_on_next_same_product;
public $is_free_shipping = false;
public $include_sub_categories;
public $applicable_categories;
public $apply_discount_code;
public $code;
public $highlight;
public $reduction_currency;
public $reduction_tax;
public $reduction_currency_discount_product;
public $reduction_tax_discount_product;
public $reduction_currency_discount_all_quantities;
public $reduction_tax_discount_all_quantities;
public $reduction_currency_discount_on_shipping_cost;
public $reduction_tax_discount_on_shipping_cost;
public $reduction_currency_discount_on_new_product;
public $reduction_tax_discount_on_new_product;
public $reduction_currency_discount_on_more_product_quantity;
public $reduction_tax_discount_on_more_product_quantity;
public $reduction_currency_discount_on_more_product_amount;
public $reduction_tax_discount_on_more_product_amount;
public $reduction_currency_discount_on_next_same_product;
public static $definition = array(
'table' => 'ets_pr_action_rule',
'primary' => 'id_ets_pr_action_rule',
'fields' => array(
'id_ets_pr_rule' => array('type' => self::TYPE_INT),
'type_action' => array('type' => self::TYPE_STRING),
'apply_free_shipping' => array('type' => self::TYPE_INT),
'discount_on_shipping_cost' => array('type' => self::TYPE_STRING),
'apply_discount_code' => array('type' => self::TYPE_STRING),
'code' => array('type' => self::TYPE_STRING),
'highlight' => array('type' => self::TYPE_INT),
'amount_discount_on_shipping_cost' => array('type' => self::TYPE_FLOAT),
'percent_discount_on_shipping_cost' => array('type' => self::TYPE_FLOAT),
'maximum_discount_on_shipping_cost' => array('type' => self::TYPE_FLOAT),
'carrier_apply_discount_on_shipping_cost' => array('type' => self::TYPE_STRING),
'discount_on_total_cart' => array('type' => self::TYPE_STRING),
'percent_total_cart' => array('type' => self::TYPE_FLOAT),
'amount_total_cart' => array('type' => self::TYPE_FLOAT),
'maximum_discount_value' => array('type' => self::TYPE_FLOAT),
'exclude_tax_before_cal_discount' => array('type' => self::TYPE_INT),
'exclude_shipping_fee_before_cal_disount' => array('type' => self::TYPE_INT),
'discount_on_product' => array('type' => self::TYPE_STRING),
'discount_type' => array('type' => self::TYPE_STRING),
'amount_discount_product' => array('type' => self::TYPE_FLOAT),
'percent_discount_proudct' => array('type' => self::TYPE_FLOAT),
'maximum_discount_product' => array('type' => self::TYPE_FLOAT),
'apply_for_discounted_product' => array('type' => self::TYPE_INT),
'applicable_product_categories' => array('type' => self::TYPE_STRING),
'include_specific_products' => array('type' => self::TYPE_STRING),
'exclude_products' => array('type' => self::TYPE_STRING),
'apply_all_attribute' => array('type' => self::TYPE_INT),
'select_attributes' => array('type' => self::TYPE_STRING),
'apply_all_features' => array('type' => self::TYPE_INT),
'select_features' => array('type' => self::TYPE_STRING),
'apply_all_supplier' => array('type' => self::TYPE_INT),
'select_suppliers' => array('type' => self::TYPE_STRING),
'apply_all_manufacturer' => array('type' => self::TYPE_INT),
'select_manufacturers' => array('type' => self::TYPE_STRING),
'apply_for_product_price_cal' => array('type' => self::TYPE_HTML),
'apply_for_product_price' => array('type' => self::TYPE_FLOAT),
'apply_for_availabled_quantity_stock_cal' => array('type' => self::TYPE_HTML),
'apply_for_availabled_quantity_stock' => array('type' => self::TYPE_INT),
'purchase_quantity_more_of_same_product' => array('type' => self::TYPE_INT),
'discount_on_all_quantities' => array('type' => self::TYPE_STRING),
'percent_discount_on_all_quantities' => array('type' => self::TYPE_FLOAT),
'amount_discount_on_all_quantities' => array('type' => self::TYPE_FLOAT),
'maximum_discount_on_all_quantities' => array('type' => self::TYPE_FLOAT),
'discount_all_quantities_action_on' => array('type' => self::TYPE_STRING),
'product_with_deffierent_attribute' => array('type' => self::TYPE_INT),
'gift_or_with_discount_product' => array('type' => self::TYPE_STRING),
'gift_product' => array('type' => self::TYPE_STRING),
'quantity_gift_product' => array('type' => self::TYPE_INT),
'apply_action_on' => array('type' => self::TYPE_STRING),
'gift_add_selected_product_to_cart' => array('type' => self::TYPE_STRING),
'new_product_with_discount_price' => array('type' => self::TYPE_STRING),
'percent_new_product_with_discount_price' => array('type' => self::TYPE_FLOAT),
'amount_new_product_with_discount_price' => array('type' => self::TYPE_FLOAT),
'maximum_new_product_with_discount_price' => array('type' => self::TYPE_FLOAT),
'purchase_more_product_quantity' => array('type' => self::TYPE_INT),
'discount_purchase_more_product_quantity' => array('type' => self::TYPE_STRING),
'percent_discount_purchase_more_product_quantity' => array('type' => self::TYPE_FLOAT),
'amount_discount_purchase_more_product_quantity' => array('type' => self::TYPE_FLOAT),
'maximum_discount_purchase_more_product_quantity' => array('type' => self::TYPE_FLOAT),
'start_counting_purchase_more_product_quantity' => array('type' => self::TYPE_STRING),
'purchase_more_product_amount' => array('type' => self::TYPE_FLOAT),
'discount_purchase_more_product_amount' => array('type' => self::TYPE_STRING),
'percent_discount_purchase_more_product_amount' => array('type' => self::TYPE_FLOAT),
'amount_discount_purchase_more_product_amount' => array('type' => self::TYPE_FLOAT),
'maximum_discount_purchase_more_product_amount' => array('type' => self::TYPE_FLOAT),
'start_counting_purchase_more_product_amount' => array('type' => self::TYPE_STRING),
'purchase_discount_on_next_same_product' => array('type' => self::TYPE_INT),
'discount_on_next_same_product' => array('type' => self::TYPE_STRING),
'percent_discount_on_next_same_product' => array('type' => self::TYPE_FLOAT),
'maximum_discount_on_next_same_product' => array('type' => self::TYPE_FLOAT),
'amount_discount_on_next_same_product' => array('type' => self::TYPE_FLOAT),
'amount_discount_on_next_same_product_tax_incl' => array('type' => self::TYPE_INT),
'apply_on_next_same_product' => array('type' => self::TYPE_INT),
'action_on_next_same_product' => array('type' => self::TYPE_STRING),
'repeat_the_action_on_next_same_product' => array('type' => self::TYPE_STRING),
'maximum_time_on_next_same_product' => array('type' => self::TYPE_INT),
'include_sub_categories' => array('type' => self::TYPE_INT),
'reduction_currency' => array('type' => self::TYPE_INT),
'reduction_tax' => array('type' => self::TYPE_INT),
'reduction_currency_discount_product' => array('type' => self::TYPE_INT),
'reduction_tax_discount_product' => array('type' => self::TYPE_INT),
'reduction_currency_discount_all_quantities' => array('type' => self::TYPE_INT),
'reduction_tax_discount_all_quantities' => array('type' => self::TYPE_INT),
'reduction_currency_discount_on_shipping_cost' => array('type' => self::TYPE_INT),
'reduction_tax_discount_on_shipping_cost' => array('type' => self::TYPE_INT),
'reduction_currency_discount_on_new_product' => array('type' => self::TYPE_INT),
'reduction_tax_discount_on_new_product' => array('type' => self::TYPE_INT),
'reduction_currency_discount_on_more_product_quantity' => array('type' => self::TYPE_INT),
'reduction_tax_discount_on_more_product_quantity' => array('type' => self::TYPE_INT),
'reduction_currency_discount_on_more_product_amount' => array('type' => self::TYPE_INT),
'reduction_tax_discount_on_more_product_amount' => array('type' => self::TYPE_INT),
'reduction_currency_discount_on_next_same_product' => array('type' => self::TYPE_INT),
'applicable_categories' => array('type' => self::TYPE_STRING),
)
);
public function __construct($id_item = null, $id_lang = null, $id_shop = null)
{
parent::__construct($id_item, $id_lang, $id_shop);
$id_currency_default = (int)Configuration::get('PS_CURRENCY_DEFAULT');
if (!$this->reduction_currency_discount_on_more_product_quantity)
{
$this->reduction_currency_discount_on_more_product_quantity = $id_currency_default;
}
if (!$this->reduction_currency_discount_on_more_product_amount)
$this->reduction_currency_discount_on_more_product_amount = $id_currency_default;
if (!$this->reduction_currency_discount_on_next_same_product)
$this->reduction_currency_discount_on_next_same_product = $id_currency_default;
if (!$this->reduction_currency)
$this->reduction_currency = $id_currency_default;
if (!$this->reduction_currency_discount_on_shipping_cost)
$this->reduction_currency_discount_on_shipping_cost = $id_currency_default;
if (!$this->reduction_currency_discount_on_new_product)
$this->reduction_currency_discount_on_new_product = $id_currency_default;
if (!$this->reduction_currency_discount_product)
$this->reduction_currency_discount_product = $id_currency_default;
if (!$this->reduction_currency_discount_all_quantities)
$this->reduction_currency_discount_all_quantities = $id_currency_default;
}
public static function getInstance()
{
if (!(isset(self::$instance)) || !self::$instance)
{
self::$instance = new Ets_pr_action_rule();
}
return self::$instance;
}
public function l($string, $file_name = '')
{
return Translate::getModuleTranslation('ets_promotion', $string, $file_name ?: pathinfo(__FILE__, PATHINFO_FILENAME));
}
public function getListFields()
{
$configs = array(
'id_ets_pr_rule' => array(
'type' => 'hidden',
'label' => '',
'default' => $this->id_ets_pr_rule,
),
'type_action' => array(
'type' => 'select',
'label' => $this->l('Action'),
'options' => array(
'optiongroup' => array(
'query' => array(
array(
'label' => $this->l('General actions'),
'options' => array(
array(
'label' => $this->l('Shipping cost discount'),
'value' => 'action_on_shipping'
),
array(
'label' => $this->l('Order amount discount'),
'value' => 'order_amount'
),
array(
'label' => $this->l('Product discount'),
'value' => 'action_on_product',
),
)
),
array(
'label' => $this->l('Advanced actions'),
'options' => array(
array(
'label' => $this->l('Buy more than X units - Get discount on all units'),
'value' => 'discount_on_all_quantities'
),
array(
'label' => $this->l('Buy X units - Get discount on next units of the same product'),
'value' => 'purchase_discount_on_next_same_product'
),
array(
'label' => $this->l('Buy product X - Get product Y for free (or discount)'),
'value' => 'gift_or_with_discount_product'
),
array(
'label' => $this->l('Buy more than X units - Get discount on next all units'),
'value' => 'purchase_more_product_quantity'
),
array(
'label' => $this->l('Buy more than $X in selected product type - Get discount on all next products'),
'value' => 'purchase_more_product_amount',
),
)
)
),
'label' => 'label',
),
'options' => array(
'query' => 'options',
'id' => 'value',
'name' => 'label'
),
'default' => array(
'value' => '',
'label' => $this->l('-- Select an action --'),
),
),
'required' => true,
),
'apply_free_shipping' => array(
'type' => 'switch',
'label' => $this->l('Apply free shipping'),
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'apply_free_shipping_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'apply_free_shipping_off',
'value' => 0,
)
),
'form_group_class' => 'type_action action_on_shipping',
'validate' => 'isUnsignedId',
),
'discount_on_shipping_cost' => array(
'type' => 'radio',
'label' => $this->l('Give discount on shipping cost'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_on_shipping_cost_percent',
'value' => 'percent',
'label' => $this->l('Percentage'),
),
array(
'id' => 'discount_on_shipping_cost_amount',
'value' => 'amount',
'label' => $this->l('Amount'),
),
),
'form_group_class' => 'type_action action_on_shipping',
'validate' => 'isCleanHtml',
),
'percent_discount_on_shipping_cost' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action action_on_shipping',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'maximum_discount_on_shipping_cost' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action action_on_shipping',
'validate' => 'isUnsignedFloat',
),
'amount_discount_on_shipping_cost' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'form_group_class' => 'type_action action_on_shipping',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency_discount_on_shipping_cost' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction currency'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax_discount_on_shipping_cost' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction tax'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'carrier_apply_discount_on_shipping_cost' => array(
'type' => 'checkbox',
'values' => array(
'query' => $this->getCarriers(),
'id' => 'id_reference',
'name' => 'name'
),
'label' => $this->l('Apply to carriers'),
'form_group_class' => 'type_action action_on_shipping',
'default' => array('all'),
'validate' => 'isCleanHtml',
'showRequired' => true,
),
'discount_on_total_cart' => array(
'type' => 'radio',
'label' => $this->l('Give discount on total cart value'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_on_total_cart_percent',
'value' => 'percent',
'label' => $this->l('Percentage'),
),
array(
'id' => 'discount_on_total_cart_amount',
'value' => 'amount',
'label' => $this->l('Amount'),
),
),
'form_group_class' => 'type_action order_amount',
'validate' => 'isCleanHtml',
),
'percent_total_cart' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action order_amount',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'maximum_discount_value' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action order_amount',
'validate' => 'isUnsignedFloat',
),
'amount_total_cart' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
//'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action order_amount',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction currency'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction tax'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'exclude_tax_before_cal_discount' => array(
'type' => 'switch',
'label' => $this->l('Exclude tax before calculating discount'),
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'exclude_tax_before_cal_discount_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'exclude_tax_before_cal_discount_off',
'value' => 0,
)
),
'form_group_class' => 'type_action order_amount',
'validate' => 'isUnsignedId',
'default' => 1,
),
'exclude_shipping_fee_before_cal_disount' => array(
'type' => 'switch',
'label' => $this->l('Exclude shipping fee before calculating discount'),
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'exclude_shipping_fee_before_cal_disount_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'exclude_shipping_fee_before_cal_disount_off',
'value' => 0,
)
),
'form_group_class' => 'type_action order_amount',
'validate' => 'isUnsignedId',
'default' => 1,
),
'discount_on_product' => array(
'type' => 'radio',
'label' => $this->l('Give discount on product'),
'default' => 'cheapest_product',
'values' => array(
array(
'id' => 'discount_on_product_cheapest_product',
'value' => 'cheapest_product',
'label' => $this->l('Cheapest product in shopping cart'),
),
array(
'id' => 'discount_on_product_most_expensive_product',
'value' => 'most_expensive_product',
'label' => $this->l('Most expensive product in shopping cart'),
),
array(
'id' => 'discount_on_product_least_quantity',
'value' => 'least_quantity',
'label' => $this->l('Product with the least quantity in shopping cart'),
),
array(
'id' => 'discount_on_product_most_quantity',
'value' => 'most_quantity',
'label' => $this->l('Product with the most quantity in shopping cart'),
),
),
'form_group_class' => 'type_action action_on_product',
'validate' => 'isCleanHtml',
),
'discount_type' => array(
'type' => 'radio',
'label' => $this->l('Discount'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_type_percent',
'value' => 'percent',
'label' => $this->l('Percentage'),
),
array(
'id' => 'discount_type_amount',
'value' => 'amount',
'label' => $this->l('Amount'),
),
),
'form_group_class' => 'type_action action_on_product',
'validate' => 'isCleanHtml',
),
'amount_discount_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'form_group_class' => 'type_action action_on_product',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency_discount_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Currency'),
'form_group_class' => 'type_action action_on_product',
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax_discount_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Tax'),
'form_group_class' => 'type_action action_on_product',
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'percent_discount_proudct' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action action_on_product',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'maximum_discount_product' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action action_on_product',
'validate' => 'isUnsignedFloat',
),
'purchase_quantity_more_of_same_product' => array(
'type' => 'text',
'label' => $this->l('Purchase'),
'suffix' => $this->l('units or more of the same product'),
'form_group_class' => 'type_action discount_on_all_quantities',
'validate' => 'isUnsignedInt',
'showRequired' => true,
'col' => 4,
),
'discount_on_all_quantities' => array(
'type' => 'radio',
'label' => $this->l('Get discount on all units'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_on_all_quantities_percent',
'value' => 'percent',
'label' => $this->l('Percentage'),
),
array(
'id' => 'discount_on_all_quantities_amount',
'value' => 'amount',
'label' => $this->l('Amount'),
),
),
'form_group_class' => 'type_action discount_on_all_quantities',
'validate' => 'isCleanHtml',
),
'amount_discount_on_all_quantities' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'form_group_class' => 'type_action discount_on_all_quantities',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency_discount_all_quantities' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction currency'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax_discount_all_quantities' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction tax'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'percent_discount_on_all_quantities' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action discount_on_all_quantities',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'maximum_discount_on_all_quantities' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action discount_on_all_quantities',
'validate' => 'isUnsignedFloat',
),
'discount_all_quantities_action_on' => array(
'type' => 'radio',
'label' => $this->l('Apply discount on'),
'default' => 'all',
'values' => array(
array(
'id' => 'discount_all_quantities_action_on_all',
'value' => 'all',
'label' => $this->l('All products in shopping cart'),
),
array(
'id' => 'discount_all_quantities_action_on_cheapest_product',
'value' => 'cheapest_product',
'label' => $this->l('Cheapest product in shopping cart'),
),
array(
'id' => 'discount_all_quantities_action_on_most_expensive_product',
'value' => 'most_expensive_product',
'label' => $this->l('Most expensive product in shopping cart'),
),
array(
'id' => 'discount_all_quantities_action_on_least_quantity',
'value' => 'least_quantity',
'label' => $this->l('Product with the least quantity in shopping cart'),
),
array(
'id' => 'discount_all_quantities_action_on_most_quantity',
'value' => 'most_quantity',
'label' => $this->l('Product with the most quantity in shopping cart'),
),
),
'form_group_class' => 'type_action discount_on_all_quantities',
'validate' => 'isCleanHtml',
),
'purchase_more_product_quantity' => array(
'type' => 'text',
'label' => $this->l('Buy'),
'suffix' => $this->l('units of products'),
'form_group_class' => 'type_action purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
'showRequired' => true,
'col' => 4,
),
'discount_purchase_more_product_quantity' => array(
'type' => 'radio',
'label' => $this->l('Get'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_purchase_more_product_quantity_percent',
'value' => 'percent',
'label' => $this->l('Discount percentage on next products'),
),
array(
'id' => 'discount_purchase_more_product_quantity_amount',
'value' => 'amount',
'label' => $this->l('Discount amount on next products'),
),
),
'form_group_class' => 'type_action purchase_more_product_quantity',
'validate' => 'isCleanHtml',
),
'amount_discount_purchase_more_product_quantity' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Discount value'),
'form_group_class' => 'type_action purchase_more_product_quantity',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency_discount_on_more_product_quantity' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction currency'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax_discount_on_more_product_quantity' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction tax'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'percent_discount_purchase_more_product_quantity' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action purchase_more_product_quantity',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'maximum_discount_purchase_more_product_quantity' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action purchase_more_product_quantity',
'validate' => 'isUnsignedFloat',
),
'start_counting_purchase_more_product_quantity' => array(
'type' => 'radio',
'label' => $this->l('Start counting quantity from'),
'default' => 'cheapest_product',
'values' => array(
array(
'id' => 'start_counting_purchase_more_product_quantity_cheapest_product',
'value' => 'cheapest_product',
'label' => $this->l('Cheapest product in shopping cart'),
),
array(
'id' => 'start_counting_purchase_more_product_quantity_most_expensive_product',
'value' => 'most_expensive_product',
'label' => $this->l('Most expensive product in shopping cart'),
),
array(
'id' => 'start_counting_purchase_more_product_quantity_least_quantity',
'value' => 'least_quantity',
'label' => $this->l('Product with the least quantity in shopping cart'),
),
array(
'id' => 'start_counting_purchase_more_product_quantity_most_quantity',
'value' => 'most_quantity',
'label' => $this->l('Product with the most quantity in shopping cart'),
),
),
'form_group_class' => 'type_action purchase_more_product_quantity',
'validate' => 'isCleanHtml',
),
'purchase_more_product_amount' => array(
'type' => 'text',
'label' => $this->l('Buy'),
'suffix' => sprintf($this->l('Amount (%s) of products'), Context::getContext()->currency->sign),
'form_group_class' => 'type_action purchase_more_product_amount',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
'col' => 4,
),
'discount_purchase_more_product_amount' => array(
'type' => 'radio',
'label' => $this->l('Get'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_purchase_more_product_amount_percent',
'value' => 'percent',
'label' => $this->l('Discount percentage on next products'),
),
array(
'id' => 'discount_purchase_more_product_amount_amount',
'value' => 'amount',
'label' => $this->l('Discount amount on next products'),
),
),
'form_group_class' => 'type_action purchase_more_product_amount',
'validate' => 'isCleanHtml',
),
'amount_discount_purchase_more_product_amount' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'form_group_class' => 'type_action purchase_more_product_amount',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency_discount_on_more_product_amount' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction currency'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax_discount_on_more_product_amount' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction tax'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'percent_discount_purchase_more_product_amount' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action purchase_more_product_amount',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'maximum_discount_purchase_more_product_amount' => array(
'type' => 'text',
'col' => 2,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action purchase_more_product_amount',
'validate' => 'isUnsignedFloat',
),
'start_counting_purchase_more_product_amount' => array(
'type' => 'radio',
'label' => $this->l('Start counting amount from'),
'default' => 'cheapest_product',
'values' => array(
array(
'id' => 'start_counting_purchase_more_product_amount_cheapest_product',
'value' => 'cheapest_product',
'label' => $this->l('Cheapest product in shopping cart'),
),
array(
'id' => 'start_counting_purchase_more_product_amount_most_expensive_product',
'value' => 'most_expensive_product',
'label' => $this->l('Most expensive product in shopping cart'),
),
array(
'id' => 'start_counting_purchase_more_product_amount_least_quantity',
'value' => 'least_quantity',
'label' => $this->l('Product with the least quantity in shopping cart'),
),
array(
'id' => 'start_counting_purchase_more_product_amount_most_quantity',
'value' => 'most_quantity',
'label' => $this->l('Product with the most quantity in shopping cart'),
),
),
'form_group_class' => 'type_action purchase_more_product_amount',
'validate' => 'isCleanHtml',
),
'purchase_discount_on_next_same_product' => array(
'type' => 'text',
'label' => $this->l('Buy'),
'suffix' => $this->l('units of the same product'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedInt',
'showRequired' => true,
'col' => 4,
),
'discount_on_next_same_product' => array(
'type' => 'radio',
'label' => $this->l('Give discount on shopping cart'),
'default' => 'percent',
'values' => array(
array(
'id' => 'discount_on_next_same_product_free',
'value' => 'free',
'label' => $this->l('Free on the next unit of the same product'),
),
array(
'id' => 'discount_on_next_same_product_percent',
'value' => 'percent',
'label' => $this->l('Give discount percentage on the next unit of the same product'),
),
array(
'id' => 'discount_on_next_same_product_amount',
'value' => 'amount',
'label' => $this->l('Give discount amount on the next unit of the same product'),
),
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isCleanHtml',
),
'percent_discount_on_next_same_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'amount_discount_on_next_same_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedFloat',
'showRequired' => true,
),
'reduction_currency_discount_on_next_same_product' => array(
'type' => 'text',
'label' => $this->l('Reduction currency'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedInt',
),
'amount_discount_on_next_same_product_tax_incl' => array(
'type' => 'text',
'label' => $this->l('Reduction tax'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedInt',
),
'maximum_discount_on_next_same_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedFloat',
),
'apply_on_next_same_product' => array(
'type' => 'text',
'label' => $this->l('Apply on next'),
'suffix' => $this->l('units of the same product'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedInt',
'col' => 4,
'desc' => $this->l('Leave blank to apply on all next units of the same product'),
),
'apply_for_discounted_product' => array(
'type' => 'switch',
'label' => $this->l('Apply for discounted products'),
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'apply_for_discounted_product_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'apply_for_discounted_product_off',
'value' => 0,
)
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedId',
'default' => 1,
),
'action_on_next_same_product' => array(
'type' => 'radio',
'label' => $this->l('Apply action on'),
'default' => 'all',
'values' => array(
array(
'id' => 'action_on_next_same_product_all',
'value' => 'all',
'label' => $this->l('All products in shopping cart'),
),
array(
'id' => 'action_on_next_same_product_cheapest_product',
'value' => 'cheapest_product',
'label' => $this->l('Cheapest product in shopping cart'),
),
array(
'id' => 'action_on_next_same_product_most_expensive_product',
'value' => 'most_expensive_product',
'label' => $this->l('Most expensive product in shopping cart'),
),
array(
'id' => 'action_on_next_same_product_least_quantity',
'value' => 'least_quantity',
'label' => $this->l('Product with the least quantity in shopping cart'),
),
array(
'id' => 'discount_all_quantities_action_on_most_quantity',
'value' => 'most_quantity',
'label' => $this->l('Product with the most quantity in shopping cart'),
),
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isCleanHtml',
),
'repeat_the_action_on_next_same_product' => array(
'type' => 'radio',
'label' => $this->l('Repeat the action'),
'default' => 'once_on_1_product',
'values' => array(
array(
'id' => 'repeat_the_action_on_next_same_product_once_on_1_product',
'value' => 'once_on_1_product',
'label' => $this->l('Once per 1 product'),
),
array(
'id' => 'repeat_the_action_on_next_same_product_many_time_on_1_product',
'value' => 'many_time_on_1_product',
'label' => $this->l('Multiple times per 1 product'),
),
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isCleanHtml',
),
'maximum_time_on_next_same_product' => array(
'type' => 'text',
'label' => $this->l('Maximum execute times'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product',
'validate' => 'isUnsignedInt',
'showRequired' => true,
'col' => 3,
),
'product_with_deffierent_attribute' => array(
'type' => 'switch',
'label' => $this->l('Products with different attributes are counted as different products'),
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'product_with_deffierent_attribute_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'product_with_deffierent_attribute_off',
'value' => 0,
)
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product action_on_product discount_on_all_quantities',
'validate' => 'isUnsignedInt',
'default' => 1,
),
// advanced setting
'applicable_product_categories' => array(
'type' => 'radio',
'label' => $this->l('Applicable product categories'),
'default' => 'all_product',
'values' => array(
array(
'id' => 'applicable_product_categories_all_product',
'value' => 'all_product',
'label' => $this->l('All product categories'),
),
array(
'id' => 'applicable_product_categories_specific_product',
'value' => 'specific_product',
'label' => $this->l('Specific product categories'),
),
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
),
'applicable_categories' => array(
'label' => $this->l('Select categories to apply condition'),
'type' => 'categories',
'tree' => array(
'id' => 'loyalty-categories-tree',
'selected_categories' => $this->applicable_categories ? explode(',', $this->applicable_categories) : array(),
'disabled_categories' => null,
'use_checkbox' => true,
'root_category' => Category::getRootCategory()->id
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
),
'include_sub_categories' => array(
'type' => 'switch',
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'include_sub_categories_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'include_sub_categories_off',
'value' => 0,
)
),
'label' => $this->l('Include products in subcategories'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
),
'include_specific_products' => array(
'type' => 'search_product',
'label' => $this->l('Include specific products'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
'placeholder' => $this->l('Search by product name, reference, id')
),
'exclude_products' => array(
'type' => 'search_product',
'label' => $this->l('Exclude products'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
'placeholder' => $this->l('Search by product name, reference, id')
),
'apply_all_attribute' => array(
'type' => 'switch',
'default' => 1,
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'apply_all_attribute_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'apply_all_attribute_off',
'value' => 0,
)
),
'label' => $this->l('Apply to all attributes'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
),
'select_attributes' => array(
'type' => 'checkbox',
'label' => $this->l('Select attributes'),
'values' => array(
'query' => $this->getAttributes(),
'id' => 'id_attribute',
'name' => 'name'
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
'showRequired' => true,
),
'apply_all_features' => array(
'type' => 'switch',
'default' => 1,
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'apply_all_features_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'apply_all_features_off',
'value' => 0,
)
),
'label' => $this->l('Apply to all features'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
),
'select_features' => array(
'type' => 'checkbox',
'label' => $this->l('Select features'),
'values' => array(
'query' => $this->getFeatures(),
'id' => 'id_feature',
'name' => 'name'
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
'showRequired' => true,
),
'apply_all_supplier' => array(
'type' => 'switch',
'default' => 1,
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'apply_all_supplier_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'apply_all_supplier_off',
'value' => 0,
)
),
'label' => $this->l('Apply to all suppliers'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
),
'select_suppliers' => array(
'type' => 'checkbox',
'label' => $this->l('Select suppliers'),
'values' => array(
'query' => $this->getSuppliers(),
'id' => 'id_supplier',
'name' => 'name'
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
'showRequired' => true,
),
'apply_all_manufacturer' => array(
'type' => 'switch',
'default' => 1,
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'apply_all_manufacturer_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'apply_all_manufacturer_off',
'value' => 0,
)
),
'label' => $this->l('Apply to all manufacturers'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
),
'select_manufacturers' => array(
'type' => 'checkbox',
'label' => $this->l('Select manufacturers'),
'values' => array(
'query' => $this->getManufacturers(),
'id' => 'id_manufacturer',
'name' => 'name'
),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
'showRequired' => true,
),
'apply_for_product_price_cal' => array(
'type' => 'select',
'label' => $this->l('Apply for product price calculator'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
),
'apply_for_product_price' => array(
'type' => 'text',
'label' => $this->l('Apply for product price'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'suffix' => Context::getContext()->currency->sign,
'validate' => 'isPrice',
),
'apply_for_availabled_quantity_stock_cal' => array(
'type' => 'select',
'label' => $this->l('Apply for available stock quantity calculator'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isCleanHtml',
),
'apply_for_availabled_quantity_stock' => array(
'type' => 'text',
'label' => $this->l('Apply for available stock quantity'),
'form_group_class' => 'type_action purchase_discount_on_next_same_product purchase_more_product_amount action_on_product discount_on_all_quantities purchase_more_product_quantity',
'validate' => 'isUnsignedInt',
),
// end advance setting;
'gift_or_with_discount_product' => array(
'type' => 'radio',
'label' => $this->l('Get'),
'default' => 'gift_product',
'values' => array(
array(
'id' => 'gift_or_with_discount_product_gift_product',
'value' => 'gift_product',
'label' => $this->l('New product as a gift (Free)'),
),
array(
'id' => 'gift_or_with_discount_product_new_product',
'value' => 'new_product',
'label' => $this->l('New product with discount price'),
),
),
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isCleanHtml',
),
'new_product_with_discount_price' => array(
'type' => 'radio',
'label' => $this->l('Discount type'),
'default' => 'percent',
'tab' => 'new_product',
'values' => array(
array(
'id' => 'new_product_with_discount_price_percent',
'value' => 'percent',
'label' => $this->l('Percentage'),
),
array(
'id' => 'new_product_with_discount_price_amount',
'value' => 'amount',
'label' => $this->l('Amount'),
),
),
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isCleanHtml',
),
'percent_new_product_with_discount_price' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
'suffix' => '%',
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isUnsignedFloat',
'tab' => 'new_product',
'showRequired' => true,
),
'maximum_new_product_with_discount_price' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Maximum discount value'),
'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isUnsignedFloat',
'tab' => 'new_product',
),
'amount_new_product_with_discount_price' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Discount value'),
//'suffix' => Context::getContext()->currency->sign,
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isUnsignedFloat',
'tab' => 'new_product',
'showRequired' => true,
),
'reduction_currency_discount_on_new_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction currency'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'reduction_tax_discount_on_new_product' => array(
'type' => 'text',
'col' => 3,
'label' => $this->l('Reduction tax'),
'validate' => 'isUnsignedInt',
'no_display' => true,
),
'gift_product' => array(
'type' => 'search_product',
'label' => $this->l('Select product(s) to giveaway as free gift'),
'tab' => 'gift_product new_product',
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isCleanHtml',
'placeholder' => $this->l('Search by product name, reference, id'),
'showRequired' => true,
),
'quantity_gift_product' => array(
'type' => 'text',
'label' => $this->l('Product quantity'),
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isUnsignedInt',
'tab' => 'gift_product new_product',
'col' => 2,
'default' => 1,
'showRequired' => true,
),
'apply_action_on' => array(
'type' => 'radio',
'label' => $this->l('Apply action on'),
'default' => 'all',
'values' => array(
array(
'id' => 'apply_action_on_all',
'value' => 'all',
'label' => $this->l('All products in selected product(s) list will be given away as free gift'),
),
array(
'id' => 'apply_action_on_cheapest',
'value' => 'cheapest',
'label' => $this->l('The cheapest product in selected product(s) list will be given away as free gift'),
),
array(
'id' => 'apply_action_on_most_expensive',
'value' => 'most_expensive',
'label' => $this->l('The most expensive product in selected product(s) list will be given away as free gift'),
),
),
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isCleanHtml',
'tab' => 'gift_product new_product',
),
'gift_add_selected_product_to_cart' => array(
'type' => 'radio',
'label' => $this->l('Add selected product to cart'),
'default' => 'auto',
'values' => array(
array(
'id' => 'gift_add_selected_product_to_cart_auto',
'value' => 'auto',
'label' => $this->l('Automatically'),
),
array(
'id' => 'gift_add_selected_product_to_cart_let_customer_chonse',
'value' => 'let_customer_chonse',
'label' => $this->l('Let customer choose'),
),
),
'form_group_class' => 'type_action gift_or_with_discount_product',
'validate' => 'isCleanHtml',
'tab' => 'gift_product new_product',
),
'apply_discount_code' => array(
'type' => 'radio',
'label' => $this->l('How to apply discount code'),
'default' => 'auto',
'values' => array(
array(
'id' => 'apply_discount_code_auto',
'value' => 'auto',
'label' => $this->l('Auto apply when shopping cart satisfies the discount condition'),
),
array(
'id' => 'apply_discount_code_code',
'value' => 'code',
'label' => $this->l(' Customer must enter a discount code'),
),
),
'validate' => 'isCleanHtml',
'form_group_class' => 'has_action',
),
'code' => array(
'type' => 'text',
'label' => $this->l('Discount code'),
'desc' => $this->l('This is the code users should enter to apply the voucher to a cart. Either create your own code or generate one by clicking on "Generate".'),
'tab' => 'apply_discount_code code',
'suffix' => $this->l('Generate'),
'col' => 3,
'validate' => 'isCleanHtml',
'showRequired' => true,
'form_group_class' => 'has_action',
),
'highlight' => array(
'type' => 'switch',
'label' => $this->l('Highlight'),
'desc' => $this->l('If the voucher is not yet in the cart, it will be displayed in the cart summary.'),
'values' => array(
array(
'label' => $this->l('Yes'),
'id' => 'highlight_on',
'value' => 1,
),
array(
'label' => $this->l('No'),
'id' => 'highlight_off',
'value' => 0,
)
),
'tab' => 'apply_discount_code code',
'form_group_class' => 'has_action',
),
);
return array(
'form' => array(
'legend' => array(
'title' => $this->id ? $this->l('Edit action rule') : $this->l('Add action for discount rule'),
),
'input' => array(),
'submit' => array(
'title' => $this->l('Save & next'),
),
'name' => 'action_rule',
'key' => 'id_ets_pr_action_rule',
'buttons' => array(
array(
'href' => Context::getContext()->link->getAdminLink('AdminModules') . '&configure=ets_promotion&editrule=1&id_ets_pr_rule=' . $this->id_ets_pr_rule . '&current_tab=condition',
'class' => 'pull-left',
'icon' => 'process-icon-back',
'title' => $this->l('Back'),
),
array(
'title' => $this->l('Save & stay'),
'type' => 'submit',
'class' => 'pull-right',
'name' => 'btnSubmitActionRuleStay',
'icon' => 'process-icon-save',
)
),
),
'configs' => $configs,
'name_controller' => 'form_codition',
);
}
public function validateCustomField(&$errors)
{
$type_action = Tools::getValue('type_action');
if ($type_action == 'action_on_shipping')
{
$apply_free_shipping = (int)Tools::getValue('apply_free_shipping');
if (!$apply_free_shipping)
{
$discount_on_shipping_cost = Tools::getValue('discount_on_shipping_cost');
if ($discount_on_shipping_cost == 'percent')
{
$percent_discount_on_shipping_cost = Tools::getValue('percent_discount_on_shipping_cost');
if ($percent_discount_on_shipping_cost == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount_on_shipping_cost) || $percent_discount_on_shipping_cost <= 0 || $percent_discount_on_shipping_cost > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_on_shipping_cost == 'amount')
{
$amount_discount = Tools::getValue('amount_discount_on_shipping_cost');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
$carrier_apply_discount_on_shipping_cost = Tools::getValue('carrier_apply_discount_on_shipping_cost');
if (!$carrier_apply_discount_on_shipping_cost)
$errors[] = $this->l('Apply to carriers is required');
elseif (!Ets_promotion::validateArray($carrier_apply_discount_on_shipping_cost))
$errors[] = $this->l('Apply to carriers is not valid');
}
elseif ($type_action == 'order_amount')
{
$discount_type = Tools::getValue('discount_on_total_cart');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_total_cart');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_total_cart');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
elseif ($type_action == 'action_on_product')
{
$advance_setting = true;
$discount_type = Tools::getValue('discount_type');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_discount_proudct');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_discount_product');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
elseif ($type_action == 'discount_on_all_quantities')
{
$advance_setting = true;
$purchase_quantity_more_of_same_product = Tools::getValue('purchase_quantity_more_of_same_product');
if ($purchase_quantity_more_of_same_product == '')
$errors[] = $this->l('Buy value is required');
elseif (!Validate::isUnsignedInt($purchase_quantity_more_of_same_product) || $purchase_quantity_more_of_same_product <= 0)
$errors[] = $this->l('Buy value is not valid');
$discount_type = Tools::getValue('discount_on_all_quantities');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_discount_on_all_quantities');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_discount_on_all_quantities');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
elseif ($type_action == 'purchase_discount_on_next_same_product')
{
$advance_setting = true;
$purchase = Tools::getValue('purchase_discount_on_next_same_product');
if ($purchase == '')
$errors[] = $this->l('Buy value is required');
elseif (!Validate::isUnsignedInt($purchase) || $purchase <= 0)
$errors[] = $this->l('Buy value is not valid');
$discount_type = Tools::getValue('discount_on_next_same_product');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_discount_on_next_same_product');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_discount_on_next_same_product');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
$repeat_the_action_on_next_same_product = Tools::getValue('repeat_the_action_on_next_same_product');
if ($repeat_the_action_on_next_same_product == 'many_time_on_1_product')
{
$maximum_time = Tools::getValue('maximum_time_on_next_same_product');
if ($maximum_time == '')
$errors[] = $this->l('Maximum times is required');
elseif (!Validate::isUnsignedInt($maximum_time) || $maximum_time <= 0)
$errors[] = $this->l('Maximum times is not valid');
}
}
elseif ($type_action == 'purchase_more_product_quantity')
{
$advance_setting = true;
$purchase = Tools::getValue('purchase_more_product_quantity');
if ($purchase == '')
$errors[] = $this->l('Buy value is required');
elseif (!Validate::isUnsignedInt($purchase) || $purchase <= 0)
$errors[] = $this->l('Buy value is not valid');
$discount_type = Tools::getValue('discount_purchase_more_product_quantity');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_discount_purchase_more_product_quantity');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_discount_purchase_more_product_quantity');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
elseif ($type_action == 'purchase_more_product_amount')
{
$advance_setting = true;
$purchase = Tools::getValue('purchase_more_product_amount');
if ($purchase == '')
$errors[] = $this->l('Buy value is required');
elseif (!Validate::isUnsignedFloat($purchase) || $purchase <= 0)
$errors[] = $this->l('Buy value is not valid');
$discount_type = Tools::getValue('discount_purchase_more_product_amount');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_discount_purchase_more_product_amount');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_discount_purchase_more_product_amount');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
elseif ($type_action == 'gift_or_with_discount_product')
{
$gift_or_with_discount_product = Tools::getValue('gift_or_with_discount_product');
if ($gift_or_with_discount_product == 'new_product')
{
$discount_type = Tools::getValue('new_product_with_discount_price');
if ($discount_type == 'percent')
{
$percent_discount = Tools::getValue('percent_new_product_with_discount_price');
if ($percent_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($percent_discount) || $percent_discount <= 0 || $percent_discount > 100)
$errors[] = $this->l('Discount value is not valid');
}
elseif ($discount_type == 'amount')
{
$amount_discount = Tools::getValue('amount_new_product_with_discount_price');
if ($amount_discount == '')
$errors[] = $this->l('Discount value is required');
elseif (!Validate::isUnsignedFloat($amount_discount) || $amount_discount <= 0)
$errors[] = $this->l('Discount value is not valid');
}
}
$gift_product = trim(Tools::getValue('gift_product'), ',');
if ($gift_product == '')
$errors[] = $this->l('Select product is required');
elseif (!Validate::isCleanHtml($gift_product))
$errors[] = $this->l('Select product is not valid');
$quantity_gift_product = Tools::getValue('quantity_gift_product');
if ($quantity_gift_product == '')
$errors[] = $this->l('Product quantity is required');
elseif (!Validate::isCleanHtml($gift_product))
$errors[] = $this->l('Product quantity is not valid');
}
if (isset($advance_setting) && $advance_setting)
{
$apply_all_attribute = (int)Tools::getValue('apply_all_attribute');
$select_attributes = Tools::getValue('select_attributes');
$apply_all_features = (int)Tools::getValue('apply_all_features');
$select_features = Tools::getValue('select_features');
$apply_all_manufacturer = (int)Tools::getValue('apply_all_manufacturer');
$select_manufacturers = Tools::getValue('select_manufacturers');
$apply_all_supplier = (int)Tools::getValue('apply_all_supplier');
$select_suppliers = Tools::getValue('select_suppliers');
if (!$apply_all_attribute && !$select_attributes)
$errors[] = $this->l('Select attributes is required');
elseif ($select_attributes && !Ets_promotion::validateArray($select_attributes))
$errors[] = $this->l('Select attributes is not valid');
if (!$apply_all_features && !$select_features)
$errors[] = $this->l('Select features is required');
elseif ($select_features && !Ets_promotion::validateArray($select_features))
$errors[] = $this->l('Select features is not valid');
if (!$apply_all_supplier && !$select_suppliers)
$errors[] = $this->l('Select suppliers is required');
elseif ($select_suppliers && !Ets_promotion::validateArray($select_suppliers))
$errors[] = $this->l('Select suppliers is not valid');
if (!$apply_all_manufacturer && !$select_manufacturers)
$errors[] = $this->l('Select manufacturers is required');
elseif ($select_manufacturers && !Ets_promotion::validateArray($select_manufacturers))
$errors[] = $this->l('Select manufacturers is not valid');
}
$apply_discount_code = Tools::getValue('apply_discount_code');
if ($apply_discount_code == 'code')
{
$code = Tools::getValue('code');
if ($code == '')
$errors[] = $this->l('Discount code is required');
elseif ($code != '' && !Validate::isCleanHtml($code))
$errors[] = $this->l('Discount code is not valid');
elseif ($code && (CartRule::cartRuleExists($code) || (($id = Ets_pr_rule::ruleExists($code)) && $this->id_ets_pr_rule != $id)))
$errors[] = $this->l('Discount code is already existed');
}
else
{
$this->cdoe = '';
$this->highlight = 0;
}
}
public function add($auto_date = true, $null_value = false)
{
if ($this->apply_discount_code == 'auto')
{
$this->code = '';
$this->highlight = 0;
}
if (parent::add($auto_date, $null_value))
{
return true;
}
}
public function update($null_value = false)
{
if ($this->apply_discount_code == 'auto')
{
$this->code = '';
$this->highlight = 0;
}
if (parent::update($null_value))
{
return true;
}
}
public static function getActionByIdRule($id_rule)
{
$cache_id = 'ets_pr_action_rule_getActionByIdRule' . $id_rule;
if (!Cache::isStored($cache_id))
{
$id = (int)Db::getInstance()->getValue('SELECT id_ets_pr_action_rule FROM `' . _DB_PREFIX_ . 'ets_pr_action_rule` WHERE id_ets_pr_rule=' . (int)$id_rule);
if ($id)
$action = new Ets_pr_action_rule($id);
else
{
$action = new Ets_pr_action_rule();
$action->id_ets_pr_rule = $id_rule;
}
Cache::store($cache_id, $action);
return $action;
}
else
{
return Cache::retrieve($cache_id);
}
}
public function getAdvancedProducts($products_with_different_attribute = true, $orderBy = '')
{
$cart = Context::getContext()->cart;
if ($cart->id)
{
$products = $cart->getProducts();
if (!$products)
return false;
$product_includes = array();
$attribute_includes = array();
$product_excludes = array();
$attribute_excludes = array();
$products_with_different_attribute;
if (!$this->apply_for_discounted_product)
{
if ($products)
{
foreach ($products as $product)
{
if (isset($product['specific_prices']) && $product['specific_prices'])
{
if ($product['id_product_attribute'] && $products_with_different_attribute)
$attribute_excludes[] = $product['id_product_attribute'];
else
$product_excludes[] = $product['id_product'];
}
}
}
}
if ($this->exclude_products)
{
$exclude_products = explode(',', $this->exclude_products);
if ($exclude_products)
{
foreach ($exclude_products as $exdlude_product)
{
if ($exdlude_product)
{
$ids = explode('-', $exdlude_product);
if (isset($ids[1]) && $ids[1] && $products_with_different_attribute)
$attribute_excludes[] = $ids[1];
elseif ($ids[0])
$product_excludes[] = $ids[0];
}
}
}
}
$filter = '';
$leftJoin = '';
$joinProduct = false;
if ($this->applicable_product_categories == 'specific_product')
{
if ($this->applicable_categories)
{
$id_categories = explode(',', $this->applicable_categories);
if (!$this->include_sub_categories)
{
$sql = 'SELECT cp.id_product,cp.id_product_attribute FROM `' . _DB_PREFIX_ . 'cart_product` cp
INNER JOIN `' . _DB_PREFIX_ . 'category_product` cap ON (cap.id_product = cp.id_product)
WHERE cp.id_cart="' . (int)Context::getContext()->cart->id . '" AND cap.id_category IN (' . implode(',', array_map('intval', $id_categories)) . ')
GROUP BY cp.id_product,cp.id_product_attribute';
}
else
{
$sql = 'SELECT cp.id_product,cp.id_product_attribute FROM `' . _DB_PREFIX_ . 'cart_product` cp
INNER JOIN `' . _DB_PREFIX_ . 'category_product` cap ON (cap.id_product = cp.id_product)
LEFT JOIN `' . _DB_PREFIX_ . 'category` ca ON (ca.id_category = cap.id_category)
LEFT JOIN `' . _DB_PREFIX_ . 'category` ca2 ON (ca.id_parent = ca2.id_category)
WHERE cp.id_cart="' . (int)Context::getContext()->cart->id . '" AND (cap.id_category IN (' . implode(',', array_map('intval', $id_categories)) . ') OR ca2.id_category IN (' . implode(',', array_map('intval', $id_categories)) . ') )
GROUP BY cp.id_product,cp.id_product_attribute';
}
$cart_products = Db::getInstance()->executeS($sql);
if ($cart_products)
{
foreach ($cart_products as $cart_product)
{
if ($products_with_different_attribute && $cart_product['id_product_attribute'])
$attribute_includes[] = $cart_product['id_product_attribute'];
else
$product_includes[] = $cart_product['id_product'];
}
}
if (!$attribute_includes && !$product_includes)
return false;
}
if ($this->include_specific_products)
{
$include_products = explode(',', $this->include_specific_products);
if ($include_products)
{
foreach ($include_products as $include_product)
{
if ($include_product)
{
$ids = explode('-', $include_product);
if (isset($ids[1]) && $ids[1] && $products_with_different_attribute)
$attribute_includes[] = $ids[1];
elseif ($ids[0])
$product_includes[] = $ids[0];
}
}
}
if (!$attribute_includes && !$product_includes)
return false;
}
}
if ($this->apply_for_product_price != 0)
{
if (!$products_with_different_attribute)
{
if (!$joinProduct)
{
$leftJoin .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = cp.id_product)';
$joinProduct = true;
}
$filter .= ' AND p.price ' . pSQL($this->apply_for_product_price_cal, true) . '"' . (float)$this->apply_for_product_price . '"';
}
else
{
$apply_for_product_price = Tools::convertPrice($this->apply_for_product_price);
foreach ($products as $product)
{
$price = Product::getPriceStatic($product['id_product'], true, $product['id_product_attribute']);
if (!Ets_pr_rule::checkCalculator($apply_for_product_price, $price, $this->apply_for_product_price_cal))
{
if ($product['id_product_attribute'])
$attribute_excludes[] = $product['id_product_attribute'];
else
$product_excludes[] = $product['id_product'];
}
}
}
}
if ($this->apply_for_availabled_quantity_stock != 0)
{
if (!$products_with_different_attribute)
{
if (!$joinProduct)
{
$leftJoin .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = cp.id_product)';
$joinProduct = true;
}
$leftJoin .= ' LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` stock ON (p.id_product = stock.id_product AND stock.id_product_attribute=0)';
$filter .= ' AND stock.quantity ' . pSQL($this->apply_for_availabled_quantity_stock_cal, true) . '"' . (int)$this->apply_for_availabled_quantity_stock . '"';
}
else
{
$apply_for_availabled_quantity_stock = $this->apply_for_availabled_quantity_stock;
foreach ($products as $product)
{
$quantity = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']);
if (!Ets_pr_rule::checkCalculator($apply_for_availabled_quantity_stock, $quantity, $this->apply_for_availabled_quantity_stock_cal))
{
if ($product['id_product_attribute'])
$attribute_excludes[] = $product['id_product_attribute'];
else
$product_excludes[] = $product['id_product'];
}
}
}
}
if (!$this->apply_all_attribute && $this->select_attributes && $this->select_attributes != 'all')
{
$select_attributes = explode(',', $this->select_attributes);
$sql = 'SELECT DISTINCT cp.id_product,cp.id_product_attribute FROM `' . _DB_PREFIX_ . 'cart_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` a ON (a.id_product_attribute = cp.id_product_attribute)
WHERE cp.id_cart = "' . (int)$cart->id . '" AND a.id_attribute IN (' . implode(',', array_map('intval', $select_attributes)) . ')';
if ($attributes = Db::getInstance()->executeS($sql))
{
foreach ($attributes as $attibute)
{
if ($products_with_different_attribute && $attibute['id_product_attribute'])
$attribute_includes[] = $attibute['id_product_attribute'];
else
$product_includes[] = $attibute['id_product'];
}
}
else
return false;
}
if (!$this->apply_all_features && $this->select_features && $this->select_features != 'all')
{
$select_features = explode(',', $this->select_features);
$sql = 'SELECT DISTINCT cp.id_product,cp.id_product_attribute FROM `' . _DB_PREFIX_ . 'cart_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'feature_product` fp ON (fp.id_product = cp.id_product)
LEFT JOIN `' . _DB_PREFIX_ . 'feature` f ON (f.id_feature = fp.id_feature)
WHERE cp.id_cart="' . (int)$cart->id . '" AND f.id_feature IN (' . implode(',', array_map('intval', $select_features)) . ')';
if ($features = Db::getInstance()->executeS($sql))
{
foreach ($features as $feature)
{
if ($products_with_different_attribute && $feature['id_product_attribute'])
$attribute_includes[] = $feature['id_product_attribute'];
else
$product_includes[] = $feature['id_product'];
}
}
else
return false;
}
if (!$this->apply_all_supplier && $this->select_suppliers && $this->select_suppliers != 'all')
{
$select_suppliers = explode(',', $this->select_suppliers);
$sql = 'SELECT DISTINCT cp.id_product,cp.id_product_attribute FROM `' . _DB_PREFIX_ . 'cart_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (ps.id_product = cp.id_product AND ps.id_product_attribute=cp.id_product_attribute)
LEFT JOIN `' . _DB_PREFIX_ . 'supplier` su ON (su.id_supplier = ps.id_supplier);
WHERE cp.id_cart="' . (int)$cart->id . '" AND su.id_supplier IN (' . implode(',', array_map('intval', $select_suppliers)) . ')';
if ($suppliers = Db::getInstance()->executeS($sql))
{
foreach ($suppliers as $supplier)
{
if ($products_with_different_attribute && $supplier['id_product_attribute'])
$attribute_includes[] = $supplier['id_product_attribute'];
else
$product_includes[] = $supplier['id_product'];
}
}
else
return false;
}
if ($product_excludes)
$filter .= ' AND cp.id_product NOT IN (' . implode(',', array_map('intval', $product_excludes)) . ')';
if ($attribute_excludes)
$filter .= ' AND cp.id_product_attribute NOT IN (' . implode(',', array_map('intval', $attribute_excludes)) . ')';
if ($product_includes)
$filter .= ' AND ' . (!$attribute_includes ? 'cp.id_product IN (' . implode(',', array_map('intval', $product_includes)) . ')' : '(cp.id_product IN (' . implode(',', array_map('intval', $product_includes)) . ') OR cp.id_product_attribute IN (' . implode(',', array_map('intval', $attribute_includes)) . '))') . ' ';
elseif ($attribute_includes)
$filter .= ' AND cp.id_product_attribute IN (' . implode(',', array_map('intval', $attribute_includes)) . ')';
if (!$this->apply_all_manufacturer && $this->select_manufacturers && $this->select_manufacturers != 'all')
{
$select_manufacturers = explode(',', $this->select_manufacturers);
if (!$joinProduct)
{
$leftJoin .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = cp.id_product)';
$joinProduct = true;
}
$filter .= ' AND p.id_manufacturer IN (' . implode(',', array_map('intval', $select_manufacturers)) . ')';
}
if ($products_with_different_attribute)
{
$cache_id = 'ets_pr_action_rule_getAdvancedProducts_products_1_' . md5($leftJoin) . $cart->id . md5($filter) . ($orderBy ? md5($orderBy) : '');
if (!Cache::isStored($cache_id))
{
$products = Db::getInstance()->executeS('SELECT sum(cp.quantity) as total_quantity,cp.id_product,cp.id_product_attribute FROM `' . _DB_PREFIX_ . 'cart_product` cp
' . ((string)$leftJoin ?: '') . '
WHERE cp.id_cart=' . (int)$cart->id . (string)$filter . ' GROUP BY cp.id_product,cp.id_product_attribute' . ($orderBy ? ' ORDER BY ' . pSQL($orderBy) : ''));
Cache::store($cache_id, $products);
}
else
{
$products = Cache::retrieve($cache_id);
}
}
else
{
$cache_id = 'ets_pr_action_rule_getAdvancedProducts_products_0_' . md5($leftJoin) . $cart->id . md5($filter) . ($orderBy ? md5($orderBy) : '');
if (!Cache::isStored($cache_id))
{
$products = Db::getInstance()->executeS('SELECT sum(cp.quantity) as total_quantity,cp.id_product FROM `' . _DB_PREFIX_ . 'cart_product` cp
' . ((string)$leftJoin ?: '') . '
WHERE cp.id_cart=' . (int)$cart->id . (string)$filter . ' GROUP BY cp.id_product' . ($orderBy ? ' ORDER BY ' . pSQL($orderBy) : ''));
Cache::store($cache_id, $products);
}
else
{
$products = Cache::retrieve($cache_id);
}
}
if (!$products)
return false;
else
return $products;
}
return false;
}
public static function getPriceProduct(&$products, $discount_on_product)
{
foreach ($products as &$product)
{
if (isset($product['id_product_attribute']))
$product['price'] = Product::getPriceStatic($product['id_product'], false, $product['id_product_attribute']);
else
{
$productObj = new Product($product['id_product']);
$product['price'] = Tools::convertPrice($productObj->price);
}
}
unset($product);
if (count($products) >= 2 && ($discount_on_product == 'cheapest_product' || $discount_on_product == 'most_expensive_product'))
{
for ($i = 0; $i < count($products) - 1; $i++)
for ($j = $i + 1; $j <= count($products) - 1; $j++)
{
if ($discount_on_product == 'cheapest_product')
{
if ($products[$i]['price'] > $products[$j]['price'])
{
$tam = $products[$i];
$products[$i] = $products[$j];
$products[$j] = $tam;
}
}
else
{
if ($products[$i]['price'] < $products[$j]['price'])
{
$tam = $products[$i];
$products[$i] = $products[$j];
$products[$j] = $tam;
}
}
}
}
return $products;
}
public function getPriceDiscount($use_tax = true)
{
switch ($this->type_action)
{
case 'action_on_shipping':
return $this->getPriceActionOnShipping($use_tax);
case 'order_amount':
return $this->getPriceActionOrderAmount($use_tax);
case 'action_on_product':
return $this->getPriceActionOnProduct($use_tax);
case 'discount_on_all_quantities':
return $this->getPriceActionOnAllQuantity($use_tax);
case 'purchase_discount_on_next_same_product':
return $this->getPriceActionOnNextSameProduct($use_tax);
case 'gift_or_with_discount_product':
return $this->getPriceGiftOrWithDiscountProduct($use_tax);
case 'purchase_more_product_quantity':
return $this->getPriceActionOnMoreProductQuantity($use_tax);
case 'purchase_more_product_amount':
return $this->getPriceActionOnMoreProductAmount($use_tax);
}
}
public function getPriceGiftOrWithDiscountProduct($use_tax = true)
{
if ($this->gift_product)
{
$gift_products = explode(',', $this->gift_product);
if ($gift_products)
{
$totalPrice = 0;
$totalQuantity = 0;
$quantity_gift_product = (int)$this->quantity_gift_product;
if ($this->apply_action_on == 'cheapest' || $this->apply_action_on == 'most_expensive')
{
if ($gift_products)
{
$priceProduct = 0;
$id_product = 0;
$quantityProduct = 0;
foreach ($gift_products as $gift_product)
{
if ($gift_product)
{
$product = explode('-', $gift_product);
if (Validate::isLoadedObject(new Product($product[0])) && ($quantity = (int)Db::getInstance()->getValue('SELECT quantity FROM `' . _DB_PREFIX_ . 'cart_product` WHERE id_cart=' . (int)Context::getContext()->cart->id . ' AND id_product="' . (int)$product[0] . '"' . (isset($product[1]) && $product[1] ? ' AND id_product_attribute="' . (int)$product[1] . '"' : ''))))
{
$price = Product::getPriceStatic($product[0], false, isset($product[1]) ? $product[1] : 0);
if (!$id_product)
{
$priceProduct = $price;
$id_product = (int)$product[0];
$quantityProduct = $quantity;
}
elseif (($this->apply_action_on == 'cheapest' && $priceProduct > $price) || ($this->apply_action_on == 'most_expensive' && $priceProduct < $price))
{
$priceProduct = $price;
$id_product = (int)$product[0];
$quantityProduct = $quantity;
}
}
}
}
if ($id_product && $quantityProduct)
{
if ($quantityProduct < $quantity_gift_product)
{
$totalPrice += $priceProduct * $quantityProduct;
$totalQuantity += $quantityProduct;
}
else
{
$totalPrice += $priceProduct * $quantity_gift_product;
$totalQuantity += $quantity_gift_product;
}
}
}
}
else
{
foreach ($gift_products as $gift_product)
{
if ($gift_product)
{
$product = explode('-', $gift_product);
$id_product = (int)$product[0];
$id_product_attribute = isset($product[1]) ? $product[1] : 0;
if ($quantity = (int)Db::getInstance()->getValue('SELECT quantity FROM `' . _DB_PREFIX_ . 'cart_product` WHERE id_cart=' . (int)Context::getContext()->cart->id . ' AND id_product="' . (int)$id_product . '"' . ($id_product_attribute ? ' AND id_product_attribute="' . (int)$id_product_attribute . '"' : '')))
{
$price = Product::getPriceStatic($id_product, $use_tax, $id_product_attribute);
if ($quantity < $quantity_gift_product)
{
$totalPrice += $price * $quantity;
$totalQuantity += $quantity;
}
else
{
$totalPrice += $price * $quantity_gift_product;
$totalQuantity += $quantity_gift_product;
}
}
}
}
}
if ($this->gift_or_with_discount_product == 'gift_product')
{
return $totalPrice;
}
else
{
if ($this->new_product_with_discount_price == 'percent')
{
$priceDiscount = $totalPrice * $this->percent_new_product_with_discount_price / 100;
$max_discount = $this->maximum_new_product_with_discount_price > 0 ? Tools::convertPrice($this->maximum_new_product_with_discount_price) : 0;
if ($max_discount > 0 && $priceDiscount > $max_discount)
return $max_discount;
else
return $priceDiscount;
}
else
{
if ($this->reduction_currency == Context::getContext()->currency->id)
{
$amount_discount = $this->amount_new_product_with_discount_price;
}
elseif ($this->reduction_currency_discount_on_new_product == Configuration::get('PS_CURRENCY_DEFAULT'))
{
$amount_discount = Tools::convertPrice($this->amount_new_product_with_discount_price);
}
elseif ($this->reduction_currency_discount_on_new_product && ($currency = new Currency($this->reduction_currency_discount_on_new_product)) && Validate::isLoadedObject($currency))
{
$amount_discount = Tools::convertPrice(Tools::convertPrice($this->amount_new_product_with_discount_price, $currency, false));
}
else
$amount_discount = Tools::convertPrice($this->amount_new_product_with_discount_price);
$priceDiscount = $amount_discount * $totalQuantity;
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($use_tax)
{
if ($tax_cart && !$this->reduction_tax_discount_on_new_product)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
else
{
if ($tax_cart && $this->reduction_tax_discount_on_new_product)
{
$priceDiscount = $priceDiscount / (1 + $tax_cart);
}
}
return $priceDiscount;
}
}
}
}
return 0;
}
public function getPriceActionOnMoreProductAmount($use_tax = true)
{
$start_counting = $this->start_counting_purchase_more_product_amount;
if ($products = $this->getAdvancedProducts(true, $start_counting == 'least_quantity' ? ' total_quantity ASC' : ' total_quantity DESC'))
{
self::getPriceProduct($products, $start_counting);
$purchase_amount = Tools::convertPrice($this->purchase_more_product_amount);
$price = 0;
$totalQuantity = 0;
$totalPrice = 0;
foreach ($products as $product)
{
for ($n = 1; $n <= $product['total_quantity']; $n++)
{
if ($price < $purchase_amount)
{
$price += $product['price'];
}
else
{
$totalPrice += $product['price'];
$totalQuantity++;
}
}
}
$discount_type = $this->discount_purchase_more_product_amount;
$max_discount = $this->maximum_discount_purchase_more_product_amount > 0 ? Tools::convertPrice($this->maximum_discount_purchase_more_product_amount) : 0;
if ($discount_type == 'amount')
{
$amount_discount = self::convertPriceByCurrency($this->amount_discount_purchase_more_product_amount, $this->reduction_currency_discount_on_more_product_amount);
$priceDiscount = $amount_discount * $totalQuantity;
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($use_tax)
{
$max_discount += $max_discount * $tax_cart;
if ($tax_cart && !$this->reduction_tax_discount_on_more_product_amount)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
else
{
if ($tax_cart && $this->reduction_tax_discount_on_more_product_amount)
{
$priceDiscount = $priceDiscount / (1 + $tax_cart);
}
}
}
else
{
$percent_discount = $this->percent_discount_purchase_more_product_amount;
$priceDiscount = Tools::ps_round($totalPrice * $percent_discount / 100, 2);
if ($use_tax)
{
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($tax_cart)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
}
if ($max_discount && $max_discount < $priceDiscount)
return $max_discount;
else
return $priceDiscount;
}
}
public static function convertPriceByCurrency($price, $id_currency)
{
if ($id_currency == Context::getContext()->currency->id)
{
return $price;
}
elseif ($id_currency == Configuration::get('PS_CURRENCY_DEFAULT'))
{
return Tools::convertPrice($price);
}
elseif ($id_currency && ($currency = new Currency($id_currency)) && Validate::isLoadedObject($currency))
{
return Tools::convertPrice(Tools::convertPrice($price, $currency, false));
}
else
return Tools::convertPrice($price);
}
public static function getTaxCart()
{
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
return Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
}
public function getPriceActionOnMoreProductQuantity($use_tax)
{
$start_counting = $this->start_counting_purchase_more_product_quantity;
if ($products = $this->getAdvancedProducts(true, $start_counting == 'least_quantity' ? ' total_quantity ASC' : ' total_quantity DESC'))
{
self::getPriceProduct($products, $start_counting);
$purchase = (int)$this->purchase_more_product_quantity;
$discount_type = $this->discount_purchase_more_product_quantity;
$max_discount = $this->maximum_discount_purchase_more_product_quantity > 0 ? Tools::convertPrice($this->maximum_discount_purchase_more_product_quantity) : 0;
if ($discount_type == 'amount')
{
$totalQuantity = (int)Db::getInstance()->getValue('SELECT SUM(quantity) FROM `' . _DB_PREFIX_ . 'cart_product` WHERE id_cart=' . (int)Context::getContext()->cart->id);
$amount_discount = self::convertPriceByCurrency($this->amount_discount_purchase_more_product_quantity, $this->reduction_currency_discount_on_more_product_quantity);
$priceDiscount = ($totalQuantity - $purchase) * $amount_discount;
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($use_tax)
{
$max_discount += $max_discount * $tax_cart;
if ($tax_cart && !$this->reduction_tax_discount_on_more_product_quantity)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
else
{
if ($tax_cart && $this->reduction_tax_discount_on_more_product_quantity)
{
$priceDiscount = $priceDiscount / (1 + $tax_cart);
}
}
}
else
{
$totalQuantity = 0;
$price = 0;
foreach ($products as $product)
{
if ($totalQuantity > $purchase)
{
$price += $product['price'] * $product['total_quantity'];
}
else
{
$totalQuantity += (int)$product['total_quantity'];
if ($totalQuantity > $purchase)
{
$price += $product['price'] * ($totalQuantity - $purchase);
}
}
}
$percent_discount = $this->percent_discount_purchase_more_product_quantity;
$priceDiscount = Tools::ps_round($price * $percent_discount / 100, 2);
if ($use_tax)
{
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
$max_discount += $max_discount * $tax_cart;
if ($tax_cart && !$this->reduction_tax_discount_on_more_product_quantity)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
}
if ($max_discount && $max_discount < $priceDiscount)
return $max_discount;
else
return $priceDiscount;
}
}
public function getPriceActionOnNextSameProduct($use_tax = true)
{
$discount_on = $this->action_on_next_same_product;
if ($products = $this->getAdvancedProducts($this->product_with_deffierent_attribute, $discount_on == 'least_quantity' ? ' total_quantity ASC' : ' total_quantity DESC'))
{
self::getPriceProduct($products, $discount_on);
$purchase = $this->purchase_discount_on_next_same_product;
$apply_next_quantity = (int)$this->apply_on_next_same_product;
$priceDiscount = 0;
$discount_type = $this->discount_on_next_same_product;
$repeat_action = $this->repeat_the_action_on_next_same_product;
$maximum_times = $this->maximum_time_on_next_same_product;
$tax_cart = self::getTaxCart();
foreach ($products as $product)
{
if ($product['total_quantity'] > $purchase)
{
$quantity = Db::getInstance()->getValue('SELECT SUM(quantity) FROM `' . _DB_PREFIX_ . 'cart_product` WHERE id_cart="' . (int)Context::getContext()->cart->id . '" AND id_product="' . (int)$product['id_product'] . '"' . (isset($product['id_product_attribute']) ? ' AND id_product_attribute=' . (int)$product['id_product_attribute'] : ''));
if ($repeat_action == 'once_on_1_product' || $maximum_times == 1 || $apply_next_quantity <= 0)
{
$apply_quantity = $quantity - $purchase;
if ($discount_type == 'free')
{
$priceProduct = $product['price'] * $apply_quantity;
$priceDiscount += Tools::ps_round($priceProduct, 2);
}
elseif ($discount_type == 'percent')
{
$priceProduct = $product['price'] * $apply_quantity;
$priceDiscount += Tools::ps_round($priceProduct * $this->percent_discount_on_next_same_product / 100, 2);
}
else
{
$amount_discount_product = self::convertPriceByCurrency($this->amount_discount_on_next_same_product, $this->reduction_currency_discount_on_next_same_product);
if ($this->amount_discount_on_next_same_product_tax_incl && $tax_cart > 0)
$amount_discount_product = $amount_discount_product / (1 + $tax_cart);
$priceDiscount += $apply_quantity * $amount_discount_product;
}
}
else
{
$action_times = 1;
while ($quantity > $purchase && $action_times <= $maximum_times)
{
$apply_quantity = $quantity - $purchase;
if ($apply_quantity > $apply_next_quantity)
$apply_quantity = $apply_next_quantity;
$quantity -= ($apply_quantity + $purchase);
$action_times++;
if ($discount_type == 'free')
{
$priceProduct = $product['price'] * $apply_quantity;
$priceDiscount += Tools::ps_round($priceProduct, 2);
}
elseif ($discount_type == 'percent')
{
$priceProduct = $product['price'] * $apply_quantity;
$priceDiscount += Tools::ps_round($priceProduct * $this->percent_discount_on_next_same_product / 100, 2);
}
else
{
$amount_discount_product = self::convertPriceByCurrency($this->amount_discount_on_next_same_product, $this->reduction_currency_discount_on_next_same_product);
if ($this->amount_discount_on_next_same_product_tax_incl && $tax_cart > 0)
$amount_discount_product = $amount_discount_product / (1 + $tax_cart);
$priceDiscount += $apply_quantity * $amount_discount_product;
}
}
}
if ($discount_on != 'all')
break;
}
}
$max_discount = $this->maximum_discount_on_next_same_product > 0 ? Tools::convertPrice($this->maximum_discount_on_next_same_product) : 0;
if ($use_tax && $tax_cart)
{
$max_discount += $max_discount * $tax_cart;
$priceDiscount += $priceDiscount * $tax_cart;
}
if ($max_discount && $priceDiscount > $max_discount)
return $max_discount;
else
return $priceDiscount;
}
}
public function getPriceActionOnAllQuantity($use_tax = true)
{
$discount_on = $this->discount_all_quantities_action_on;
if ($products = $this->getAdvancedProducts($this->product_with_deffierent_attribute, $discount_on == 'least_quantity' ? ' total_quantity ASC' : ' total_quantity DESC'))
{
self::getPriceProduct($products, $discount_on);
$purchase = $this->purchase_quantity_more_of_same_product;
$priceDiscount = 0;
$discount_type = $this->discount_on_all_quantities;
$max_discount = $this->maximum_discount_on_all_quantities > 0 ? Tools::convertPrice($this->maximum_discount_on_all_quantities) : 0;
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($use_tax)
$max_discount += $max_discount * $tax_cart;
foreach ($products as $product)
{
if ($product['total_quantity'] >= $purchase)
{
$quantity = Db::getInstance()->getValue('SELECT SUM(quantity) FROM `' . _DB_PREFIX_ . 'cart_product` WHERE id_cart="' . (int)Context::getContext()->cart->id . '" AND id_product="' . (int)$product['id_product'] . '"' . (isset($product['id_product_attribute']) ? ' AND id_product_attribute=' . (int)$product['id_product_attribute'] : ''));
if ($discount_type == 'percent')
{
$priceProduct = $product['price'] * $quantity;
$priceDiscount += Tools::ps_round($priceProduct * $this->percent_discount_on_all_quantities / 100, 2);
}
else
{
$amount_discount_product = self::convertPriceByCurrency($this->amount_discount_on_all_quantities, $this->reduction_currency_discount_all_quantities);
$priceDiscount += $quantity * $amount_discount_product;
}
if ($discount_on != 'all')
break;
}
}
if ($priceDiscount)
{
if ($discount_type == 'percent')
{
if ($use_tax)
$priceDiscount += $priceDiscount * $tax_cart;
}
else
{
if ($use_tax)
{
if ($tax_cart && !$this->reduction_tax_discount_all_quantities)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
else
{
if ($tax_cart && $this->reduction_tax_discount_all_quantities)
{
$priceDiscount = $priceDiscount / (1 + $tax_cart);
}
}
}
}
if ($max_discount && $priceDiscount > $max_discount)
return $max_discount;
else
return $priceDiscount;
}
}
public function getPriceActionOnProduct($use_tax = true)
{
$discount_on_product = $this->discount_on_product;
if ($products = $this->getAdvancedProducts($this->product_with_deffierent_attribute, $discount_on_product == 'least_quantity' ? ' total_quantity ASC' : ' total_quantity DESC'))
{
self::getPriceProduct($products, $discount_on_product);
$product = $products[0];
$discount_type = $this->discount_type;
$quantity = Db::getInstance()->getValue('SELECT SUM(quantity) FROM `' . _DB_PREFIX_ . 'cart_product` WHERE id_cart="' . (int)Context::getContext()->cart->id . '" AND id_product="' . (int)$product['id_product'] . '"' . (isset($product['id_product_attribute']) ? ' AND id_product_attribute=' . (int)$product['id_product_attribute'] : ''));
$max_discount = $this->maximum_discount_product != 0 ? Tools::convertPrice($this->maximum_discount_product) : 0;
if ($discount_type == 'percent')
{
$priceProduct = $product['price'];// * $quantity;
$priceDiscount = Tools::ps_round($priceProduct * $this->percent_discount_proudct / 100, 2);
if ($use_tax)
{
// $product = new Product( (int)$product['id_product'] );
// if ( $product->id_tax_rules_group )
// {
// $taxRate = Tax::getProductTaxRate((int)$product['id_product'] );
// echo $taxRate . '<br>';
// }
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Tax::getProductTaxRate((int)$product['id_product'] ) / 100; //Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($tax_cart)
{
$priceDiscount += $priceDiscount * $tax_cart;
$max_discount += $max_discount * $tax_cart;
}
}
}
else
{
$amount_discount_product = self::convertPriceByCurrency($this->amount_discount_product, $this->reduction_currency_discount_product);
$priceDiscount = $quantity * $amount_discount_product;
$cartAmountTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = Context::getContext()->cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($use_tax)
{
$max_discount += $max_discount * $tax_cart;
if ($tax_cart && !$this->reduction_tax_discount_product)
{
$priceDiscount += $priceDiscount * $tax_cart;
}
}
else
{
if ($tax_cart && $this->reduction_tax_discount_product)
{
$priceDiscount = $priceDiscount / (1 + $tax_cart);
}
}
}
if ($max_discount > 0 && $priceDiscount > $max_discount)
return $max_discount;
else
return $priceDiscount;
}
}
public function getPriceActionOrderAmount($use_tax = true)
{
$cart = Context::getContext()->cart;
$total_product = $cart->getOrderTotal(!$this->exclude_tax_before_cal_discount ? true : false, Cart::ONLY_PRODUCTS);
$total_shipping = $cart->getOrderTotal(true, Cart::ONLY_SHIPPING);
$cartRules = $cart->getCartRules();
$totalDiscount = 0;
$free_shipping = false;
if ($cartRules)
{
foreach ($cartRules as $cartRule)
{
if ($cartRule['free_shipping'])
$free_shipping = true;
$totalDiscount += $cartRule['value_real'];
}
}
$otherRules = Db::getInstance()->executeS('SELECT r.id_ets_pr_rule FROM `' . _DB_PREFIX_ . 'ets_pr_rule` r
INNER JOIN `' . _DB_PREFIX_ . 'ets_pr_cart_rule` cr ON (r.id_ets_pr_rule = cr.id_ets_pr_rule AND cr.id_cart="' . (int)$cart->id . '")
ORDER BY r.priority ASC, cr.date_add asc');
if ($otherRules)
{
foreach ($otherRules as $otherRule)
{
if ($otherRule['id_ets_pr_rule'] = $this->id_ets_pr_rule)
break;
else
{
$action = Ets_pr_action_rule::getActionByIdRule($otherRule['id_ets_pr_rule']);
if ($action->type_action == 'action_on_shipping' && $action->apply_free_shipping)
$free_shipping = true;
$totalDiscount += $action->getPriceDiscount();
}
}
}
if (!$this->exclude_shipping_fee_before_cal_disount)
{
$totalAmount = $total_product + $total_shipping - $totalDiscount;
}
else
{
if ($free_shipping)
$totalDiscount -= $total_shipping;
$totalAmount = $total_product - $totalDiscount;
}
if ($this->discount_on_total_cart == 'percent')
{
$discountPrice = Tools::ps_round($totalAmount * $this->percent_total_cart / 100, 2);
$maximum_discount = $this->maximum_discount_value > 0 ? Tools::convertPrice($this->maximum_discount_value) : 0;
if ($maximum_discount != 0 && $discountPrice > $maximum_discount)
$discountPrice = $maximum_discount;
}
else
{
$discountPrice = self::convertPriceByCurrency($this->amount_total_cart, $this->reduction_currency);
}
if ($discountPrice > $totalAmount)
$price = $totalAmount;
else
$price = $discountPrice;
$cartAmountTaxIncluded = $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cartAmountTaxExcluded = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$tax_cart = $cart->getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded);
if ($use_tax)
{
if ($tax_cart && !$this->reduction_tax)
{
$price += $price * $tax_cart;
}
}
else
{
if ($tax_cart && $this->reduction_tax)
{
$price = $price / (1 + $tax_cart);
}
}
return $price;
}
public function getPriceActionOnShipping($use_tax = true)
{
if ($this->apply_free_shipping)
{
$this->is_free_shipping = true;
return Context::getContext()->cart->getOrderTotal($use_tax, Cart::ONLY_SHIPPING);
}
else
{
$total_shipping = Context::getContext()->cart->getOrderTotal($use_tax, Cart::ONLY_SHIPPING);
if ($this->discount_on_shipping_cost == 'percent')
{
$priceDiscount = Tools::ps_round($total_shipping * $this->percent_discount_on_shipping_cost / 100, 2);
$maximum_discount = $this->maximum_discount_on_shipping_cost != 0 ? Tools::convertPrice($this->maximum_discount_on_shipping_cost) : 0;
if ($maximum_discount && $maximum_discount < $priceDiscount)
return $maximum_discount;
else
return $priceDiscount;
}
else
{
$priceDiscount = self::convertPriceByCurrency($this->amount_discount_on_shipping_cost, $this->reduction_currency_discount_on_shipping_cost);
$shippingTaxIncluded = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_SHIPPING);
$shippingTaxExcluded = Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_SHIPPING);
$shipping_vat_amount = $shippingTaxIncluded - $shippingTaxExcluded;
if ($shipping_vat_amount == 0 || $shippingTaxExcluded == 0)
$tax_shipping = 0;
else
$tax_shipping = Tools::ps_round($shipping_vat_amount / $shippingTaxExcluded, Tax::TAX_DEFAULT_PRECISION);
if ($use_tax)
{
if ($tax_shipping && !$this->reduction_tax_discount_on_shipping_cost)
{
$priceDiscount += $priceDiscount * $tax_shipping;
}
}
else
{
if ($tax_shipping && $this->reduction_tax_discount_on_shipping_cost)
{
$priceDiscount = $priceDiscount / (1 + $tax_shipping);
}
}
if ($priceDiscount < $total_shipping)
return $priceDiscount;
else
return $total_shipping;
}
}
}
}