示例#1
0
    protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
    {
        $content = '';
        if (!($obj = $this->loadObject())) {
            return;
        }
        $specific_prices = SpecificPrice::getByProductId((int) $obj->id);
        $specific_price_priorities = SpecificPrice::getPriority((int) $obj->id);
        $tax_rate = $obj->getTaxesRate(Address::initialize());
        $tmp = array();
        foreach ($shops as $shop) {
            $tmp[$shop['id_shop']] = $shop;
        }
        $shops = $tmp;
        $tmp = array();
        foreach ($currencies as $currency) {
            $tmp[$currency['id_currency']] = $currency;
        }
        $currencies = $tmp;
        $tmp = array();
        foreach ($countries as $country) {
            $tmp[$country['id_country']] = $country;
        }
        $countries = $tmp;
        $tmp = array();
        foreach ($groups as $group) {
            $tmp[$group['id_group']] = $group;
        }
        $groups = $tmp;
        if (!is_array($specific_prices) || !count($specific_prices)) {
            $content .= '
				<tr>
					<td class="text-center" colspan="13"><i class="icon-warning-sign"></i>&nbsp;' . $this->l('No specific prices.') . '</td>
				</tr>';
        } else {
            $i = 0;
            foreach ($specific_prices as $specific_price) {
                $current_specific_currency = $currencies[$specific_price['id_currency'] ? $specific_price['id_currency'] : $defaultCurrency->id];
                if ($specific_price['reduction_type'] == 'percentage') {
                    $impact = '- ' . $specific_price['reduction'] * 100 . ' %';
                } elseif ($specific_price['reduction'] > 0) {
                    $impact = '- ' . Tools::displayPrice(Tools::ps_round($specific_price['reduction'], 2), $current_specific_currency);
                } else {
                    $impact = '--';
                }
                if ($specific_price['from'] == '0000-00-00 00:00:00' && $specific_price['to'] == '0000-00-00 00:00:00') {
                    $period = $this->l('Unlimited');
                } else {
                    $period = $this->l('From') . ' ' . ($specific_price['from'] != '0000-00-00 00:00:00' ? $specific_price['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specific_price['to'] != '0000-00-00 00:00:00' ? $specific_price['to'] : '0000-00-00 00:00:00');
                }
                if ($specific_price['id_product_attribute']) {
                    $combination = new Combination((int) $specific_price['id_product_attribute']);
                    $attributes = $combination->getAttributesName((int) $this->context->language->id);
                    $attributes_name = '';
                    foreach ($attributes as $attribute) {
                        $attributes_name .= $attribute['name'] . ' - ';
                    }
                    $attributes_name = rtrim($attributes_name, ' - ');
                } else {
                    $attributes_name = $this->l('All combinations');
                }
                $rule = new SpecificPriceRule((int) $specific_price['id_specific_price_rule']);
                $rule_name = $rule->id ? $rule->name : '--';
                if ($specific_price['id_customer']) {
                    $customer = new Customer((int) $specific_price['id_customer']);
                    if (Validate::isLoadedObject($customer)) {
                        $customer_full_name = $customer->firstname . ' ' . $customer->lastname;
                    }
                    unset($customer);
                }
                if (!$specific_price['id_shop'] || in_array($specific_price['id_shop'], Shop::getContextListShopID())) {
                    $content .= '
					<tr ' . ($i % 2 ? 'class="alt_row"' : '') . '>
						<td>' . $rule_name . '</td>
						<td>' . $attributes_name . '</td>';
                    $can_delete_specific_prices = true;
                    if (Shop::isFeatureActive()) {
                        $id_shop_sp = $specific_price['id_shop'];
                        $can_delete_specific_prices = count($this->context->employee->getAssociatedShops()) > 1 && !$id_shop_sp || $id_shop_sp;
                        $content .= '
						<td>' . ($id_shop_sp ? $shops[$id_shop_sp]['name'] : $this->l('All shops')) . '</td>';
                    }
                    $price = Tools::ps_round($specific_price['price'], 2);
                    $fixed_price = $price == Tools::ps_round($obj->price, 2) || $specific_price['price'] == -1 ? '--' : Tools::displayPrice($price, $current_specific_currency);
                    $content .= '
						<td>' . ($specific_price['id_currency'] ? $currencies[$specific_price['id_currency']]['name'] : $this->l('All currencies')) . '</td>
						<td>' . ($specific_price['id_country'] ? $countries[$specific_price['id_country']]['name'] : $this->l('All countries')) . '</td>
						<td>' . ($specific_price['id_group'] ? $groups[$specific_price['id_group']]['name'] : $this->l('All groups')) . '</td>
						<td title="' . $this->l('ID:') . ' ' . $specific_price['id_customer'] . '">' . (isset($customer_full_name) ? $customer_full_name : $this->l('All customers')) . '</td>
						<td>' . $fixed_price . '</td>
						<td>' . $impact . '</td>
						<td>' . $period . '</td>
						<td>' . $specific_price['from_quantity'] . '</th>
						<td>' . (!$rule->id && $can_delete_specific_prices ? '<a class="btn btn-default" name="delete_link" href="' . self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&action=deleteSpecificPrice&id_specific_price=' . (int) $specific_price['id_specific_price'] . '&token=' . Tools::getValue('token') . '"><i class="icon-trash"></i></a>' : '') . '</td>
					</tr>';
                    $i++;
                    unset($customer_full_name);
                }
            }
        }
        $content .= '
				</tbody>
			</table>
			</div>
			<div class="panel-footer">
				<a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save') . '</button>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save and stay') . '</button>
			</div>
		</div>';
        $content .= '
		<script type="text/javascript">
			var currencies = new Array();
			currencies[0] = new Array();
			currencies[0]["sign"] = "' . $defaultCurrency->sign . '";
			currencies[0]["format"] = ' . $defaultCurrency->format . ';
			';
        foreach ($currencies as $currency) {
            $content .= '
				currencies[' . $currency['id_currency'] . '] = new Array();
				currencies[' . $currency['id_currency'] . ']["sign"] = "' . $currency['sign'] . '";
				currencies[' . $currency['id_currency'] . ']["format"] = ' . $currency['format'] . ';
				';
        }
        $content .= '
		</script>
		';
        // Not use id_customer
        if ($specific_price_priorities[0] == 'id_customer') {
            unset($specific_price_priorities[0]);
        }
        // Reindex array starting from 0
        $specific_price_priorities = array_values($specific_price_priorities);
        $content .= '<div class="panel">
		<h3>' . $this->l('Priority management') . '</h3>
		<div class="alert alert-info">
				' . $this->l('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . '
		</div>';
        $content .= '
		<div class="form-group">
			<label class="control-label col-lg-3" for="specificPricePriority1">' . $this->l('Priorities') . '</label>
			<div class="input-group col-lg-9">
				<select id="specificPricePriority1" name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[0] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[0] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[0] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[0] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
				<span class="input-group-addon"><i class="icon-chevron-right"></i></span>
				<select name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[1] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[1] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[1] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[1] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
				<span class="input-group-addon"><i class="icon-chevron-right"></i></span>
				<select name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[2] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[2] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[2] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[2] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
				<span class="input-group-addon"><i class="icon-chevron-right"></i></span>
				<select name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[3] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[3] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[3] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[3] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<div class="col-lg-9 col-lg-offset-3">
				<p class="checkbox">
					<label for="specificPricePriorityToAll"><input type="checkbox" name="specificPricePriorityToAll" id="specificPricePriorityToAll" />' . $this->l('Apply to all products') . '</label>
				</p>
			</div>
		</div>
		<div class="panel-footer">
				<a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save') . '</button>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save and stay') . '</button>
			</div>
		</div>
		';
        return $content;
    }
示例#2
0
 public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 {
     if (!Configuration::get('LEGAL_SHIPTAXMETH')) {
         return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
     }
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = Context::getContext()->country;
     }
     if (!is_null($product_list)) {
         foreach ($product_list as $key => $value) {
             if ($value['is_virtual'] == 1) {
                 unset($product_list[$key]);
             }
         }
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
         $address_id = (int) $this->id_address_invoice;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod['id_address_delivery'];
     } else {
         $address_id = null;
     }
     if (!Address::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
         }
     }
     if (Cache::isStored($cache_id)) {
         return Cache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if (!count($products)) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (!isset($id_zone)) {
         // Get id zone
         if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             if (!Validate::isLoadedObject($default_country)) {
                 $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
             }
             $id_zone = (int) $default_country->id_zone;
         }
     }
     if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
                 $total_order = $total_package_without_shipping_tax_inc;
                 $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $id_carrier = (int) $row['id_carrier'];
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     // No valid Carrier or $id_carrier <= 0 ?
     if (!Validate::isLoadedObject($carrier)) {
         Cache::store($cache_id, 0);
         return 0;
     }
     if (!$carrier->active) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         Cache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !Tax::excludeTaxeOption()) {
         $address = Address::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
     if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         if (!isset($id_zone)) {
             // Get id zone
             if (isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
                 $id_zone = Address::getZoneById((int) $this->id_address_delivery);
             } else {
                 $id_zone = (int) $default_country->id_zone;
             }
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $id_zone, (int) $this->id_currency)) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) {
         $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING'];
     }
     // Additional Shipping Cost per product
     foreach ($products as $product) {
         if (!$product['is_virtual']) {
             $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
         }
     }
     $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $module_name = $carrier->external_module_name;
         $module = Module::getInstanceByName($module_name);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $carrier->id;
             }
             if ($carrier->need_range) {
                 if (method_exists($module, 'getPackageShippingCost')) {
                     $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products);
                 } else {
                     $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
                 }
             } else {
                 $shipping_cost = $module->getOrderShippingCostExternal($this);
             }
             // Check if carrier is available
             if ($shipping_cost === false) {
                 Cache::store($cache_id, false);
                 return false;
             }
         } else {
             Cache::store($cache_id, false);
             return false;
         }
     }
     $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2);
     Cache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
 /**
  * Create or Updates Prestashop address
  * @return Address Address object
  */
 protected function createAddress($addressInformations, $address = null)
 {
     $country = $this->getCountryByCode($addressInformations->country->alpha2Code);
     if (!$country->active) {
         $this->addError(sprintf($this->module->l('This country is not active : %s'), $addressInformations->country->alpha2Code), PowaTagErrorType::$MERCHANT_WRONG_COUNTRY);
         return false;
     }
     if (!isset($addressInformations->friendlyName)) {
         $friendlyName = $this->module->l('My address');
     } else {
         $friendlyName = $addressInformations->friendlyName;
     }
     if (PowaTagAPI::apiLog()) {
         PowaTagLogs::initAPILog('Create address', PowaTagLogs::IN_PROGRESS, $addressInformations->lastName . ' ' . $addressInformations->firstName . ' : ' . $friendlyName);
     }
     $address = $address != null ? $address : Address::initialize();
     $address->id_customer = (int) $this->customer->id;
     $address->id_country = (int) $country->id;
     $address->alias = $friendlyName;
     $address->lastname = $addressInformations->lastName;
     $address->firstname = $addressInformations->firstName;
     $address->address1 = $addressInformations->line1;
     $address->address2 = $addressInformations->line2;
     $address->postcode = $addressInformations->postCode;
     $address->city = $addressInformations->city;
     $address->phone = isset($addressInformations->phone) ? $addressInformations->phone : '0000000000';
     $address->id_state = isset($addressInformations->state) ? (int) State::getIdByIso($addressInformations->state, (int) $country->id) : 0;
     if (!$address->save()) {
         $this->addError($this->module->l('Impossible to save address'), PowaTagErrorType::$INTERNAL_ERROR);
         if (PowaTagAPI::apiLog()) {
             PowaTagLogs::initAPILog('Create address', PowaTagLogs::ERROR, $this->error['message']);
         }
         return false;
     }
     if (PowaTagAPI::apiLog()) {
         PowaTagLogs::initAPILog('Create address', PowaTagLogs::SUCCESS, 'Address ID : ' . $address->id);
     }
     return $address;
 }
