/** * Assign price and tax to the template. */ protected function assignPriceAndTax() { $id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0; $id_group = (int) Group::getCurrent()->id; $id_country = $id_customer ? (int) Customer::getCurrentCountry($id_customer) : (int) Tools::getCountry(); // Tax $tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $this->context->smarty->assign('tax_rate', $tax); $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2); } $id_currency = (int) $this->context->cookie->id_currency; $id_product = (int) $this->product->id; $id_product_attribute = Tools::getValue('id_product_attribute', null); $id_shop = $this->context->shop->id; $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_product_attribute, false, (int) $this->context->customer->id); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount['id_product_attribute']) { $combination = new Combination((int) $quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); foreach ($attributes as $attribute) { $quantity_discount['attributes'] = $attribute['name'] . ' - '; } $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } if ((int) $quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') { $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency); } } $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false); $this->quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $this->product->ecotax); $this->context->smarty->assign(array('no_tax' => Tax::excludeTaxeOption() || !$tax, 'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'), 'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group))); }
public function initContent() { if (!Combination::isFeatureActive()) { $url = '<a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->trans('Performance', array(), 'Admin.Global') . '</a>'; $this->displayWarning(sprintf($this->trans('This feature has been disabled. You can activate it here: %s.', array('%s' => $url), 'Admin.Catalog.Notification'))); return; } // Init toolbar $this->initPageHeaderToolbar(); $this->initGroupTable(); $attributes = Attribute::getAttributes(Context::getContext()->language->id, true); $attribute_js = array(); foreach ($attributes as $k => $attribute) { $attribute_js[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name']; } $attribute_groups = AttributeGroup::getAttributesGroups($this->context->language->id); $this->product = new Product((int) Tools::getValue('id_product')); $this->context->smarty->assign(array('tax_rates' => $this->product->getTaxesRate(), 'generate' => isset($_POST['generate']) && !count($this->errors), 'combinations_size' => count($this->combinations), 'product_name' => $this->product->name[$this->context->language->id], 'product_reference' => $this->product->reference, 'url_generator' => self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&attributegenerator&token=' . Tools::getValue('token'), 'attribute_groups' => $attribute_groups, 'attribute_js' => $attribute_js, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => true, 'show_page_header_toolbar' => $this->show_page_header_toolbar, 'page_header_toolbar_title' => $this->page_header_toolbar_title, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn)); }
/** * Assign price and tax to the template */ protected function assignPriceAndTax() { $id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0; $id_group = isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_; $id_country = (int) $id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'); $group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group); if ($group_reduction == 0) { $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100; } // Tax $tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $this->context->smarty->assign('tax_rate', $tax); $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2); } $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax; $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2); } $id_currency = (int) $this->context->cookie->id_currency; $id_product = (int) $this->product->id; $id_shop = $this->context->shop->id; $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount['id_product_attribute']) { $combination = new Combination((int) $quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); foreach ($attributes as $attribute) { $quantity_discount['attributes'] = $attribute['name'] . ' - '; } $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } } $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false); $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $this->context->smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax), 'ecotax_tax_inc' => $ecotax_tax_amount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'productPriceWithoutEcoTax' => (double) $product_price_without_eco_tax, 'group_reduction' => 1 - $group_reduction, 'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address), 'ecotax' => !count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'tax_enabled' => Configuration::get('PS_TAX'))); }
public function ajaxProcessSearchProducts() { Context::getContext()->customer = new Customer((int) Tools::getValue('id_customer')); $currency = new Currency((int) Tools::getValue('id_currency')); if ($products = Product::searchByName((int) $this->context->language->id, pSQL(Tools::getValue('product_search')))) { foreach ($products as &$product) { // Formatted price $product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency); // Concret price $product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2); $product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2); $productObj = new Product((int) $product['id_product'], false, (int) $this->context->language->id); $combinations = array(); $attributes = $productObj->getAttributesGroups((int) $this->context->language->id); // Tax rate for this customer if (Tools::isSubmit('id_address')) { $product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address'))); } $product['warehouse_list'] = array(); foreach ($attributes as $attribute) { if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) { $combinations[$attribute['id_product_attribute']]['attributes'] = ''; } $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'] . ' - '; $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute']; $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on']; if (!isset($combinations[$attribute['id_product_attribute']]['price'])) { $price_tax_incl = Product::getPriceStatic((int) $product['id_product'], true, $attribute['id_product_attribute']); $price_tax_excl = Product::getPriceStatic((int) $product['id_product'], false, $attribute['id_product_attribute']); $combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2); $combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2); $combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_excl, $currency), $currency); } if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) { $combinations[$attribute['id_product_attribute']]['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], $attribute['id_product_attribute'], (int) $this->context->shop->id); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) { $product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']); } else { $product['warehouse_list'][$attribute['id_product_attribute']] = array(); } $product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) { $product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']); } else { $product['warehouse_list'][0] = array(); } $product['stock'][0] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], 0, (int) $this->context->shop->id); foreach ($combinations as &$combination) { $combination['attributes'] = rtrim($combination['attributes'], ' - '); } $product['combinations'] = $combinations; if ($product['customizable']) { $product_instance = new Product((int) $product['id_product']); $product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id); } } $to_return = array('products' => $products, 'found' => true); } else { $to_return = array('found' => false); } $this->content = Tools::jsonEncode($to_return); }
public function getProducts($selected_filters, &$products, &$nb_products, &$p, &$n, &$pages_nb, &$start, &$stop, &$range, &$combinations) { global $cookie; $products = $this->getProductByFilters($selected_filters); $products = Product::getProductsProperties((int) $cookie->id_lang, $products); $nb_products = $this->nbr_products; $range = 2; /* how many pages around page selected */ $n = (int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')); if ($n <= 0) { $n = 1; } $p = $this->page; if ($p < 0) { $p = 0; } if ($p > $nb_products / $n) { $p = ceil($nb_products / $n); } $pages_nb = ceil($nb_products / (int) $n); $start = (int) ($p - $range); if ($start < 1) { $start = 1; } $stop = (int) ($p + $range); if ($stop > $pages_nb) { $stop = (int) $pages_nb; } foreach ($products as &$product) { if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) { $product['minimal_quantity'] = $product['product_attribute_minimal_quantity']; } $product_obj = new Product((int) $product['id_product'], $this->context->language->id); $product['groups'] = $product_obj->getProductCombinationsGroups((int) $product['id_product']); $product['obj'] = $product_obj; $combinations[$product['id_product']] = $product_obj->getProductAttributeCombinations($product['id_product']); $id_group = (int) Group::getCurrent()->id; $group_reduction = GroupReduction::getValueForProduct($product['id_product'], $id_group); if ($group_reduction === false) { $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100; } $product['group_reduction'] = $group_reduction; $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $product['no_tax'] = Tax::excludeTaxeOption() || !$product_obj->getTaxesRate($address); $product['customer_group_without_tax'] = Group::getPriceDisplayMethod($this->context->customer->id_default_group); $tax = (double) $product_obj->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $product['tax_rate'] = $tax; $product['unit_price_ratio'] = $product_obj->unit_price_ratio; $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $product['ecotaxTax_rate'] = $ecotax_rate; } }
protected function getArticles(Order $order, $cart = false) { $this->to_refund = 0; $this->to_refund_tax = 0; if ($cart) { $products = $cart->getProducts(); } else { $products = $order->getProducts(); foreach ($products as $key => &$order_item) { $order_item['product_quantity'] -= $order_item['product_quantity_refunded']; $this->to_refund += $order_item['product_quantity_refunded'] * $order_item['unit_price_tax_incl']; $this->to_refund_tax += $order_item['product_quantity_refunded'] * $order_item['unit_price_tax_excl']; if ((int) $order_item['product_quantity'] <= 0) { unset($products[$key]); } } } $articles = array(); $link = new Link(); foreach ($products as $order_item) { if ($cart) { $productId = $order_item['id_product']; $Product = new Product($productId); $discounts = $order_item['reduction_applies']; $quantity = $order_item['cart_quantity']; $price = $order_item['price_wt']; $description_short = strip_tags($order_item['description_short']); $image_url = str_replace('http://', '', $link->getImageLink('product', $order_item['id_image'])); $name = $order_item['name']; $sku = $order_item['id_product_attribute']; $product_url = $link->getProductLink($productId); } else { $productId = $order_item['product_id']; $Product = new Product($productId); $discounts = $order_item['reduction_amount_tax_incl']; $quantity = $order_item['product_quantity']; $price = $order_item['unit_price_tax_incl']; $description_short = strip_tags($order_item['description_short']); $image_url = str_replace('http://', '', $link->getImageLink('product', $order_item['image']->id)); $name = $order_item['product_name']; $sku = $order_item['product_attribute_id']; $product_url = $link->getProductLink($productId); } $articles[] = array("id" => $productId, "sku" => $sku, "name" => $name, "description" => substr($description_short, 0, 255), "url" => $product_url, "image_url" => 'http://' . $image_url, "quantity" => intval($quantity), "price" => static::formatDecimals($price), "tax_rate" => static::formatDecimals($Product->getTaxesRate()), "discount" => static::formatDecimals($discounts)); } return $articles; }
public function initContent() { if (!$this->ajax) { parent::initContent(); } // parent::initContent(); $this->setTemplate(_PS_THEME_DIR_ . 'category.tpl'); if (!$this->customer_access) { return; } if (isset($this->context->cookie->id_compare)) { $this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int) $this->context->cookie->id_compare)); } $this->productSort(); // Product sort must be called before assignProductList() $this->assignScenes(); $this->assignSubcategories(); $this->assignProductList(); $products = isset($this->cat_products) && $this->cat_products ? $this->cat_products : null; $combinations = array(); if ($products !== NULL) { foreach ($products as &$pro) { $product_obj = new Product($pro['id_product'], $this->context->language->id); $pro['groups'] = $product_obj->getProductCombinationsGroups($pro['id_product']); $combinations[$pro['id_product']] = $product_obj->getProductAttributeCombinations($pro['id_product']); $id_group = (int) Group::getCurrent()->id; $group_reduction = GroupReduction::getValueForProduct($pro['id_product'], $id_group); if ($group_reduction === false) { $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100; } $pro['group_reduction'] = $group_reduction; $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $pro['no_tax'] = Tax::excludeTaxeOption() || !$product_obj->getTaxesRate($address); $pro['customer_group_without_tax'] = Group::getPriceDisplayMethod($this->context->customer->id_default_group); $tax = (double) $product_obj->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $pro['tax_rate'] = $tax; $pro['unit_price_ratio'] = $product_obj->unit_price_ratio; $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $pro['ecotaxTax_rate'] = $ecotax_rate; } } $this->context->smarty->assign(array('category' => $this->category, 'description_short' => Tools::truncateString($this->category->description, 350), 'products' => $products, 'id_category' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name), 'path' => Tools::getPath($this->category->id), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'categorySize' => Image::getSize(ImageType::getFormatedName('category')), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'allow_oosp' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'comparator_max_item' => (int) Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'suppliers' => Supplier::getSuppliers(), 'body_classes' => array($this->php_self . '-' . $this->category->id, $this->php_self . '-' . $this->category->link_rewrite), 'combinations' => $combinations)); }
private function processPrice() { if ($this->id_product) { $product = new Product($this->id_product, true, $this->context->language->id); if ($product->id && $product->active) { $error = false; $properties = $product->productProperties(); if ($properties['pp_ext'] == 1 && in_array($properties['pp_ext_policy'], array(0, 2))) { $qty = PP::resolveInputQty(Tools::getValue('qty'), 0, $properties['pp_qty_step']); } else { $qty = PP::resolveInputQty(Tools::getValue('qty'), $properties['pp_qty_policy'], $properties['pp_qty_step']); } if ($qty <= 0) { $error = true; } if (!$error) { if ($properties['pp_ext'] == 1 && in_array($properties['pp_ext_policy'], array(0, 2))) { $ext_prop_quantities = array(); $ext_prop_qty_ratio = array(); if ($properties['pp_ext_policy'] == 2) { $prop = $product->productProp(); } $positions = count($properties['pp_ext_prop']); for ($position = 1; $position <= $positions; $position++) { $pp_ext_prop = $properties['pp_ext_prop'][$position]; if ($properties['pp_ext_policy'] == 2) { $q = PP::productProp($prop, $this->id_product_attribute, $position, 'quantity'); if ($q === false) { $q = (double) $pp_ext_prop['default_quantity']; } if ($q <= 0) { $q = 1; } } else { $q = PP::resolveInputQty(Tools::getValue('pp_ext_prop_quantity_' . $position, 'default'), $properties['pp_qty_policy'], $pp_ext_prop['qty_step'], $pp_ext_prop['default_quantity'] > 0 ? $pp_ext_prop['default_quantity'] : 1); } $ext_prop_quantities[$position] = $q; $ext_prop_qty_ratio[$position] = $properties['pp_ext_prop'][$position]['qty_ratio']; if ($q <= 0) { $error = true; } $min_qty = (double) $pp_ext_prop['minimum_quantity']; if ($min_qty > 0 && $q < $min_qty) { $error = true; } $max_qty = (double) $pp_ext_prop['maximum_quantity']; if ($max_qty > 0 && $q > $max_qty) { $error = true; } } if (!$error) { $ext_prop_qty = array(); $quantity = $qty; $quantity_fractional = $properties['pp_ext_method'] == 1 ? 1 : 0; $count = count($ext_prop_quantities); for ($position = 1; $position <= $count; $position++) { $value = $ext_prop_quantities[$position]; $qty_ratio = $ext_prop_qty_ratio[$position]; $ext_prop_qty[$position] = $qty_ratio > 0 ? $value / $qty_ratio : $value; if ($properties['pp_ext_method'] == 1) { $quantity_fractional *= $ext_prop_qty[$position]; } elseif ($properties['pp_ext_method'] == 2) { $quantity_fractional += $ext_prop_qty[$position]; } } } } else { if (PP::qtyPolicyFractional($properties['pp_qty_policy'])) { $quantity = 1; $quantity_fractional = $qty; } else { $quantity = $qty; $quantity_fractional = 0; } } } if (!$error) { $id_customer = isset($this->context->customer) ? $this->context->customer->id : null; $this->id_product_attribute = $this->id_product_attribute > 0 ? $this->id_product_attribute : null; $qty = array($quantity, $quantity_fractional); $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $tax = (double) $product->getTaxesRate($address); $no_tax = Tax::excludeTaxeOption() || !$tax || Group::getPriceDisplayMethod($this->context->customer->id_default_group); $specific_price_output = null; $total = Product::getPriceStatic($this->id_product, !$no_tax, $this->id_product_attribute, 6, null, false, true, $qty, false, $id_customer, null, $address->id, $specific_price_output, true, true, $this->context); $total = PP::calcPrice($total, $quantity, $quantity_fractional, $this->id_product, false); $result = array('status' => 'success', 'total' => &$total); /*[HOOK ppropertiessmartprice]*/ $result['total'] = Tools::ps_round($total, _PS_PRICE_COMPUTE_PRECISION_); } } } if (!isset($result)) { $result = array('status' => 'error'); } die(Tools::jsonEncode($result)); }