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 hookDisplayProductPriceBlock($param) { if (!isset($param['product']) || !isset($param['type'])) { return; } $product = $param['product']; if (is_array($product)) { $product_repository = $this->entity_manager->getRepository('Product'); $product = $product_repository->findOne((int) $product['id_product']); } if (!Validate::isLoadedObject($product)) { return; } $smartyVars = array(); /* Handle Product Combinations label */ if ($param['type'] == 'before_price' && (bool) Configuration::get('AEUC_LABEL_SPECIFIC_PRICE') === true) { if ($product->hasAttributes()) { $need_display = false; $combinations = $product->getAttributeCombinations($this->context->language->id); if ($combinations && is_array($combinations)) { foreach ($combinations as $combination) { if ((double) $combination['price'] > 0) { $need_display = true; break; } } unset($combinations); if ($need_display) { $smartyVars['before_price'] = array(); $smartyVars['before_price']['from_str_i18n'] = $this->l('From', 'advancedeucompliance'); return $this->dumpHookDisplayProductPriceBlock($smartyVars); } } return; } } /* Handle Specific Price label*/ if ($param['type'] == 'old_price' && (bool) Configuration::get('AEUC_LABEL_SPECIFIC_PRICE') === true) { $smartyVars['old_price'] = array(); $smartyVars['old_price']['before_str_i18n'] = $this->l('Before', 'advancedeucompliance'); return $this->dumpHookDisplayProductPriceBlock($smartyVars); } /* Handle taxes Inc./Exc. and Shipping Inc./Exc.*/ if ($param['type'] == 'price') { $smartyVars['price'] = array(); $need_shipping_label = true; if ((bool) Configuration::get('AEUC_LABEL_TAX_INC_EXC') === true) { if ((bool) Configuration::get('PS_TAX') === true) { $smartyVars['price']['tax_str_i18n'] = $this->l('Tax included', 'advancedeucompliance'); } else { $smartyVars['price']['tax_str_i18n'] = $this->l('Tax excluded', 'advancedeucompliance'); } if (isset($param['from']) && $param['from'] == 'blockcart') { $smartyVars['price']['css_class'] = 'aeuc_tax_label_blockcart'; $need_shipping_label = false; } } if ((bool) Configuration::get('AEUC_LABEL_SHIPPING_INC_EXC') === true && $need_shipping_label === true) { if (!$product->is_virtual) { $cms_role_repository = $this->entity_manager->getRepository('CMSRole'); $cms_repository = $this->entity_manager->getRepository('CMS'); $cms_page_associated = $cms_role_repository->findOneByName(Advancedeucompliance::LEGAL_SHIP_PAY); if (isset($cms_page_associated->id_cms) && $cms_page_associated->id_cms != 0) { $cms_ship_pay_id = (int) $cms_page_associated->id_cms; $cms_revocations = $cms_repository->i10nFindOneById($cms_ship_pay_id, $this->context->language->id, $this->context->shop->id); $is_ssl_enabled = (bool) Configuration::get('PS_SSL_ENABLED'); $link_ship_pay = $this->context->link->getCMSLink($cms_revocations, $cms_revocations->link_rewrite, $is_ssl_enabled); if (!strpos($link_ship_pay, '?')) { $link_ship_pay .= '?content_only=1'; } else { $link_ship_pay .= '&content_only=1'; } $smartyVars['ship'] = array(); $smartyVars['ship']['link_ship_pay'] = $link_ship_pay; $smartyVars['ship']['ship_str_i18n'] = $this->l('Shipping excluded', 'advancedeucompliance'); $smartyVars['ship']['js_ship_fancybx'] = '<script type="text/javascript"> $(document).ready(function(){ if (!!$.prototype.fancybox) $("a.iframe").fancybox({ "type": "iframe", "width": 600, "height": 600 }); }) </script>'; } } } return $this->dumpHookDisplayProductPriceBlock($smartyVars); } /* Handles product's weight */ if ($param['type'] == 'weight' && (bool) Configuration::get('PS_DISPLAY_PRODUCT_WEIGHT') === true && isset($param['hook_origin']) && $param['hook_origin'] == 'product_sheet') { if ((double) $product->weight) { $smartyVars['weight'] = array(); $rounded_weight = round((double) $product->weight, Configuration::get('PS_PRODUCT_WEIGHT_PRECISION')); $smartyVars['weight']['rounded_weight_str_i18n'] = $rounded_weight . ' ' . Configuration::get('PS_WEIGHT_UNIT'); return $this->dumpHookDisplayProductPriceBlock($smartyVars); } } /* Handle Estimated delivery time label */ if ($param['type'] == 'after_price') { $context_id_lang = $this->context->language->id; $is_product_available = Product::getRealQuantity($product->id) >= 1 ? true : false; $smartyVars['after_price'] = array(); if ($is_product_available) { $contextualized_content = Configuration::get('AEUC_LABEL_DELIVERY_TIME_AVAILABLE', (int) $context_id_lang); $smartyVars['after_price']['delivery_str_i18n'] = $contextualized_content; } else { $contextualized_content = Configuration::get('AEUC_LABEL_DELIVERY_TIME_OOS', (int) $context_id_lang); $smartyVars['after_price']['delivery_str_i18n'] = $contextualized_content; } return $this->dumpHookDisplayProductPriceBlock($smartyVars); } return; }
/** * @param \Product $product * * @return bool * @throws \Exception * @author Panagiotis Vagenas <*****@*****.**> * @since 150213 */ protected function getAvailabilityString(\Product &$product) { $hasStock = $product->getRealQuantity($product->id) > 0; // If product is in stock if ($hasStock) { return $this->Options->availOptions[$this->Options->getValue('avail_inStock')]; } elseif ($this->backOrdersAllowed($product)) { // if product is out of stock and no backorders then return false if ($this->Options->getValue('avail_backorders') == 0) { return false; } // else return value return $this->Options->availOptions[$this->Options->getValue('avail_backorders') - 1]; } elseif ($this->Options->getValue('avail_outOfStock') > 0) { // no stock, no backorders but must include product. Return value return $this->Options->availOptions[$this->Options->getValue('avail_outOfStock') - 1]; } return false; }
/** * @param \Product $product * * @return bool * @throws \Exception * @author Panagiotis Vagenas <*****@*****.**> * @since 150213 */ protected function getAvailabilityString(\Product &$product) { $hasStock = $product->getRealQuantity($product->id) > 0; $out = false; // If product is in stock if ($hasStock) { $out = $this->Options->getValue('avail_inStock'); } elseif ($this->backOrdersAllowed($product)) { $backOrdersString = $this->Options->getValue('avail_backorders'); if ($this->String->is_not_empty($backOrdersString)) { $out = $backOrdersString; } } else { $outOfStockString = $this->Options->getValue('avail_outOfStock'); if ($this->String->is_not_empty($outOfStockString)) { $out = $outOfStockString; } } return $out; }