示例#4
0
 public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true)
 {
     $currency = new Currency((int) $order->id_currency);
     $order_slip = new OrderSlip();
     $order_slip->id_customer = (int) $order->id_customer;
     $order_slip->id_order = (int) $order->id;
     $order_slip->conversion_rate = $currency->conversion_rate;
     if ($add_tax) {
         $add_or_remove = 'add';
         $inc_or_ex_1 = 'excl';
         $inc_or_ex_2 = 'incl';
     } else {
         $add_or_remove = 'remove';
         $inc_or_ex_1 = 'incl';
         $inc_or_ex_2 = 'excl';
     }
     $order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = 0;
     $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = 0;
     $order_slip->partial = 0;
     if ($shipping_cost !== false) {
         $order_slip->shipping_cost = true;
         $carrier = new Carrier((int) $order->id_carrier);
         $address = Address::initialize($order->id_address_delivery, false);
         $tax_calculator = $carrier->getTaxCalculator($address);
         $order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = $shipping_cost === null ? $order->{'total_shipping_tax_' . $inc_or_ex_1} : (double) $shipping_cost;
         if ($tax_calculator instanceof TaxCalculator) {
             $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($order_slip->{'total_shipping_tax_' . $inc_or_ex_1}), _PS_PRICE_COMPUTE_PRECISION_);
         } else {
             $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
         }
     } else {
         $order_slip->shipping_cost = false;
     }
     $order_slip->amount = 0;
     $order_slip->{'total_products_tax_' . $inc_or_ex_1} = 0;
     $order_slip->{'total_products_tax_' . $inc_or_ex_2} = 0;
     foreach ($product_list as &$product) {
         $order_detail = new OrderDetail((int) $product['id_order_detail']);
         $price = (double) $product['unit_price'];
         $quantity = (int) $product['quantity'];
         $order_slip_resume = OrderSlip::getProductSlipResume((int) $order_detail->id);
         if ($quantity + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
             $quantity = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
         }
         if ($quantity == 0) {
             continue;
         }
         if (!Tools::isSubmit('cancelProduct') && $order->hasBeenPaid()) {
             $order_detail->product_quantity_refunded += $quantity;
         }
         $order_detail->save();
         $address = Address::initialize($order->id_address_invoice, false);
         $id_address = (int) $address->id;
         $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $order_detail->product_id);
         $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
         $order_slip->{'total_products_tax_' . $inc_or_ex_1} += $price * $quantity;
         if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
             if (!isset($total_products[$id_tax_rules_group])) {
                 $total_products[$id_tax_rules_group] = 0;
             }
         } else {
             if (!isset($total_products[$id_tax_rules_group . '_' . $id_address])) {
                 $total_products[$id_tax_rules_group . '_' . $id_address] = 0;
             }
         }
         $product_tax_incl_line = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price) * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
         switch (Configuration::get('PS_ROUND_TYPE')) {
             case Order::ROUND_ITEM:
                 $product_tax_incl = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_) * $quantity;
                 $total_products[$id_tax_rules_group] += $product_tax_incl;
                 break;
             case Order::ROUND_LINE:
                 $product_tax_incl = $product_tax_incl_line;
                 $total_products[$id_tax_rules_group] += $product_tax_incl;
                 break;
             case Order::ROUND_TOTAL:
                 $product_tax_incl = $product_tax_incl_line;
                 $total_products[$id_tax_rules_group . '_' . $id_address] += $price * $quantity;
                 break;
         }
         $product['unit_price_tax_' . $inc_or_ex_1] = $price;
         $product['unit_price_tax_' . $inc_or_ex_2] = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
         $product['total_price_tax_' . $inc_or_ex_1] = Tools::ps_round($price * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
         $product['total_price_tax_' . $inc_or_ex_2] = Tools::ps_round($product_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
     }
     unset($product);
     foreach ($total_products as $key => $price) {
         if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
             $tmp = explode('_', $key);
             $address = Address::initialize((int) $tmp[1], true);
             $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
             $order_slip->{'total_products_tax_' . $inc_or_ex_2} += Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
         } else {
             $order_slip->{'total_products_tax_' . $inc_or_ex_2} += $price;
         }
     }
     $order_slip->{'total_products_tax_' . $inc_or_ex_2} -= (double) $amount && !$amount_choosen ? (double) $amount : 0;
     $order_slip->amount = $amount_choosen ? (double) $amount : $order_slip->{'total_products_tax_' . $inc_or_ex_1};
     $order_slip->shipping_cost_amount = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
     if ((double) $amount && !$amount_choosen) {
         $order_slip->order_slip_type = 1;
     }
     if ((double) $amount && $amount_choosen || $order_slip->shipping_cost_amount > 0) {
         $order_slip->order_slip_type = 2;
     }
     if (!$order_slip->add()) {
         return false;
     }
     $res = true;
     foreach ($product_list as $product) {
         $res &= $order_slip->addProductOrderSlip($product);
     }
     return $res;
 }
示例#5
0
 /**
  * @return the total taxes rate applied to the product
  */
 public function getTaxesRate(Address $address = null)
 {
     if (!$address || !$address->id_country) {
         $address = Address::initialize();
     }
     $tax_manager = TaxManagerFactory::getManager($address, $this->id_tax_rules_group);
     $tax_calculator = $tax_manager->getTaxCalculator();
     return $tax_calculator->getTotalRate();
 }
示例#6
0
 /**
  * Returns the product tax
  *
  * @param integer $id_product
  * @param integer $id_country
  * @return Tax
  */
 public static function getProductTaxRate($id_product, $id_address = null, Context $context = null)
 {
     if ($context == null) {
         $context = Context::getContext();
     }
     $address = Address::initialize($id_address);
     $id_tax_rules = (int) Product::getIdTaxRulesGroupByIdProduct($id_product, $context);
     $tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules);
     $tax_calculator = $tax_manager->getTaxCalculator();
     return $tax_calculator->getTotalRate();
 }
示例#7
0
 /**
  * Return package shipping cost
  *
  * @param integer $id_carrier Carrier ID (default : current carrier)
  * @param booleal $use_tax
  * @param Country $default_country
  * @param Array $product_list
  * @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
  *
  * @return float Shipping total
  */
 public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null)
 {
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = Context::getContext()->country;
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
         $address_id = (int) $this->id_address_invoice;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod['id_address_delivery'];
     } else {
         $address_id = null;
     }
     if (!Address::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
         }
     }
     if (Cache::isStored($cache_id)) {
         return Cache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if (!count($products)) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get id zone
     if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
         $id_zone = Address::getZoneById((int) $this->id_address_delivery);
     } else {
         if (!Validate::isLoadedObject($default_country)) {
             $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
         }
         $id_zone = (int) $default_country->id_zone;
     }
     if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
                 $total_order = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
                 $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $id_carrier = (int) $row['id_carrier'];
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('Fatal error: "no default carrier"'));
     }
     if (!$carrier->active) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         Cache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !Tax::excludeTaxeOption()) {
         $address = Address::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
     if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         // Get id zone
         if (isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             $id_zone = (int) $default_country->id_zone;
         }
         $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->getTotalWeight(), (int) $id_zone);
         // Code Review V&V TO FINISH
         $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list), $id_zone, (int) $this->id_currency);
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) {
         $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING'];
     }
     // Additional Shipping Cost per product
     foreach ($products as $product) {
         if (!$product['is_virtual']) {
             $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
         }
     }
     $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $module_name = $carrier->external_module_name;
         $module = Module::getInstanceByName($module_name);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $carrier->id;
             }
             if ($carrier->need_range) {
                 if (method_exists($module, 'getPackageShippingCost')) {
                     $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products);
                 } else {
                     $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
                 }
             } else {
                 $shipping_cost = $module->getOrderShippingCostExternal($this);
             }
             // Check if carrier is available
             if ($shipping_cost === false) {
                 Cache::store($cache_id, false);
                 return false;
             }
         } else {
             Cache::store($cache_id, false);
             return false;
         }
     }
     // Apply tax
     if ($use_tax && isset($carrier_tax)) {
         $shipping_cost *= 1 + $carrier_tax / 100;
     }
     // ###############################################################
     $num = $this->getTotalWeight($product_list);
     $countryAndState = Address::getCountryAndState((int) $this->id_address_delivery);
     $state = $countryAndState['id_state'];
     $pri = false;
     if ($pri) {
         echo "carrierid =>" . $id_carrier . "-";
         echo 'products => ' . $num . '-';
         echo 'state => ' . $state . '-';
     }
     //Ground
     //if( $id_carrier == 21 ){
     if ($id_carrier == 31) {
         //NO CA
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 19.75;
             } elseif ($num == 2) {
                 $shipping_cost = 20.5;
             } elseif ($num == 3) {
                 $shipping_cost = 22.0;
             } elseif ($num == 4) {
                 $shipping_cost = 24.5;
             } elseif ($num == 5) {
                 $shipping_cost = 25.75;
             } elseif ($num == 6) {
                 $shipping_cost = 27.0;
             } elseif ($num == 7) {
                 $shipping_cost = 30.5;
             } elseif ($num == 8) {
                 $shipping_cost = 31.5;
             } elseif ($num == 9) {
                 $shipping_cost = 32.25;
             } elseif ($num == 10) {
                 $shipping_cost = 33.5;
             } elseif ($num == 11) {
                 $shipping_cost = 34.25;
             } else {
                 $shipping_cost = 34.5;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 19.75;
             } elseif ($num == 2) {
                 $shipping_cost = 20.5;
             } elseif ($num == 3) {
                 $shipping_cost = 22.25;
             } elseif ($num == 4) {
                 $shipping_cost = 25.25;
             } elseif ($num == 5) {
                 $shipping_cost = 26.5;
             } elseif ($num == 6) {
                 $shipping_cost = 28.0;
             } elseif ($num == 7) {
                 $shipping_cost = 32.5;
             } elseif ($num == 8) {
                 $shipping_cost = 33.25;
             } elseif ($num == 9) {
                 $shipping_cost = 34.5;
             } elseif ($num == 10) {
                 $shipping_cost = 35.25;
             } elseif ($num == 11) {
                 $shipping_cost = 36.75;
             } else {
                 $shipping_cost = 38.0;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 22.75;
             } elseif ($num == 2) {
                 $shipping_cost = 23.75;
             } elseif ($num == 3) {
                 $shipping_cost = 25.0;
             } elseif ($num == 4) {
                 $shipping_cost = 25.75;
             } elseif ($num == 5) {
                 $shipping_cost = 27.5;
             } elseif ($num == 6) {
                 $shipping_cost = 28.25;
             } elseif ($num == 7) {
                 $shipping_cost = 33.25;
             } elseif ($num == 8) {
                 $shipping_cost = 34.5;
             } elseif ($num == 9) {
                 $shipping_cost = 35.5;
             } elseif ($num == 10) {
                 $shipping_cost = 36.75;
             } elseif ($num == 11) {
                 $shipping_cost = 38.0;
             } else {
                 $shipping_cost = 39.5;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 23.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.5;
             } elseif ($num == 3) {
                 $shipping_cost = 25.75;
             } elseif ($num == 4) {
                 $shipping_cost = 26.5;
             } elseif ($num == 5) {
                 $shipping_cost = 28.0;
             } elseif ($num == 6) {
                 $shipping_cost = 29.5;
             } elseif ($num == 7) {
                 $shipping_cost = 34.75;
             } elseif ($num == 8) {
                 $shipping_cost = 36.75;
             } elseif ($num == 9) {
                 $shipping_cost = 38.25;
             } elseif ($num == 10) {
                 $shipping_cost = 39.5;
             } elseif ($num == 11) {
                 $shipping_cost = 41.25;
             } else {
                 $shipping_cost = 42.5;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.75;
             } elseif ($num == 3) {
                 $shipping_cost = 26.25;
             } elseif ($num == 4) {
                 $shipping_cost = 27.75;
             } elseif ($num == 5) {
                 $shipping_cost = 30.25;
             } elseif ($num == 6) {
                 $shipping_cost = 33.25;
             } elseif ($num == 7) {
                 $shipping_cost = 38.5;
             } elseif ($num == 8) {
                 $shipping_cost = 41.25;
             } elseif ($num == 9) {
                 $shipping_cost = 44.0;
             } elseif ($num == 10) {
                 $shipping_cost = 45.75;
             } elseif ($num == 11) {
                 $shipping_cost = 47.75;
             } else {
                 $shipping_cost = 49.5;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 25.25;
             } elseif ($num == 3) {
                 $shipping_cost = 27.5;
             } elseif ($num == 4) {
                 $shipping_cost = 29.75;
             } elseif ($num == 5) {
                 $shipping_cost = 32.75;
             } elseif ($num == 6) {
                 $shipping_cost = 36.25;
             } elseif ($num == 7) {
                 $shipping_cost = 42.25;
             } elseif ($num == 8) {
                 $shipping_cost = 44.75;
             } elseif ($num == 9) {
                 $shipping_cost = 47.0;
             } elseif ($num == 10) {
                 $shipping_cost = 49.75;
             } elseif ($num == 11) {
                 $shipping_cost = 52.0;
             } else {
                 $shipping_cost = 54.0;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = 46.0;
             } elseif ($num == 2) {
                 $shipping_cost = 56.25;
             } elseif ($num == 3) {
                 $shipping_cost = 64.75;
             } elseif ($num == 4) {
                 $shipping_cost = 74.0;
             } elseif ($num == 5) {
                 $shipping_cost = 77.25;
             } elseif ($num == 6) {
                 $shipping_cost = 85.0;
             } elseif ($num == 7) {
                 $shipping_cost = 91.5;
             } elseif ($num == 8) {
                 $shipping_cost = 98.0;
             } elseif ($num == 9) {
                 $shipping_cost = 105.25;
             } elseif ($num == 10) {
                 $shipping_cost = 111.5;
             } elseif ($num == 11) {
                 $shipping_cost = 117.5;
             } else {
                 $shipping_cost = 124.25;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 24.75;
             } elseif ($num == 2) {
                 $shipping_cost = 26.25;
             } elseif ($num == 3) {
                 $shipping_cost = 28.75;
             } elseif ($num == 4) {
                 $shipping_cost = 30.25;
             } elseif ($num == 5) {
                 $shipping_cost = 35.0;
             } elseif ($num == 6) {
                 $shipping_cost = 39.0;
             } elseif ($num == 7) {
                 $shipping_cost = 45.5;
             } elseif ($num == 8) {
                 $shipping_cost = 48.75;
             } elseif ($num == 9) {
                 $shipping_cost = 51.75;
             } elseif ($num == 10) {
                 $shipping_cost = 54.75;
             } elseif ($num == 11) {
                 $shipping_cost = 58.0;
             } else {
                 $shipping_cost = 60.5;
             }
         }
     } elseif ($id_carrier == 30) {
         //NO CA - 302
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.75;
             } elseif ($num == 3) {
                 $shipping_cost = 25.25;
             } elseif ($num == 4) {
                 $shipping_cost = 26.25;
             } elseif ($num == 5) {
                 $shipping_cost = 27.75;
             } elseif ($num == 6) {
                 $shipping_cost = 29.75;
             } elseif ($num == 7) {
                 $shipping_cost = 32.25;
             } elseif ($num == 8) {
                 $shipping_cost = 34.5;
             } elseif ($num == 9) {
                 $shipping_cost = 36.25;
             } elseif ($num == 10) {
                 $shipping_cost = 38.0;
             } elseif ($num == 11) {
                 $shipping_cost = 40.0;
             } else {
                 $shipping_cost = 42.0;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.75;
             } elseif ($num == 3) {
                 $shipping_cost = 25.75;
             } elseif ($num == 4) {
                 $shipping_cost = 27.75;
             } elseif ($num == 5) {
                 $shipping_cost = 30.25;
             } elseif ($num == 6) {
                 $shipping_cost = 33.5;
             } elseif ($num == 7) {
                 $shipping_cost = 38.0;
             } elseif ($num == 8) {
                 $shipping_cost = 38.5;
             } elseif ($num == 9) {
                 $shipping_cost = 40.0;
             } elseif ($num == 10) {
                 $shipping_cost = 41.75;
             } elseif ($num == 11) {
                 $shipping_cost = 45.5;
             } else {
                 $shipping_cost = 47.75;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 24.75;
             } elseif ($num == 2) {
                 $shipping_cost = 25.75;
             } elseif ($num == 3) {
                 $shipping_cost = 27.0;
             } elseif ($num == 4) {
                 $shipping_cost = 30.5;
             } elseif ($num == 5) {
                 $shipping_cost = 34.0;
             } elseif ($num == 6) {
                 $shipping_cost = 36.75;
             } elseif ($num == 7) {
                 $shipping_cost = 40.25;
             } elseif ($num == 8) {
                 $shipping_cost = 42.25;
             } elseif ($num == 9) {
                 $shipping_cost = 45.25;
             } elseif ($num == 10) {
                 $shipping_cost = 47.75;
             } elseif ($num == 11) {
                 $shipping_cost = 50.75;
             } else {
                 $shipping_cost = 53.5;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 24.75;
             } elseif ($num == 2) {
                 $shipping_cost = 27.75;
             } elseif ($num == 3) {
                 $shipping_cost = 29.5;
             } elseif ($num == 4) {
                 $shipping_cost = 33.5;
             } elseif ($num == 5) {
                 $shipping_cost = 38.0;
             } elseif ($num == 6) {
                 $shipping_cost = 40.75;
             } elseif ($num == 7) {
                 $shipping_cost = 45.25;
             } elseif ($num == 8) {
                 $shipping_cost = 48.0;
             } elseif ($num == 9) {
                 $shipping_cost = 52.25;
             } elseif ($num == 10) {
                 $shipping_cost = 54.25;
             } elseif ($num == 11) {
                 $shipping_cost = 57.25;
             } else {
                 $shipping_cost = 62.25;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 25.5;
             } elseif ($num == 2) {
                 $shipping_cost = 30.5;
             } elseif ($num == 3) {
                 $shipping_cost = 36.0;
             } elseif ($num == 4) {
                 $shipping_cost = 40.25;
             } elseif ($num == 5) {
                 $shipping_cost = 47.75;
             } elseif ($num == 6) {
                 $shipping_cost = 51.25;
             } elseif ($num == 7) {
                 $shipping_cost = 56.25;
             } elseif ($num == 8) {
                 $shipping_cost = 60.25;
             } elseif ($num == 9) {
                 $shipping_cost = 65.0;
             } elseif ($num == 10) {
                 $shipping_cost = 69.5;
             } elseif ($num == 11) {
                 $shipping_cost = 74.25;
             } else {
                 $shipping_cost = 78.5;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 31.5;
             } elseif ($num == 2) {
                 $shipping_cost = 33.25;
             } elseif ($num == 3) {
                 $shipping_cost = 38.5;
             } elseif ($num == 4) {
                 $shipping_cost = 43.75;
             } elseif ($num == 5) {
                 $shipping_cost = 49.5;
             } elseif ($num == 6) {
                 $shipping_cost = 54.75;
             } elseif ($num == 7) {
                 $shipping_cost = 62.25;
             } elseif ($num == 8) {
                 $shipping_cost = 67.0;
             } elseif ($num == 9) {
                 $shipping_cost = 72.0;
             } elseif ($num == 10) {
                 $shipping_cost = 77.25;
             } elseif ($num == 11) {
                 $shipping_cost = 81.5;
             } else {
                 $shipping_cost = 86.5;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = -1;
             } elseif ($num == 2) {
                 $shipping_cost = -1;
             } elseif ($num == 3) {
                 $shipping_cost = -1;
             } elseif ($num == 4) {
                 $shipping_cost = -1;
             } elseif ($num == 5) {
                 $shipping_cost = -1;
             } elseif ($num == 6) {
                 $shipping_cost = -1;
             } elseif ($num == 7) {
                 $shipping_cost = -1;
             } elseif ($num == 8) {
                 $shipping_cost = -1;
             } elseif ($num == 9) {
                 $shipping_cost = -1;
             } elseif ($num == 10) {
                 $shipping_cost = -1;
             } elseif ($num == 11) {
                 $shipping_cost = -1;
             } else {
                 $shipping_cost = -1;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 28.25;
             } elseif ($num == 2) {
                 $shipping_cost = 34.25;
             } elseif ($num == 3) {
                 $shipping_cost = 41.0;
             } elseif ($num == 4) {
                 $shipping_cost = 48.25;
             } elseif ($num == 5) {
                 $shipping_cost = 54.0;
             } elseif ($num == 6) {
                 $shipping_cost = 59.0;
             } elseif ($num == 7) {
                 $shipping_cost = 67.0;
             } elseif ($num == 8) {
                 $shipping_cost = 73.75;
             } elseif ($num == 9) {
                 $shipping_cost = 77.5;
             } elseif ($num == 10) {
                 $shipping_cost = 83.25;
             } elseif ($num == 11) {
                 $shipping_cost = 88.5;
             } else {
                 $shipping_cost = 93.0;
             }
         }
     } elseif ($id_carrier == 32) {
         //NO CA - 202
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 23.75;
             } elseif ($num == 2) {
                 $shipping_cost = 23.75;
             } elseif ($num == 3) {
                 $shipping_cost = 26.0;
             } elseif ($num == 4) {
                 $shipping_cost = 27.5;
             } elseif ($num == 5) {
                 $shipping_cost = 29.25;
             } elseif ($num == 6) {
                 $shipping_cost = 30.75;
             } elseif ($num == 7) {
                 $shipping_cost = 34.75;
             } elseif ($num == 8) {
                 $shipping_cost = 37.5;
             } elseif ($num == 9) {
                 $shipping_cost = 40.0;
             } elseif ($num == 10) {
                 $shipping_cost = 40.75;
             } elseif ($num == 11) {
                 $shipping_cost = 43.25;
             } else {
                 $shipping_cost = 45.5;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 23.75;
             } elseif ($num == 2) {
                 $shipping_cost = 24.25;
             } elseif ($num == 3) {
                 $shipping_cost = 28.0;
             } elseif ($num == 4) {
                 $shipping_cost = 29.25;
             } elseif ($num == 5) {
                 $shipping_cost = 31.75;
             } elseif ($num == 6) {
                 $shipping_cost = 34.75;
             } elseif ($num == 7) {
                 $shipping_cost = 38.75;
             } elseif ($num == 8) {
                 $shipping_cost = 41.25;
             } elseif ($num == 9) {
                 $shipping_cost = 43.75;
             } elseif ($num == 10) {
                 $shipping_cost = 46.25;
             } elseif ($num == 11) {
                 $shipping_cost = 48.25;
             } else {
                 $shipping_cost = 50.5;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 23.75;
             } elseif ($num == 2) {
                 $shipping_cost = 25.5;
             } elseif ($num == 3) {
                 $shipping_cost = 30.75;
             } elseif ($num == 4) {
                 $shipping_cost = 33.0;
             } elseif ($num == 5) {
                 $shipping_cost = 36.25;
             } elseif ($num == 6) {
                 $shipping_cost = 40.5;
             } elseif ($num == 7) {
                 $shipping_cost = 44.75;
             } elseif ($num == 8) {
                 $shipping_cost = 46.5;
             } elseif ($num == 9) {
                 $shipping_cost = 50.25;
             } elseif ($num == 10) {
                 $shipping_cost = 52.5;
             } elseif ($num == 11) {
                 $shipping_cost = 55.25;
             } else {
                 $shipping_cost = 59.0;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 27.25;
             } elseif ($num == 2) {
                 $shipping_cost = 30.75;
             } elseif ($num == 3) {
                 $shipping_cost = 36.0;
             } elseif ($num == 4) {
                 $shipping_cost = 41.0;
             } elseif ($num == 5) {
                 $shipping_cost = 46.0;
             } elseif ($num == 6) {
                 $shipping_cost = 50.5;
             } elseif ($num == 7) {
                 $shipping_cost = 57.25;
             } elseif ($num == 8) {
                 $shipping_cost = 61.75;
             } elseif ($num == 9) {
                 $shipping_cost = 65.0;
             } elseif ($num == 10) {
                 $shipping_cost = 68.75;
             } elseif ($num == 11) {
                 $shipping_cost = 72.25;
             } else {
                 $shipping_cost = 76.75;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 29.25;
             } elseif ($num == 2) {
                 $shipping_cost = 38.75;
             } elseif ($num == 3) {
                 $shipping_cost = 46.5;
             } elseif ($num == 4) {
                 $shipping_cost = 54.75;
             } elseif ($num == 5) {
                 $shipping_cost = 62.75;
             } elseif ($num == 6) {
                 $shipping_cost = 69.75;
             } elseif ($num == 7) {
                 $shipping_cost = 77.75;
             } elseif ($num == 8) {
                 $shipping_cost = 84.25;
             } elseif ($num == 9) {
                 $shipping_cost = 90.75;
             } elseif ($num == 10) {
                 $shipping_cost = 96.75;
             } elseif ($num == 11) {
                 $shipping_cost = 105.0;
             } else {
                 $shipping_cost = 111.25;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 32.0;
             } elseif ($num == 2) {
                 $shipping_cost = 40.25;
             } elseif ($num == 3) {
                 $shipping_cost = 49.75;
             } elseif ($num == 4) {
                 $shipping_cost = 58.0;
             } elseif ($num == 5) {
                 $shipping_cost = 65.5;
             } elseif ($num == 6) {
                 $shipping_cost = 74.25;
             } elseif ($num == 7) {
                 $shipping_cost = 82.5;
             } elseif ($num == 8) {
                 $shipping_cost = 89.5;
             } elseif ($num == 9) {
                 $shipping_cost = 96.5;
             } elseif ($num == 10) {
                 $shipping_cost = 102.5;
             } elseif ($num == 11) {
                 $shipping_cost = 109.25;
             } else {
                 $shipping_cost = 116.75;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = -1;
             } elseif ($num == 2) {
                 $shipping_cost = -1;
             } elseif ($num == 3) {
                 $shipping_cost = -1;
             } elseif ($num == 4) {
                 $shipping_cost = -1;
             } elseif ($num == 5) {
                 $shipping_cost = -1;
             } elseif ($num == 6) {
                 $shipping_cost = -1;
             } elseif ($num == 7) {
                 $shipping_cost = -1;
             } elseif ($num == 8) {
                 $shipping_cost = -1;
             } elseif ($num == 9) {
                 $shipping_cost = -1;
             } elseif ($num == 10) {
                 $shipping_cost = -1;
             } elseif ($num == 11) {
                 $shipping_cost = -1;
             } else {
                 $shipping_cost = -1;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 34.75;
             } elseif ($num == 2) {
                 $shipping_cost = 41.0;
             } elseif ($num == 3) {
                 $shipping_cost = 50.25;
             } elseif ($num == 4) {
                 $shipping_cost = 59.75;
             } elseif ($num == 5) {
                 $shipping_cost = 66.5;
             } elseif ($num == 6) {
                 $shipping_cost = 75.25;
             } elseif ($num == 7) {
                 $shipping_cost = 84.5;
             } elseif ($num == 8) {
                 $shipping_cost = 92.25;
             } elseif ($num == 9) {
                 $shipping_cost = 98.5;
             } elseif ($num == 10) {
                 $shipping_cost = 105.5;
             } elseif ($num == 11) {
                 $shipping_cost = 112.0;
             } else {
                 $shipping_cost = 119.25;
             }
         }
     } elseif ($id_carrier == 29) {
         //NO CA - 102
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 27.25;
             } elseif ($num == 2) {
                 $shipping_cost = 29.0;
             } elseif ($num == 3) {
                 $shipping_cost = 32.75;
             } elseif ($num == 4) {
                 $shipping_cost = 36.25;
             } elseif ($num == 5) {
                 $shipping_cost = 38.75;
             } elseif ($num == 6) {
                 $shipping_cost = 40.75;
             } elseif ($num == 7) {
                 $shipping_cost = 45.25;
             } elseif ($num == 8) {
                 $shipping_cost = 48.25;
             } elseif ($num == 9) {
                 $shipping_cost = 50.5;
             } elseif ($num == 10) {
                 $shipping_cost = 54.75;
             } elseif ($num == 11) {
                 $shipping_cost = 56.25;
             } else {
                 $shipping_cost = 60.5;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 31.75;
             } elseif ($num == 2) {
                 $shipping_cost = 37.5;
             } elseif ($num == 3) {
                 $shipping_cost = 39.5;
             } elseif ($num == 4) {
                 $shipping_cost = 44.25;
             } elseif ($num == 5) {
                 $shipping_cost = 48.0;
             } elseif ($num == 6) {
                 $shipping_cost = 52.75;
             } elseif ($num == 7) {
                 $shipping_cost = 56.75;
             } elseif ($num == 8) {
                 $shipping_cost = 59.5;
             } elseif ($num == 9) {
                 $shipping_cost = 65.0;
             } elseif ($num == 10) {
                 $shipping_cost = 67.5;
             } elseif ($num == 11) {
                 $shipping_cost = 71.25;
             } else {
                 $shipping_cost = 76.5;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 38.75;
             } elseif ($num == 2) {
                 $shipping_cost = 47.75;
             } elseif ($num == 3) {
                 $shipping_cost = 57.75;
             } elseif ($num == 4) {
                 $shipping_cost = 64.0;
             } elseif ($num == 5) {
                 $shipping_cost = 71.25;
             } elseif ($num == 6) {
                 $shipping_cost = 80.75;
             } elseif ($num == 7) {
                 $shipping_cost = 85.75;
             } elseif ($num == 8) {
                 $shipping_cost = 92.5;
             } elseif ($num == 9) {
                 $shipping_cost = 100.75;
             } elseif ($num == 10) {
                 $shipping_cost = 105.25;
             } elseif ($num == 11) {
                 $shipping_cost = 111.5;
             } else {
                 $shipping_cost = 117.75;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 41.25;
             } elseif ($num == 2) {
                 $shipping_cost = 50.75;
             } elseif ($num == 3) {
                 $shipping_cost = 61.75;
             } elseif ($num == 4) {
                 $shipping_cost = 70.75;
             } elseif ($num == 5) {
                 $shipping_cost = 78.75;
             } elseif ($num == 6) {
                 $shipping_cost = 86.75;
             } elseif ($num == 7) {
                 $shipping_cost = 91.5;
             } elseif ($num == 8) {
                 $shipping_cost = 99.0;
             } elseif ($num == 9) {
                 $shipping_cost = 105.5;
             } elseif ($num == 10) {
                 $shipping_cost = 113.0;
             } elseif ($num == 11) {
                 $shipping_cost = 119.75;
             } else {
                 $shipping_cost = 126.5;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 46.75;
             } elseif ($num == 2) {
                 $shipping_cost = 53.75;
             } elseif ($num == 3) {
                 $shipping_cost = 67.25;
             } elseif ($num == 4) {
                 $shipping_cost = 77.0;
             } elseif ($num == 5) {
                 $shipping_cost = 83.75;
             } elseif ($num == 6) {
                 $shipping_cost = 93.0;
             } elseif ($num == 7) {
                 $shipping_cost = 100.25;
             } elseif ($num == 8) {
                 $shipping_cost = 103.0;
             } elseif ($num == 9) {
                 $shipping_cost = 112.25;
             } elseif ($num == 10) {
                 $shipping_cost = 120.5;
             } elseif ($num == 11) {
                 $shipping_cost = 126.25;
             } else {
                 $shipping_cost = 132.0;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 49.25;
             } elseif ($num == 2) {
                 $shipping_cost = 56.25;
             } elseif ($num == 3) {
                 $shipping_cost = 69.0;
             } elseif ($num == 4) {
                 $shipping_cost = 79.25;
             } elseif ($num == 5) {
                 $shipping_cost = 88.25;
             } elseif ($num == 6) {
                 $shipping_cost = 95.75;
             } elseif ($num == 7) {
                 $shipping_cost = 101.5;
             } elseif ($num == 8) {
                 $shipping_cost = 109.25;
             } elseif ($num == 9) {
                 $shipping_cost = 116.0;
             } elseif ($num == 10) {
                 $shipping_cost = 123.25;
             } elseif ($num == 11) {
                 $shipping_cost = 130.0;
             } else {
                 $shipping_cost = 138.75;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = 53.75;
             } elseif ($num == 2) {
                 $shipping_cost = 67.5;
             } elseif ($num == 3) {
                 $shipping_cost = 78.75;
             } elseif ($num == 4) {
                 $shipping_cost = 85.5;
             } elseif ($num == 5) {
                 $shipping_cost = 96.75;
             } elseif ($num == 6) {
                 $shipping_cost = 101.5;
             } elseif ($num == 7) {
                 $shipping_cost = 116.25;
             } elseif ($num == 8) {
                 $shipping_cost = 130.0;
             } elseif ($num == 9) {
                 $shipping_cost = 142.5;
             } elseif ($num == 10) {
                 $shipping_cost = 152.5;
             } elseif ($num == 11) {
                 $shipping_cost = 159.75;
             } else {
                 $shipping_cost = 168.25;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 50.75;
             } elseif ($num == 2) {
                 $shipping_cost = 60.5;
             } elseif ($num == 3) {
                 $shipping_cost = 70.5;
             } elseif ($num == 4) {
                 $shipping_cost = 81.0;
             } elseif ($num == 5) {
                 $shipping_cost = 90.25;
             } elseif ($num == 6) {
                 $shipping_cost = 98.5;
             } elseif ($num == 7) {
                 $shipping_cost = 104.5;
             } elseif ($num == 8) {
                 $shipping_cost = 113.0;
             } elseif ($num == 9) {
                 $shipping_cost = 119.25;
             } elseif ($num == 10) {
                 $shipping_cost = 127.0;
             } elseif ($num == 11) {
                 $shipping_cost = 133.75;
             } else {
                 $shipping_cost = 139.75;
             }
         }
     } elseif ($id_carrier == 16) {
         //NO CA
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 11.0;
             } elseif ($num == 2) {
                 $shipping_cost = 12.0;
             } elseif ($num == 3) {
                 $shipping_cost = 12.75;
             } elseif ($num == 4) {
                 $shipping_cost = 14.75;
             } elseif ($num == 5) {
                 $shipping_cost = 15.75;
             } elseif ($num == 6) {
                 $shipping_cost = 16.0;
             } elseif ($num == 7) {
                 $shipping_cost = 19.0;
             } elseif ($num == 8) {
                 $shipping_cost = 19.25;
             } elseif ($num == 9) {
                 $shipping_cost = 20.0;
             } elseif ($num == 10) {
                 $shipping_cost = 20.75;
             } elseif ($num == 11) {
                 $shipping_cost = 22.0;
             } else {
                 $shipping_cost = 22.25;
             }
         } elseif ($state == 314) {
             if ($num == 1) {
                 $shipping_cost = 11.75;
             } elseif ($num == 2) {
                 $shipping_cost = 12.5;
             } elseif ($num == 3) {
                 $shipping_cost = 13.75;
             } elseif ($num == 4) {
                 $shipping_cost = 14.75;
             } elseif ($num == 5) {
                 $shipping_cost = 16.0;
             } elseif ($num == 6) {
                 $shipping_cost = 16.75;
             } elseif ($num == 7) {
                 $shipping_cost = 20.0;
             } elseif ($num == 8) {
                 $shipping_cost = 20.75;
             } elseif ($num == 9) {
                 $shipping_cost = 22.0;
             } elseif ($num == 10) {
                 $shipping_cost = 22.75;
             } elseif ($num == 11) {
                 $shipping_cost = 24.0;
             } else {
                 $shipping_cost = 24.0;
             }
         } elseif ($state == 315) {
             if ($num == 1) {
                 $shipping_cost = 12.25;
             } elseif ($num == 2) {
                 $shipping_cost = 13.75;
             } elseif ($num == 3) {
                 $shipping_cost = 14.5;
             } elseif ($num == 4) {
                 $shipping_cost = 15.75;
             } elseif ($num == 5) {
                 $shipping_cost = 16.5;
             } elseif ($num == 6) {
                 $shipping_cost = 17.0;
             } elseif ($num == 7) {
                 $shipping_cost = 20.5;
             } elseif ($num == 8) {
                 $shipping_cost = 22.0;
             } elseif ($num == 9) {
                 $shipping_cost = 22.75;
             } elseif ($num == 10) {
                 $shipping_cost = 24.0;
             } elseif ($num == 11) {
                 $shipping_cost = 25.25;
             } else {
                 $shipping_cost = 26.0;
             }
         } elseif ($state == 3 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 12.25;
             } elseif ($num == 2) {
                 $shipping_cost = 14.0;
             } elseif ($num == 3) {
                 $shipping_cost = 14.75;
             } elseif ($num == 4) {
                 $shipping_cost = 16.25;
             } elseif ($num == 5) {
                 $shipping_cost = 17.75;
             } elseif ($num == 6) {
                 $shipping_cost = 18.75;
             } elseif ($num == 7) {
                 $shipping_cost = 22.5;
             } elseif ($num == 8) {
                 $shipping_cost = 24.0;
             } elseif ($num == 9) {
                 $shipping_cost = 25.25;
             } elseif ($num == 10) {
                 $shipping_cost = 26.75;
             } elseif ($num == 11) {
                 $shipping_cost = 28.25;
             } else {
                 $shipping_cost = 29.0;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = -1;
             } elseif ($num == 2) {
                 $shipping_cost = -1;
             } elseif ($num == 3) {
                 $shipping_cost = -1;
             } elseif ($num == 4) {
                 $shipping_cost = -1;
             } elseif ($num == 5) {
                 $shipping_cost = -1;
             } elseif ($num == 6) {
                 $shipping_cost = -1;
             } elseif ($num == 7) {
                 $shipping_cost = -1;
             } elseif ($num == 8) {
                 $shipping_cost = -1;
             } elseif ($num == 9) {
                 $shipping_cost = -1;
             } elseif ($num == 10) {
                 $shipping_cost = -1;
             } elseif ($num == 11) {
                 $shipping_cost = -1;
             } else {
                 $shipping_cost = -1;
             }
         }
     }
     //###############################################################
     $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2);
     Cache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
 protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
 {
     $lpdesmvcrvu = "specific_price_priorities";
     ${"GLOBALS"}["gwvlvnhgf"] = "group";
     $plkmtiqjex = "specific_price_priorities";
     ${"GLOBALS"}["ertbhqqwavl"] = "tmp";
     ${"GLOBALS"}["glybiybrjmv"] = "group";
     ${"GLOBALS"}["nihfjn"] = "tmp";
     $ivhgohevles = "taxRate";
     ${${"GLOBALS"}["nkvjzc"]} = "";
     ${"GLOBALS"}["ukanssy"] = "currencies";
     if (!$this->object) {
         return;
     }
     ${"GLOBALS"}["tfufwuqnbgxc"] = "tmp";
     ${${"GLOBALS"}["ixsaqwcye"]} = SpecificPrice::getByProductId((int) $this->object->id);
     $rarsexno = "shop";
     $vrcmtksat = "shop";
     $gedaion = "specific_price_priorities";
     ${"GLOBALS"}["xsrbwsm"] = "shops";
     ${$lpdesmvcrvu} = SpecificPrice::getPriority((int) $this->object->id);
     ${$ivhgohevles} = $this->object->getTaxesRate(Address::initialize());
     $uhzkmfbqi = "shop";
     $ahuedic = "specific_price_priorities";
     ${${"GLOBALS"}["bdtyklee"]} = array();
     foreach (${${"GLOBALS"}["xsrbwsm"]} as ${$uhzkmfbqi}) {
         ${${"GLOBALS"}["bdtyklee"]}[${$rarsexno}["id_shop"]] = ${$vrcmtksat};
     }
     $rbdspr = "currencies";
     ${"GLOBALS"}["ruiubiwy"] = "countries";
     $nyuyhmkcene = "content";
     ${${"GLOBALS"}["lazfnitt"]} = ${${"GLOBALS"}["bdtyklee"]};
     $hcdvvpbef = "tmp";
     $wdrtujtw = "currency";
     ${${"GLOBALS"}["nihfjn"]} = array();
     foreach (${$rbdspr} as ${${"GLOBALS"}["qwffcfylwvlg"]}) {
         ${${"GLOBALS"}["bdtyklee"]}[${$wdrtujtw}["id_currency"]] = ${${"GLOBALS"}["qwffcfylwvlg"]};
     }
     ${${"GLOBALS"}["ukanssy"]} = ${${"GLOBALS"}["ertbhqqwavl"]};
     ${${"GLOBALS"}["tfufwuqnbgxc"]} = array();
     foreach (${${"GLOBALS"}["ruiubiwy"]} as ${${"GLOBALS"}["dtehljxk"]}) {
         ${${"GLOBALS"}["bdtyklee"]}[${${"GLOBALS"}["dtehljxk"]}["id_country"]] = ${${"GLOBALS"}["dtehljxk"]};
     }
     $tclsxk = "specific_price_priorities";
     ${${"GLOBALS"}["kroabu"]} = ${${"GLOBALS"}["bdtyklee"]};
     ${$hcdvvpbef} = array();
     foreach (${${"GLOBALS"}["myyouyoez"]} as ${${"GLOBALS"}["gwvlvnhgf"]}) {
         ${${"GLOBALS"}["bdtyklee"]}[${${"GLOBALS"}["oxbcew"]}["id_group"]] = ${${"GLOBALS"}["glybiybrjmv"]};
     }
     ${"GLOBALS"}["cptxpwqsgzo"] = "content";
     ${${"GLOBALS"}["myyouyoez"]} = ${${"GLOBALS"}["bdtyklee"]};
     if (!is_array(${${"GLOBALS"}["ixsaqwcye"]}) || !count(${${"GLOBALS"}["ixsaqwcye"]})) {
         ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=\"13\">" . $this->l('No specific prices') . "</td>\n\t\t\t\t</tr>";
     } else {
         ${"GLOBALS"}["ixvreqo"] = "specific_prices";
         ${${"GLOBALS"}["eqiehjn"]} = 0;
         ${"GLOBALS"}["xwjpok"] = "specific_price";
         foreach (${${"GLOBALS"}["ixvreqo"]} as ${${"GLOBALS"}["xwjpok"]}) {
             ${"GLOBALS"}["jgkoendjlpt"] = "specific_price";
             $sdpwvfzmwy = "current_specific_currency";
             ${"GLOBALS"}["drapxqkxjfw"] = "customer_full_name";
             ${"GLOBALS"}["wrefbrz"] = "specific_price";
             $ywnqxjizw = "impact";
             $pmhlqxsivhg = "currencies";
             ${"GLOBALS"}["lnqbpvxxuw"] = "i";
             $qndkwpcllv = "specific_price";
             ${"GLOBALS"}["cfbvjzjfz"] = "specific_price";
             ${"GLOBALS"}["hyijedlreo"] = "specific_price";
             ${"GLOBALS"}["bdnvmedpllw"] = "customer_full_name";
             ${"GLOBALS"}["yonxxgguvyc"] = "shops";
             ${"GLOBALS"}["brpkiqjctz"] = "specific_price";
             ${"GLOBALS"}["cubiilo"] = "customer_full_name";
             $msgvsejfwpg = "specific_price";
             ${"GLOBALS"}["ihxryxdypi"] = "groups";
             $frcvwum = "rule";
             $fpsxqukp = "price";
             ${"GLOBALS"}["ucfgiwdbfvge"] = "period";
             ${"GLOBALS"}["pjigladsg"] = "fixed_price";
             ${"GLOBALS"}["qrcsyna"] = "specific_price";
             $nwumqlplzzwc = "specific_price";
             $tihycjulltff = "impact";
             ${$sdpwvfzmwy} = ${$pmhlqxsivhg}[${${"GLOBALS"}["oudwfbvcvoj"]}["id_currency"] ? ${${"GLOBALS"}["cfbvjzjfz"]}["id_currency"] : $defaultCurrency->id];
             ${"GLOBALS"}["wxttwnsgf"] = "specific_price";
             if (${${"GLOBALS"}["oudwfbvcvoj"]}["reduction_type"] == "percentage") {
                 ${$ywnqxjizw} = "- " . ${${"GLOBALS"}["oudwfbvcvoj"]}["reduction"] * 100 . " %";
             } elseif (${${"GLOBALS"}["oudwfbvcvoj"]}["reduction"] > 0) {
                 ${${"GLOBALS"}["uaxmvunoy"]} = "- " . Tools::displayPrice(Tools::ps_round(${$nwumqlplzzwc}["reduction"], 2), ${${"GLOBALS"}["lbhedgts"]});
             } else {
                 ${$tihycjulltff} = "--";
             }
             ${"GLOBALS"}["nwsoorkiv"] = "impact";
             if (${${"GLOBALS"}["jgkoendjlpt"]}["from"] == "0000-00-00 00:00:00" && ${${"GLOBALS"}["oudwfbvcvoj"]}["to"] == "0000-00-00 00:00:00") {
                 ${${"GLOBALS"}["zcpltzs"]} = $this->l('Unlimited');
             } else {
                 ${${"GLOBALS"}["zcpltzs"]} = $this->l('From') . " " . (${${"GLOBALS"}["wxttwnsgf"]}["from"] != "0000-00-00 00:00:00" ? ${${"GLOBALS"}["oudwfbvcvoj"]}["from"] : "0000-00-00 00:00:00") . "<br />" . $this->l('To') . " " . (${${"GLOBALS"}["oudwfbvcvoj"]}["to"] != "0000-00-00 00:00:00" ? ${${"GLOBALS"}["oudwfbvcvoj"]}["to"] : "0000-00-00 00:00:00");
             }
             if (${${"GLOBALS"}["oudwfbvcvoj"]}["id_product_attribute"]) {
                 ${"GLOBALS"}["ysyybwjtlnlr"] = "attributes_name";
                 $supdob = "attributes_name";
                 $nwznli = "attribute";
                 ${"GLOBALS"}["ucovwpfrg"] = "specific_price";
                 $ghrcpselphnv = "combination";
                 $gyrrgbrm = "attributes";
                 ${$ghrcpselphnv} = new Combination((int) ${${"GLOBALS"}["ucovwpfrg"]}["id_product_attribute"]);
                 ${$gyrrgbrm} = $combination->getAttributesName((int) $this->context->language->id);
                 ${${"GLOBALS"}["ysyybwjtlnlr"]} = "";
                 foreach (${${"GLOBALS"}["tecppiwmy"]} as ${${"GLOBALS"}["nmduzbby"]}) {
                     ${${"GLOBALS"}["dkpnrhqmdel"]} .= ${$nwznli}["name"] . " - ";
                 }
                 ${$supdob} = rtrim(${${"GLOBALS"}["dkpnrhqmdel"]}, " - ");
             } else {
                 ${${"GLOBALS"}["dkpnrhqmdel"]} = $this->l('All combinations');
             }
             $seqiqveynpjq = "specific_price";
             ${$frcvwum} = new SpecificPriceRule((int) ${${"GLOBALS"}["oudwfbvcvoj"]}["id_specific_price_rule"]);
             ${${"GLOBALS"}["qwfludjdg"]} = $rule->id ? $rule->name : "--";
             if (${${"GLOBALS"}["oudwfbvcvoj"]}["id_customer"]) {
                 ${"GLOBALS"}["oyqwsagds"] = "customer";
                 $zdwishb = "customer";
                 ${${"GLOBALS"}["mcehpjcdvu"]} = new Customer((int) ${${"GLOBALS"}["oudwfbvcvoj"]}["id_customer"]);
                 if (Validate::isLoadedObject(${$zdwishb})) {
                     ${${"GLOBALS"}["valsyupb"]} = $customer->firstname . " " . $customer->lastname;
                 }
                 unset(${${"GLOBALS"}["oyqwsagds"]});
             }
             ${${"GLOBALS"}["judupfn"]} = Tools::ps_round(${$qndkwpcllv}["price"], 2);
             ${${"GLOBALS"}["pjigladsg"]} = ${${"GLOBALS"}["judupfn"]} == Tools::ps_round($this->object->price, 2) || ${${"GLOBALS"}["oudwfbvcvoj"]}["price"] == -1 ? "--" : Tools::displayPrice(${$fpsxqukp});
             ${"GLOBALS"}["rtvaytzbs"] = "specific_price";
             ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t<tr " . (${${"GLOBALS"}["eqiehjn"]} % 2 ? "class=\"alt_row\"" : "") . ">\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["qwfludjdg"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["dkpnrhqmdel"]} . "</td>\n\t\t\t\t\t" . (Shop::isFeatureActive() ? "<td class=\"cell border\">" . (${${"GLOBALS"}["rtvaytzbs"]}["id_shop"] ? ${${"GLOBALS"}["yonxxgguvyc"]}[${$msgvsejfwpg}["id_shop"]]["name"] : $this->l('All shops')) . "</td>" : "") . "\n\t\t\t\t\t<td class=\"cell border\">" . (${${"GLOBALS"}["oudwfbvcvoj"]}["id_currency"] ? ${${"GLOBALS"}["qeyondtkko"]}[${$seqiqveynpjq}["id_currency"]]["name"] : $this->l('All currencies')) . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . (${${"GLOBALS"}["oudwfbvcvoj"]}["id_country"] ? ${${"GLOBALS"}["kroabu"]}[${${"GLOBALS"}["wrefbrz"]}["id_country"]]["name"] : $this->l('All countries')) . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . (${${"GLOBALS"}["brpkiqjctz"]}["id_group"] ? ${${"GLOBALS"}["ihxryxdypi"]}[${${"GLOBALS"}["oudwfbvcvoj"]}["id_group"]]["name"] : $this->l('All groups')) . "</td>\n\t\t\t\t\t<td class=\"cell border\" title=\"" . $this->l('ID:') . " " . ${${"GLOBALS"}["oudwfbvcvoj"]}["id_customer"] . "\">" . (isset(${${"GLOBALS"}["cubiilo"]}) ? ${${"GLOBALS"}["bdnvmedpllw"]} : $this->l('All customers')) . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["ojfggiuyn"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["nwsoorkiv"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["ucfgiwdbfvge"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["hyijedlreo"]}["from_quantity"] . "</th>\n\t\t\t\t\t<td class=\"cell border\">" . (!$rule->id ? "<a name=\"delete_link\" href=\"" . __PS_BASE_URI__ . "modules/agilemultipleseller/ajax_products.php?action=DeleteSpecificPrice&id_product=" . $this->id_object . "&id_specific_price=" . (int) ${${"GLOBALS"}["qrcsyna"]}["id_specific_price"] . "\"><img src=\"" . __PS_BASE_URI__ . "img/admin/delete.gif\" alt=\"" . $this->l('Delete') . "\" /></a>" : "") . "</td>\n\t\t\t\t</tr>";
             ${${"GLOBALS"}["lnqbpvxxuw"]}++;
             unset(${${"GLOBALS"}["drapxqkxjfw"]});
         }
     }
     $dvylzfofp = "currency";
     ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t</tbody>\n\t\t\t</table>\n\t\t</div>";
     ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t<script type=\"text/javascript\">\n\t\t\tvar currencies = new Array();\n\t\t\tcurrencies[0] = new Array();\n\t\t\tcurrencies[0][\"sign\"] = \"" . $defaultCurrency->sign . "\";\n\t\t\tcurrencies[0][\"format\"] = " . $defaultCurrency->format . ";\n\t\t\t";
     foreach (${${"GLOBALS"}["qeyondtkko"]} as ${$dvylzfofp}) {
         ${"GLOBALS"}["orynunkni"] = "currency";
         $glvdhrwfpl = "currency";
         $dnugvdxrefxp = "currency";
         $jtxjbwyjntp = "content";
         $gocuffop = "currency";
         ${$jtxjbwyjntp} .= "\n\t\t\t\tcurrencies[" . ${$glvdhrwfpl}["id_currency"] . "] = new Array();\n\t\t\t\tcurrencies[" . ${${"GLOBALS"}["orynunkni"]}["id_currency"] . "][\"sign\"] = \"" . ${${"GLOBALS"}["qwffcfylwvlg"]}["sign"] . "\";\n\t\t\t\tcurrencies[" . ${$dnugvdxrefxp}["id_currency"] . "][\"format\"] = " . ${$gocuffop}["format"] . ";\n\t\t\t\t";
     }
     ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t</script>\n\t\t";
     $djpchkks = "specific_price_priorities";
     ${"GLOBALS"}["bkvknwhmmk"] = "specific_price_priorities";
     $pecvkmoo = "specific_price_priorities";
     ${"GLOBALS"}["csovwwlu"] = "specific_price_priorities";
     if (${$plkmtiqjex}[0] == "id_customer") {
         unset(${$djpchkks}[0]);
     }
     ${${"GLOBALS"}["tupdle"]} = array_values(${${"GLOBALS"}["tupdle"]});
     ${$nyuyhmkcene} .= "<div id=\"agile\"class=\"panel\">\n\t\t<h3>" . $this->l('Priority management') . "</h3>\n\t\t<div class=\"alert alert-info\">\n\t\t\t\t" . $this->l('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . "\n\t\t</div>";
     ${${"GLOBALS"}["cptxpwqsgzo"]} .= "\n\t\t<div class=\"form-group\">\n\t\t\t<label class=\"control-label agile-col-sm-3 agile-col-md-3 agile-col-lg-3 agile-col-xl-3\" for=\"specificPricePriority1\">" . $this->l('Priorities:') . "</label>\n\t\t\t<div class=\"input-group  agile-col-sm-9  agile-col-md9 col-lg-9  agile-col-xl-9\">\n\t\t\t\t<select id=\"specificPricePriority1\" name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${${"GLOBALS"}["tupdle"]}[0] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${$gedaion}[0] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[0] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${${"GLOBALS"}["tupdle"]}[0] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t\t<span class=\"input-group-addon\"><i class=\"icon-chevron-right\"></i></span>\n\t\t\t\t<select name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${$pecvkmoo}[1] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${${"GLOBALS"}["csovwwlu"]}[1] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[1] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${${"GLOBALS"}["tupdle"]}[1] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t\t<span class=\"input-group-addon\"><i class=\"icon-chevron-right\"></i></span>\n\t\t\t\t<select name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t\t<span class=\"input-group-addon\"><i class=\"icon-chevron-right\"></i></span>\n\t\t\t\t<select name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${${"GLOBALS"}["bkvknwhmmk"]}[3] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${$ahuedic}[3] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[3] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${$tclsxk}[3] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"form-group\">\n\t\t\t<div class=\" agile-col-sm-9  agile-sm-offset-3  agile-col-md-9  agile-md-offset-3 col-lg-9 col-lg-offset-3  agile-col-xl-9  agile-xl-ooffset-3\">\n\t\t\t\t<p class=\"checkbox\">\n\t\t\t\t\t<label for=\"specificPricePriorityToAll\"><input type=\"checkbox\" name=\"specificPricePriorityToAll\" id=\"specificPricePriorityToAll\" />" . $this->l('Apply to all products') . "</label>\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t</div>\n\t\t</div>\n\t\t";
     return ${${"GLOBALS"}["nkvjzc"]};
 }
示例#9
0
    /**
     * Return cart products
     *
     * @result array Products
     */
    public function getProducts($refresh = false, $id_product = false, $id_country = null)
    {
        if (!$this->id) {
            return array();
        }
        // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
        if ($this->_products !== null && !$refresh) {
            // Return product row with specified ID if it exists
            if (is_int($id_product)) {
                foreach ($this->_products as $product) {
                    if ($product['id_product'] == $id_product) {
                        return array($product);
                    }
                }
                return array();
            }
            return $this->_products;
        }
        // Build query
        $sql = new DbQuery();
        // Build SELECT
        $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
						pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`,
						p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
						product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`,
						stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
						p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
						CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
						product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference, IFNULL(sp.`reduction_type`, 0) AS reduction_type');
        // Build FROM
        $sql->from('cart_product', 'cp');
        // Build JOIN
        $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
        $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)');
        $sql->leftJoin('product_lang', 'pl', '
			p.`id_product` = pl.`id_product`
			AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop'));
        $sql->leftJoin('category_lang', 'cl', '
			product_shop.`id_category_default` = cl.`id_category`
			AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop'));
        $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`');
        $sql->leftJoin('specific_price', 'sp', 'sp.`id_product` = cp.`id_product`');
        // AND 'sp.`id_shop` = cp.`id_shop`
        // @todo test if everything is ok, then refactorise call of this method
        $sql->join(Product::sqlStock('cp', 'cp'));
        // Build WHERE clauses
        $sql->where('cp.`id_cart` = ' . (int) $this->id);
        if ($id_product) {
            $sql->where('cp.`id_product` = ' . (int) $id_product);
        }
        $sql->where('p.`id_product` IS NOT NULL');
        // Build GROUP BY
        $sql->groupBy('unique_id');
        // Build ORDER BY
        $sql->orderBy('cp.`date_add`, p.`id_product`, cp.`id_product_attribute` ASC');
        if (Customization::isFeatureActive()) {
            $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity');
            $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = ' . (int) $this->id);
        } else {
            $sql->select('NULL AS customization_quantity, NULL AS id_customization');
        }
        if (Combination::isFeatureActive()) {
            $sql->select('
				product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
				IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
				(p.`weight`+ pa.`weight`) weight_attribute,
				IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
				IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
				pai.`id_image` as pai_id_image, il.`legend` as pai_legend,
				IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity,
				IF(product_attribute_shop.wholesale_price > 0,  product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price
			');
            $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
            $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
            $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`');
            $sql->leftJoin('image_lang', 'il', 'il.`id_image` = pai.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang);
        } else {
            $sql->select('p.`reference` AS reference, p.`ean13`,
				p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price');
        }
        $result = Db::getInstance()->executeS($sql);
        // Reset the cache before the following return, or else an empty cart will add dozens of queries
        $products_ids = array();
        $pa_ids = array();
        if ($result) {
            foreach ($result as $row) {
                $products_ids[] = $row['id_product'];
                $pa_ids[] = $row['id_product_attribute'];
            }
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        Product::cacheProductsFeatures($products_ids);
        Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
        $this->_products = array();
        if (empty($result)) {
            return array();
        }
        $cart_shop_context = Context::getContext()->cloneContext();
        foreach ($result as &$row) {
            if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
                $row['ecotax'] = (double) $row['ecotax_attr'];
            }
            $row['stock_quantity'] = (int) $row['quantity'];
            // for compatibility with 1.2 themes
            $row['quantity'] = (int) $row['cart_quantity'];
            if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
                $row['weight'] = (double) $row['weight_attribute'];
            }
            if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
                $address_id = (int) $this->id_address_invoice;
            } else {
                $address_id = (int) $row['id_address_delivery'];
            }
            if (!Address::addressExists($address_id)) {
                $address_id = null;
            }
            if ($cart_shop_context->shop->id != $row['id_shop']) {
                $cart_shop_context->shop = new Shop((int) $row['id_shop']);
            }
            $address = Address::initialize($address_id, true);
            $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context);
            $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
            $row['price'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, false, true, $cart_shop_context);
            switch (Configuration::get('PS_ROUND_TYPE')) {
                case Order::ROUND_TOTAL:
                case Order::ROUND_LINE:
                    $row['total'] = Tools::ps_round($row['price'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                    $row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']) * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                    break;
                case Order::ROUND_ITEM:
                default:
                    $row['total'] = Tools::ps_round($row['price'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
                    $row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']), _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
                    break;
            }
            $row['price_wt'] = $tax_calculator->addTaxes($row['price']);
            $row['description_short'] = Tools::nl2br($row['description_short']);
            /**
             * ABU: correction bug
             * https://github.com/PrestaShop/PrestaShop/commit/bbc5591495b12021aa95421af1a0d27acd7a378e?diff=split
             */
            /*if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0)
            		{
            			$cache_id = 'Cart::getProducts_'.'-pai_id_image-'.(int)$row['id_product'].'-'.(int)$this->id_lang.'-'.(int)$row['id_shop'];
            			if (!Cache::isStored($cache_id))
            			{
            				$row2 = Db::getInstance()->getRow('
            					SELECT image_shop.`id_image` id_image, il.`legend`
            					FROM `'._DB_PREFIX_.'image` i
            					JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop='.(int)$row['id_shop'].')
            					LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.')
            					WHERE i.`id_product` = '.(int)$row['id_product'].' AND image_shop.`cover` = 1'
            				);
            				Cache::store($cache_id, $row2);
            			}
            			$row2 = Cache::retrieve($cache_id);
            			if (!$row2)
            				$row2 = array('id_image' => false, 'legend' => false);
            			else
            				$row = array_merge($row, $row2);
            		}
            		else
            		{
            			$row['id_image'] = $row['pai_id_image'];
            			$row['legend'] = $row['pai_legend'];
            		}*/
            $cache_id = 'Cart::getProducts_' . '-pai_id_image-' . (int) $row['id_product'] . '-' . (int) $row['id_product_attribute'] . '-' . (int) $this->id_lang . '-' . (int) $row['id_shop'];
            if (!Cache::isStored($cache_id)) {
                $flag = (int) $row['id_product_attribute'] && (int) $row['pai_id_image'];
                $row2 = Db::getInstance()->getRow('
					SELECT image_shop.`id_image` id_image, il.`legend`
					FROM `' . _DB_PREFIX_ . 'image` i
					INNER JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop
						ON (i.id_image = image_shop.id_image' . (!$flag ? ' AND image_shop.cover = 1' : '') . ' AND image_shop.id_shop = ' . (int) $row['id_shop'] . ')' . ($flag ? '
					INNER JOIN `' . _DB_PREFIX_ . 'product_attribute_image` pai
						ON (pai.`id_image` = i.`id_image` AND pai.`id_product_attribute` = ' . (int) $row['id_product_attribute'] . ')' : '') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il
						ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang . ')
					WHERE i.`id_product` = ' . (int) $row['id_product'] . ($flag ? '
					ORDER BY i.`position` ASC' : ''));
                Cache::store($cache_id, $row2);
            }
            $row2 = Cache::retrieve($cache_id);
            if (!$row2) {
                $row2 = array('id_image' => false, 'legend' => false);
            }
            $row = array_merge($row, $row2);
            /**
             * /end bug correction
             */
            $row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
            $row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity'];
            $row['id_image'] = Product::defineProductImage($row, $this->id_lang);
            $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
            $row['features'] = Product::getFeaturesStatic((int) $row['id_product']);
            if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) {
                $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]);
            }
            $row = Product::getTaxesInformations($row, $cart_shop_context);
            $this->_products[] = $row;
        }
        return $this->_products;
    }
 public function getAddressModel()
 {
     $model = new Address();
     return $model->initialize($this->getParameters());
 }
 /**
  * Add Products to cart
  * @param Cart $cart Cart object
  */
 private function addProductsToCart($cart, $codeCountry)
 {
     $products = $this->datas->orderLineItems;
     $country = $this->getCountry($codeCountry);
     $address = Address::initialize();
     $address->id_country = $country->id;
     if ($products && count($products)) {
         foreach ($products as $p) {
             if (PowaTagAPI::apiLog()) {
                 PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::IN_PROGRESS, 'Product : ' . $p->product->code);
             }
             $product = PowaTagProductHelper::getProductByCode($p->product->code, $this->context->language->id);
             if (!Validate::isLoadedObject($product)) {
                 $this->addError(sprintf($this->module->l('This product does not exists : %s'), $p->product->code), PowaTagErrorType::$SKU_NOT_FOUND);
                 if (PowaTagAPI::apiLog()) {
                     PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
                 }
                 return false;
             }
             $variants = $p->product->productVariants;
             $product_rate = 1 + $product->getTaxesRate($address) / 100;
             foreach ($variants as $variant) {
                 $variantCurrency = $this->getCurrencyByIsoCode($variant->finalPrice->currency);
                 if (!PowaTagValidate::currencyEnable($variantCurrency)) {
                     $this->addError(sprintf($this->module->l('Currency not found : %s'), $variant->code), PowaTagErrorType::$CURRENCY_NOT_SUPPORTED);
                     if (PowaTagAPI::apiLog()) {
                         PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
                     }
                     return false;
                 }
                 $variantAmount = $variant->finalPrice->amount;
                 $id_product_attribute = false;
                 $combination = false;
                 if ($id_product_attribute = PowaTagProductAttributeHelper::getCombinationByCode($product->id, $variant->code)) {
                     $combination = new Combination($id_product_attribute);
                     $priceAttribute = $product->getPrice($this->display_taxes, $id_product_attribute);
                     $qtyInStock = PowaTagProductQuantityHelper::getProductQuantity($product, $id_product_attribute);
                 } else {
                     if ($product) {
                         $priceAttribute = $product->getPrice($this->display_taxes);
                         $qtyInStock = PowaTagProductQuantityHelper::getProductQuantity($product);
                     } else {
                         $this->addError(sprintf($this->module->l('This variant does not exist : %s'), $variant->code), PowaTagErrorType::$SKU_NOT_FOUND);
                         if (PowaTagAPI::apiLog()) {
                             PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
                         }
                         return false;
                     }
                 }
                 if ($qtyInStock == 0) {
                     $this->addError(sprintf($this->module->l('No Stock Available')), PowaTagErrorType::$SKU_OUT_OF_STOCK);
                     if (PowaTagAPI::apiLog()) {
                         PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
                     }
                     return false;
                 }
                 if ($qtyInStock < $p->quantity) {
                     $this->addError(sprintf($this->module->l('Quantity > Stock Count')), PowaTagErrorType::$INSUFFICIENT_STOCK);
                     if (PowaTagAPI::apiLog()) {
                         PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
                     }
                     return false;
                 }
                 if ($p->quantity < $product->minimal_quantity || $combination && $combination->minimal_quantity > $p->quantity) {
                     $this->addError(sprintf($this->module->l('Quantity < minimal quantity for product')), PowaTagErrorType::$OTHER_STOCK_ERROR);
                     if (PowaTagAPI::apiLog()) {
                         PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
                     }
                     return false;
                 }
                 $cart->updateQty($p->quantity, $product->id, $id_product_attribute);
                 if (PowaTagAPI::apiLog()) {
                     PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::SUCCESS, 'Cart ID : ' . $cart->id . ' - Product ID : ' . $product->id);
                 }
                 break;
             }
         }
     } else {
         $this->addError($this->module->l('No product found in request'), PowaTagErrorType::$SKU_NOT_FOUND);
         return false;
     }
     // add vouchers
     if (isset($this->datas->vouchers)) {
         $this->context->cart = $cart;
         $vouchers = $this->datas->vouchers;
         if ($vouchers && count($vouchers)) {
             foreach ($vouchers as $voucher) {
                 $ci = CartRule::getIdByCode($voucher);
                 if (!$ci) {
                     continue;
                 }
                 $cr = new CartRule($ci);
                 if (!$cr) {
                     continue;
                 }
                 if ($error = $cr->checkValidity($this->context, false, true)) {
                     continue;
                 }
                 $this->context->cart->addCartRule($cr->id);
                 if (PowaTagAPI::apiLog()) {
                     PowaTagLogs::initAPILog('Added voucher', PowaTagLogs::SUCCESS, 'Cart ID : ' . $cart->id . ' - Voucher : ' . $voucher);
                 }
             }
         }
     }
     return true;
 }
示例#12
0
 /**
  * Get the gift wrapping price
  * @param boolean $with_taxes With or without taxes
  * @return float wrapping price
  */
 public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
 {
     static $address = null;
     $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
     if ($with_taxes && $wrapping_fees > 0) {
         if ($address === null) {
             if ($id_address === null) {
                 $id_address = (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
             }
             try {
                 $address = Address::initialize($id_address);
             } catch (Exception $e) {
                 $address = new Address();
                 $address->id_country = Configuration::get('PS_COUNTRY_DEFAULT');
             }
         }
         $tax_manager = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_GIFT_WRAPPING_TAX_RULES_GROUP'));
         $tax_calculator = $tax_manager->getTaxCalculator();
         $wrapping_fees = $tax_calculator->addTaxes($wrapping_fees);
     }
     return $wrapping_fees;
 }
示例#13
0
    public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true)
    {
        $currency = new Currency((int) $order->id_currency);
        $order_slip = new OrderSlip();
        $order_slip->id_customer = (int) $order->id_customer;
        $order_slip->id_order = (int) $order->id;
        $order_slip->conversion_rate = $currency->conversion_rate;
        if ($add_tax) {
            $add_or_remove = 'add';
            $inc_or_ex_1 = 'excl';
            $inc_or_ex_2 = 'incl';
        } else {
            $add_or_remove = 'remove';
            $inc_or_ex_1 = 'incl';
            $inc_or_ex_2 = 'excl';
        }
        $order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = 0;
        $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = 0;
        $order_slip->partial = 0;
        if ($shipping_cost !== false) {
            $order_slip->shipping_cost = true;
            $carrier = new Carrier((int) $order->id_carrier);
            $address = Address::initialize($order->id_address_delivery, false);
            $tax_calculator = $carrier->getTaxCalculator($address);
            $order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = $shipping_cost === null ? $order->{'total_shipping_tax_' . $inc_or_ex_1} : (double) $shipping_cost;
            if ($tax_calculator instanceof TaxCalculator) {
                $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($order_slip->{'total_shipping_tax_' . $inc_or_ex_1}), _PS_PRICE_COMPUTE_PRECISION_);
            } else {
                $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
            }
        } else {
            $order_slip->shipping_cost = false;
        }
        $order_slip->amount = 0;
        $order_slip->{'total_products_tax_' . $inc_or_ex_1} = 0;
        $order_slip->{'total_products_tax_' . $inc_or_ex_2} = 0;
        foreach ($product_list as &$product) {
            $order_detail = new OrderDetail((int) $product['id_order_detail']);
            $price = (double) $product['unit_price'];
            $quantity = (int) $product['quantity'];
            $order_slip_resume = OrderSlip::getProductSlipResume((int) $order_detail->id);
            if ($quantity + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
                $quantity = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
            }
            if ($quantity == 0) {
                continue;
            }
            $order_detail->product_quantity_refunded += $quantity;
            $order_detail->save();
            $address = Address::initialize($order->id_address_invoice, false);
            $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $order_detail->product_id);
            $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
            $order_slip->{'total_products_tax_' . $inc_or_ex_1} += $price * $quantity;
            if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
                if (!isset($total_products[$id_tax_rules_group])) {
                    $total_products[$id_tax_rules_group] = 0;
                } else {
                    if (!isset($total_products[$id_tax_rules_group . '_' . $id_address])) {
                        $total_products[$id_tax_rules_group . '_' . $id_address] = 0;
                    }
                }
            }
            $product_tax_incl_line = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price) * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
            switch (Configuration::get('PS_ROUND_TYPE')) {
                case Order::ROUND_ITEM:
                    $product_tax_incl = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_) * $quantity;
                    $total_products[$id_tax_rules_group] += $product_tax_incl;
                    break;
                case Order::ROUND_LINE:
                    $product_tax_incl = $product_tax_incl_line;
                    $total_products[$id_tax_rules_group] += $product_tax_incl;
                    break;
                case Order::ROUND_TOTAL:
                    $product_tax_incl = $product_tax_incl_line;
                    $total_products[$id_tax_rules_group . '_' . $id_address] += $price * $quantity;
                    break;
            }
            $product['unit_price_tax_' . $inc_or_ex_1] = $price;
            $product['unit_price_tax_' . $inc_or_ex_2] = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
            $product['total_price_tax_' . $inc_or_ex_1] = Tools::ps_round($price * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
            $product['total_price_tax_' . $inc_or_ex_2] = Tools::ps_round($product_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
            $product['product_id'] = $order_detail->product_id;
        }
        unset($product);
        foreach ($total_products as $key => $price) {
            if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
                $tmp = explode('_', $key);
                $address = Address::initialize((int) $tmp[1], true);
                $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
                $order_slip->{'total_products_tax_' . $inc_or_ex_2} += Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
            } else {
                $order_slip->{'total_products_tax_' . $inc_or_ex_2} += $price;
            }
        }
        $order_slip->{'total_products_tax_' . $inc_or_ex_2} -= (double) $amount && !$amount_choosen ? (double) $amount : 0;
        $order_slip->amount = $amount_choosen ? (double) $amount : $order_slip->{'total_products_tax_' . $inc_or_ex_1};
        $order_slip->shipping_cost_amount = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
        if ((double) $amount && !$amount_choosen) {
            $order_slip->order_slip_type = 1;
        }
        if ((double) $amount && $amount_choosen || $order_slip->shipping_cost_amount > 0) {
            $order_slip->order_slip_type = 2;
        }
        if (!$order_slip->add()) {
            return false;
        }
        $res = true;
        $param = array();
        $param['MerchantOrderID'] = $order->id;
        $prefix = _DB_PREFIX_;
        $i = 0;
        foreach ($product_list as $product) {
            $res &= $order_slip->addProductOrderSlip($product);
            $order_item_detail = new OrderDetail((int) $product['id_order_detail']);
            $sql = 'UPDATE `' . $prefix . 'stock_available` set
					`quantity` = `quantity` + ' . $product['quantity'] . '
					where `id_product` = ' . $product['product_id'] . ' and
					`id_product_attribute` = 0
					';
            //Db::getInstance()->Execute($sql);
            if ($order_item_detail->product_attribute_id > 0) {
                $sql = 'UPDATE `' . $prefix . 'stock_available` set
						`quantity` = `quantity` + ' . $product['quantity'] . '
						where `id_product` = ' . $product['product_id'] . ' and
						`id_product_attribute` = ' . $order_item_detail->product_attribute_id . '
						';
                //Db::getInstance()->Execute($sql);
            }
            $date = date('Y-m-d');
            $sql = 'UPDATE `' . $prefix . 'product_sale` set
					`quantity` = `quantity` - ' . $product['quantity'] . ',
					`sale_nbr` = `sale_nbr` - ' . $product['quantity'] . ',
					`date_upd` = ' . $date . '
					where `id_product` = ' . $product['product_id'] . '
					';
            //Db::getInstance()->Execute($sql);
            $param['items'][$i]['MerchantOrderItemID'] = $product['product_id'];
            $param['items'][$i]['Principal'] = $product['total_price_tax_incl'];
            $param['items'][$i]['Shipping'] = 0;
            $param['items'][$i]['Tax'] = 0;
            $param['items'][$i]['ShippingTax'] = 0;
            $param['items'][$i]['quantity'] = $product['quantity'];
            $i++;
        }
        $refund = new Pwapresta();
        $refund->pwa_refund_feed($param);
        return $res;
    }
示例#14
0
    /**
     * Return cart products
     *
     * @result array Products
     */
    public function getProducts($refresh = false, $id_product = false, $id_country = null)
    {
        if (!$this->id) {
            return array();
        }
        // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
        if ($this->_products !== null && !$refresh) {
            // Return product row with specified ID if it exists
            if (is_int($id_product)) {
                foreach ($this->_products as $product) {
                    if ($product['id_product'] == $id_product) {
                        return array($product);
                    }
                }
                return array();
            }
            return $this->_products;
        }
        // Build query
        $sql = new DbQuery();
        // Build SELECT
        $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, cp.delivery_date, cp.delivery_time_to, cp.delivery_time_from, pl.`name`, p.`is_virtual`,
						pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`,
						p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
						product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`,
						stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
						p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
						CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
						product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference');
        // Build FROM
        $sql->from('cart_product', 'cp');
        // Build JOIN
        $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
        $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)');
        $sql->leftJoin('product_lang', 'pl', '
			p.`id_product` = pl.`id_product`
			AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop'));
        $sql->leftJoin('category_lang', 'cl', '
			product_shop.`id_category_default` = cl.`id_category`
			AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop'));
        $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`');
        // @todo test if everything is ok, then refactorise call of this method
        $sql->join(Product::sqlStock('cp', 'cp'));
        // Build WHERE clauses
        $sql->where('cp.`id_cart` = ' . (int) $this->id);
        if ($id_product) {
            $sql->where('cp.`id_product` = ' . (int) $id_product);
        }
        $sql->where('p.`id_product` IS NOT NULL');
        // Build ORDER BY
        $sql->orderBy('cp.`date_add`, cp.`id_product`, cp.`id_product_attribute` ASC');
        if (Customization::isFeatureActive()) {
            $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity');
            $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = ' . (int) $this->id);
            $sql->groupBy('cp.`id_product_attribute`, cp.`id_product`, cp.`id_shop`');
        } else {
            $sql->select('NULL AS customization_quantity, NULL AS id_customization');
        }
        if (Combination::isFeatureActive()) {
            $sql->select('
				product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
				IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
				(p.`weight`+ pa.`weight`) weight_attribute,
				IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
				IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
				IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity,
				IF(product_attribute_shop.wholesale_price > 0,  product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price
			');
            $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
            $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
        } else {
            $sql->select('p.`reference` AS reference, p.`ean13`,
				p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price');
        }
        $sql->select('image_shop.`id_image` id_image, il.`legend`');
        $sql->leftJoin('image_shop', 'image_shop', 'image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $this->id_shop);
        $sql->leftJoin('image_lang', 'il', 'il.`id_image` = image_shop.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang);
        $result = Db::getInstance()->executeS($sql);
        // Reset the cache before the following return, or else an empty cart will add dozens of queries
        $products_ids = array();
        $pa_ids = array();
        if ($result) {
            foreach ($result as $key => $row) {
                $products_ids[] = $row['id_product'];
                $pa_ids[] = $row['id_product_attribute'];
                $specific_price = SpecificPrice::getSpecificPrice($row['id_product'], $this->id_shop, $this->id_currency, $id_country, $this->id_shop_group, $row['cart_quantity'], $row['id_product_attribute'], $this->id_customer, $this->id);
                if ($specific_price) {
                    $reduction_type_row = array('reduction_type' => $specific_price['reduction_type']);
                } else {
                    $reduction_type_row = array('reduction_type' => 0);
                }
                $result[$key] = array_merge($row, $reduction_type_row);
            }
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        Product::cacheProductsFeatures($products_ids);
        Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
        $this->_products = array();
        if (empty($result)) {
            return array();
        }
        $ecotax_rate = (double) Tax::getProductEcotaxRate($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
        $apply_eco_tax = Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX');
        $cart_shop_context = Context::getContext()->cloneContext();
        foreach ($result as &$row) {
            if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
                $row['ecotax'] = (double) $row['ecotax_attr'];
            }
            $row['stock_quantity'] = (int) $row['quantity'];
            // for compatibility with 1.2 themes
            $row['quantity'] = (int) $row['cart_quantity'];
            if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
                $row['weight'] = (double) $row['weight_attribute'];
            }
            if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
                $address_id = (int) $this->id_address_invoice;
            } else {
                $address_id = (int) $row['id_address_delivery'];
            }
            if (!Address::addressExists($address_id)) {
                $address_id = null;
            }
            if ($cart_shop_context->shop->id != $row['id_shop']) {
                $cart_shop_context->shop = new Shop((int) $row['id_shop']);
            }
            $row['shop_name'] = $cart_shop_context->shop->name;
            $address = Address::initialize($address_id, true);
            $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context);
            $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
            $row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, !empty($row['delivery_date']) && $row['delivery_date'] != '0000-00-00' ? 0 : (isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null), 6, null, false, false, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context, true, $row['delivery_date'], $row['delivery_time_from'], $row['delivery_time_to']);
            $row['price_with_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, !empty($row['delivery_date']) && $row['delivery_date'] != '0000-00-00' ? 0 : (isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null), 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context, true, $row['delivery_date'], $row['delivery_time_from'], $row['delivery_time_to']);
            $row['price'] = $row['price_with_reduction_without_tax'] = Product::getPriceStatic((int) $row['id_product'], false, !empty($row['delivery_date']) && $row['delivery_date'] != '0000-00-00' ? 0 : (isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null), 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context, true, $row['delivery_date'], $row['delivery_time_from'], $row['delivery_time_to']);
            switch (Configuration::get('PS_ROUND_TYPE')) {
                case Order::ROUND_TOTAL:
                    $row['total'] = $row['price_with_reduction_without_tax'] * (int) $row['cart_quantity'];
                    $row['total_wt'] = $row['price_with_reduction'] * (int) $row['cart_quantity'];
                    break;
                case Order::ROUND_LINE:
                    $row['total'] = Tools::ps_round($row['price_with_reduction_without_tax'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                    $row['total_wt'] = Tools::ps_round($row['price_with_reduction'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                    break;
                case Order::ROUND_ITEM:
                default:
                    $row['total'] = Tools::ps_round($row['price_with_reduction_without_tax'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
                    $row['total_wt'] = Tools::ps_round($row['price_with_reduction'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
                    break;
            }
            $row['price_wt'] = $row['price_with_reduction'];
            $row['description_short'] = Tools::nl2br($row['description_short']);
            // check if a image associated with the attribute exists
            if ($row['id_product_attribute']) {
                $row2 = Image::getBestImageAttribute($row['id_shop'], $this->id_lang, $row['id_product'], $row['id_product_attribute']);
                if ($row2) {
                    $row = array_merge($row, $row2);
                }
            }
            $row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
            $row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity'];
            $row['id_image'] = Product::defineProductImage($row, $this->id_lang);
            $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
            $row['features'] = Product::getFeaturesStatic((int) $row['id_product']);
            if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) {
                $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]);
            }
            $row = Product::getTaxesInformations($row, $cart_shop_context);
            $this->_products[] = $row;
        }
        return $this->_products;
    }
示例#15
0
 public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true)
 {
     static $address = null;
     if (!$this->id) {
         return 0;
     }
     $type = (int) $type;
     $array_type = array(Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING);
     // Define virtual context to prevent case where the cart is not the in the global context
     $virtual_context = Context::getContext()->cloneContext();
     $virtual_context->cart = $this;
     if (!in_array($type, $array_type)) {
         die(Tools::displayError());
     }
     $with_shipping = in_array($type, array(Cart::BOTH, Cart::ONLY_SHIPPING));
     // if cart rules are not used
     if ($type == Cart::ONLY_DISCOUNTS && !CartRule::isFeatureActive()) {
         return 0;
     }
     // no shipping cost if is a cart with only virtuals products
     $virtual = $this->isVirtualCart();
     if ($virtual && $type == Cart::ONLY_SHIPPING) {
         return 0;
     }
     if ($virtual && $type == Cart::BOTH) {
         $type = Cart::BOTH_WITHOUT_SHIPPING;
     }
     if ($with_shipping || $type == Cart::ONLY_DISCOUNTS) {
         if (is_null($products) && is_null($id_carrier)) {
             $shipping_fees = $this->getTotalShippingCost(null, (bool) $with_taxes);
         } else {
             $shipping_fees = $this->getPackageShippingCost($id_carrier, (bool) $with_taxes, null, $products);
         }
     } else {
         $shipping_fees = 0;
     }
     if ($type == Cart::ONLY_SHIPPING) {
         return $shipping_fees;
     }
     if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING) {
         $type = Cart::ONLY_PRODUCTS;
     }
     $param_product = true;
     if (is_null($products)) {
         $param_product = false;
         $products = $this->getProducts();
     }
     if ($type == Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) {
         foreach ($products as $key => $product) {
             if ($product['is_virtual']) {
                 unset($products[$key]);
             }
         }
         $type = Cart::ONLY_PRODUCTS;
     }
     $order_total = 0;
     if (Tax::excludeTaxeOption()) {
         $with_taxes = false;
     }
     $products_total = array();
     $ecotax_total = 0;
     foreach ($products as $product) {
         if ($virtual_context->shop->id != $product['id_shop']) {
             $virtual_context->shop = new Shop((int) $product['id_shop']);
         }
         if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
             $id_address = (int) $this->id_address_invoice;
         } else {
             $id_address = (int) $product['id_address_delivery'];
         }
         // Get delivery address of the product from the cart
         if (!Address::addressExists($id_address)) {
             $id_address = null;
         }
         $null = null;
         $price = Product::getPriceStatic((int) $product['id_product'], false, (int) $product['id_product_attribute'], 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $id_address, $null, false, true, $virtual_context);
         if (Configuration::get('PS_USE_ECOTAX')) {
             $ecotax = $product['ecotax'];
             if (isset($product['attribute_ecotax']) && $product['attribute_ecotax'] > 0) {
                 $ecotax = $product['attribute_ecotax'];
             }
         } else {
             $ecotax = 0;
         }
         $address = Address::initialize($id_address, true);
         if ($with_taxes) {
             $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product'], $virtual_context);
             $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
             if ($ecotax) {
                 $ecotax_tax_calculator = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID'))->getTaxCalculator();
             }
         } else {
             $id_tax_rules_group = 0;
         }
         if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
             if (!isset($products_total[$id_tax_rules_group])) {
                 $products_total[$id_tax_rules_group] = 0;
             }
         } else {
             if (!isset($products_total[$id_tax_rules_group . '_' . $id_address])) {
                 $products_total[$id_tax_rules_group . '_' . $id_address] = 0;
             }
         }
         switch (Configuration::get('PS_ROUND_TYPE')) {
             case Order::ROUND_TOTAL:
                 $products_total[$id_tax_rules_group . '_' . $id_address] += PP::calcPrice($price, $product['cart_quantity'], $product['cart_quantity_fractional'], (int) $product['id_product'], false);
                 $ppropertiessmartprice_hook3 = null;
                 if ($ecotax) {
                     $ecotax_total += PP::calcPrice($ecotax, $product['cart_quantity'], $product['cart_quantity_fractional'], null, false);
                 }
                 break;
             case Order::ROUND_LINE:
                 $product_price = PP::calcPrice($price, $product['cart_quantity'], $product['cart_quantity_fractional'], (int) $product['id_product'], false);
                 $ppropertiessmartprice_hook4 = null;
                 if ($with_taxes) {
                     $products_total[$id_tax_rules_group] += Tools::ps_round($product_price + $tax_calculator->getTaxesTotalAmount($product_price), _PS_PRICE_COMPUTE_PRECISION_);
                 } else {
                     $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, _PS_PRICE_COMPUTE_PRECISION_);
                 }
                 if ($ecotax) {
                     $ecotax_price = PP::calcPrice($ecotax, $product['cart_quantity'], $product['cart_quantity_fractional'], null, false);
                     if ($with_taxes) {
                         $ecotax_total += Tools::ps_round($ecotax_price + $ecotax_tax_calculator->getTaxesTotalAmount($ecotax_price), _PS_PRICE_COMPUTE_PRECISION_);
                     } else {
                         $ecotax_total += Tools::ps_round($ecotax_price, _PS_PRICE_COMPUTE_PRECISION_);
                     }
                 }
                 break;
             case Order::ROUND_ITEM:
             default:
                 $product_price = $with_taxes ? $tax_calculator->addTaxes($price) : $price;
                 $products_total[$id_tax_rules_group] += PP::calcPrice($product_price, $product['cart_quantity'], $product['cart_quantity_fractional'], (int) $product['id_product'], Order::ROUND_ITEM);
                 $ppropertiessmartprice_hook5 = null;
                 if ($ecotax) {
                     $ecotax_price = $with_taxes ? $ecotax_tax_calculator->addTaxes($ecotax) : $ecotax;
                     $ecotax_total += PP::calcPrice($ecotax_price, $product['cart_quantity'], $product['cart_quantity_fractional'], null, Order::ROUND_ITEM);
                 }
                 break;
         }
     }
     foreach ($products_total as $key => $price) {
         if ($with_taxes && Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
             $tmp = explode('_', $key);
             $address = Address::initialize((int) $tmp[1], true);
             $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
             $order_total += Tools::ps_round($price + $tax_calculator->getTaxesTotalAmount($price), _PS_PRICE_COMPUTE_PRECISION_);
         } else {
             $order_total += $price;
         }
     }
     if ($ecotax_total && $with_taxes && Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
         $ecotax_total = Tools::ps_round($ecotax_total, _PS_PRICE_COMPUTE_PRECISION_) + Tools::ps_round($ecotax_tax_calculator->getTaxesTotalAmount($ecotax_total), _PS_PRICE_COMPUTE_PRECISION_);
     }
     $order_total += $ecotax_total;
     $order_total_products = $order_total;
     if ($type == Cart::ONLY_DISCOUNTS) {
         $order_total = 0;
     }
     // Wrapping Fees
     $wrapping_fees = 0;
     if ($this->gift) {
         $wrapping_fees = Tools::convertPrice(Tools::ps_round($this->getGiftWrappingPrice($with_taxes), _PS_PRICE_COMPUTE_PRECISION_), Currency::getCurrencyInstance((int) $this->id_currency));
     }
     if ($type == Cart::ONLY_WRAPPING) {
         return $wrapping_fees;
     }
     $order_total_discount = 0;
     $order_shipping_discount = 0;
     if (!in_array($type, array(Cart::ONLY_SHIPPING, Cart::ONLY_PRODUCTS)) && CartRule::isFeatureActive()) {
         // First, retrieve the cart rules associated to this "getOrderTotal"
         if ($with_shipping || $type == Cart::ONLY_DISCOUNTS) {
             $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_ALL);
         } else {
             $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_REDUCTION);
             // Cart Rules array are merged manually in order to avoid doubles
             foreach ($this->getCartRules(CartRule::FILTER_ACTION_GIFT) as $tmp_cart_rule) {
                 $flag = false;
                 foreach ($cart_rules as $cart_rule) {
                     if ($tmp_cart_rule['id_cart_rule'] == $cart_rule['id_cart_rule']) {
                         $flag = true;
                     }
                 }
                 if (!$flag) {
                     $cart_rules[] = $tmp_cart_rule;
                 }
             }
         }
         $id_address_delivery = 0;
         if (isset($products[0])) {
             $id_address_delivery = is_null($products) ? $this->id_address_delivery : $products[0]['id_address_delivery'];
         }
         $package = array('id_carrier' => $id_carrier, 'id_address' => $id_address_delivery, 'products' => $products);
         // Then, calculate the contextual value for each one
         $flag = false;
         foreach ($cart_rules as $cart_rule) {
             // If the cart rule offers free shipping, add the shipping cost
             if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule['obj']->free_shipping && !$flag) {
                 $order_shipping_discount = (double) Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, $param_product ? $package : null, $use_cache), _PS_PRICE_COMPUTE_PRECISION_);
                 $flag = true;
             }
             // If the cart rule is a free gift, then add the free gift value only if the gift is in this package
             if ((int) $cart_rule['obj']->gift_product) {
                 $in_order = false;
                 if (is_null($products)) {
                     $in_order = true;
                 } else {
                     foreach ($products as $product) {
                         if ($cart_rule['obj']->gift_product == $product['id_product'] && $cart_rule['obj']->gift_product_attribute == $product['id_product_attribute']) {
                             $in_order = true;
                         }
                     }
                 }
                 if ($in_order) {
                     $order_total_discount += $cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_GIFT, $package, $use_cache);
                 }
             }
             // If the cart rule offers a reduction, the amount is prorated (with the products in the package)
             if ($cart_rule['obj']->reduction_percent > 0 || $cart_rule['obj']->reduction_amount > 0) {
                 $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_REDUCTION, $package, $use_cache), _PS_PRICE_COMPUTE_PRECISION_);
             }
         }
         $order_total_discount = min(Tools::ps_round($order_total_discount, 2), (double) $order_total_products) + (double) $order_shipping_discount;
         $order_total -= $order_total_discount;
     }
     if ($type == Cart::BOTH) {
         $order_total += $shipping_fees + $wrapping_fees;
     }
     if ($order_total < 0 && $type != Cart::ONLY_DISCOUNTS) {
         return 0;
     }
     if ($type == Cart::ONLY_DISCOUNTS) {
         return $order_total_discount;
     }
     return Tools::ps_round((double) $order_total, _PS_PRICE_COMPUTE_PRECISION_);
 }