public function initContent() { if (!$this->listAllowed()) { $this->errors[] = Tools::displayError('An error occurred while retrieving the product information'); } parent::initContent(); }
public function init() { if ($product_rewrite = Tools::getValue('product_rewrite')) { $url_id_pattern = '/.*?([0-9]+)\\-([a-zA-Z0-9-]*)(\\.html)?/'; $lang_id = (int) Context::getContext()->language->id; $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . pSQL(str_replace('.html', '', $product_rewrite)) . '\' AND `id_lang` = ' . $lang_id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } elseif (preg_match($url_id_pattern, $this->request_uri, $url_parts)) { $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `id_product` = \'' . pSQL($url_parts[1]) . '\' AND `id_lang` = ' . $lang_id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } } } parent::init(); }
public function initContent() { $adjacent_products = $this->product->getAdjacentProducts(); $related_artists = $this->product->getRelatedArtists(); $this->context->smarty->assign(array('prev_product' => $adjacent_products['previous'], 'next_product' => $adjacent_products['next'], 'related_artists' => $related_artists)); parent::initContent(); }
public function initContent() { parent::initContent(); if (Configuration::get('PS_EU_PAYMENT_API')) { $instance = new EU_Legal(); Media::addJsDef(array('deliveryNowValue' => $this->product->delivery_now, 'deliveryLaterValue' => $this->product->delivery_later, 'deliveryNoStockValue' => $instance->l('This product is no longer in stock'))); } }
public function initContent() { parent::initContent(); //Module EiCmsLinks : On récupère les liens dynamiques des produits include_once dirname(__FILE__) . '/../../../modules/eicmslinks/eicmslinks.php'; $this->product->description_short = EiCmsLinks::updateCmsLinksDisplay($this->product->description_short); $this->product->description = EiCmsLinks::updateCmsLinksDisplay($this->product->description); $this->context->smarty->assign(array('product' => $this->product)); }
public function initContent() { if (!$this->errors) { $lampStart = 0; $lampLimit = 5; $lampOrderBy = 'id_product'; $lampOrderWay = 'ASC'; $lampOnlyActive = true; $lampIdCategory = 42; $id_lang = (int) $this->context->language->id; $lampIdCategories = CategoryCore::getChildren($lampIdCategory, $id_lang); Product::getProducts($id_lang, $lampStart, $lampLimit, $lampOrderBy, $lampOrderWay, $lampIdCategory, $lampOnlyActive); $prod = $this->product; $this->context->smarty->assign(array('HOOK_LAMP_ACCESSORIES' => Hook::exec('lampAccessories'))); } parent::initContent(); $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl'); }
public function init() { if (Tools::getValue('product_rewrite')) { $rewrite_url = Tools::getValue('product_rewrite'); $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $rewrite_url . '\''); if ($id_product > 0) { $_GET['id_product'] = $id_product; //$_GET['noredirect'] = 1; } else { Tools::display404Error(); die; } } parent::init(); }
public function init() { if (Tools::getValue('product_rewrite')) { //$url_id_pattern = '/[a-zA-Z0-9-]*\/([0-9]+)\-([a-zA-Z0-9-]*)\.html/'; $url_id_pattern = '/.*?([0-9]+)\\-([a-zA-Z0-9-]*)\\.html/'; $rewrite_url = Tools::getValue('product_rewrite'); $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $rewrite_url . '\' AND `id_lang` = ' . Context::getContext()->language->id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } else { if (preg_match($url_id_pattern, $_SERVER['REQUEST_URI'], $url_split)) { $url_id_product = $url_split[1]; $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `id_product` = \'' . $url_id_product . '\' AND `id_lang` = ' . Context::getContext()->language->id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } else { //TODO: Do we need to send 404? header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } } else { //TODO: Do we need to send 404? header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } } } parent::init(); }
public function init() { parent::init(); $pagerCat = FALSE; if (isset($_SERVER['HTTP_REFERER'])) { $parseQuery = explode('id_category=', $_SERVER['HTTP_REFERER']); if (count($parseQuery) == 2) { $parseQuery[1] = (int) $parseQuery[1]; if ($parseQuery[1]) { $pagerCat = $parseQuery[1]; } } } if ((int) Tools::getValue('pagerCat')) { $pagerCat = (int) Tools::getValue('pagerCat'); } if ($pagerCat) { if (Product::idIsOnCategoryId((int) $this->product->id, array(array('id_category' => $pagerCat)))) { $this->category = new Category($pagerCat, (int) $this->context->cookie->id_lang); } } }
/** * Method init() : Initialize product controller with product_rewrite params * * @module now_seo_links * * @see ProductControllerCore::init() */ public function init() { // Get rewrite $sRewrite = Tools::getValue('product_rewrite', false); if ($sRewrite) { $iIdProduct = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $sRewrite . '\' AND `id_lang` = ' . Context::getContext()->language->id); if ($iIdProduct) { $_GET['id_product'] = $iIdProduct; } } parent::init(); // On vérifie si l'URL actuelle est correcte ou pas $goodUrl = Context::getContext()->link->getProductLink($this->product); if (!preg_match('#' . $_SERVER['REDIRECT_URL'] . '#', $goodUrl)) { header('Status: 301 Moved Permanently', false, 301); header('Location: ' . $goodUrl); exit; } }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $flag_pack = true; if (!$this->errors) { // if(!isset($_GET['quick_view'])) // if (Pack::isPack((int)$this->product->id) && !Pack::isInStock((int)$this->product->id)) // if (Pack::isPack((int)$this->product->id)) // $this->product->quantity = 0; // else // $flag_pack = false; // else // $flag_pack = false; if (!Pack::isPack((int) $this->product->id)) { $flag_pack = false; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); // Assign to the template the id of the virtual product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { // If cart has not been saved, we need to do it so that customization fields can have an id_cart // We check that the cookie exists first to avoid ghost carts if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { $this->context->cart->add(); $this->context->cookie->id_cart = (int) $this->context->cart->id; } $this->pictureUpload(); $this->textRecord(); $this->formTargetFormat(); } else { if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.'); } } $pictures = array(); $text_fields = array(); if ($this->product->customizable) { $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); foreach ($files as $file) { $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value']; } $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); foreach ($texts as $text_field) { $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']); } } $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields)); // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax $this->assignPriceAndTax(); // Assign template vars related to the images $this->assignImages(); $this->assign3dImages(); // Assign attribute groups to the template $this->assignAttributesGroups(); // Assign attributes combinations to the template $this->assignAttributesCombinations(); // Pack management $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array(); if (is_array($pack_items) && count($pack_items)) { foreach ($pack_items as &$pack_item) { $pack_item['features'] = Product::getFrontFeaturesStatic($this->context->language->id, $pack_item['id_product']); } } $this->context->smarty->assign('packItems', $pack_items); $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1)); if (isset($this->category->id) && $this->category->id) { $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category)); } else { $return_link = 'javascript: history.back();'; } //reviews // $average = ProductComment::getAverageGrade((int)Tools::getValue('id_product')); $nbComments = (int) ProductComment::getCommentNumber((int) Tools::getValue('id_product')); $act_pack = 0; //паки if (!$flag_pack) { $sql = "SELECT DISTINCT(id_product_pack) FROM " . _DB_PREFIX_ . "pack WHERE id_product_item={$this->product->id}"; $pack_products = array(); $result_packs = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (is_array($result_packs) && count($result_packs)) { foreach ($result_packs as $k => $id_product_pack) { $prod = new Product($id_product_pack['id_product_pack'], $this->context->language->id, true); $cover = $prod->getCover((int) $prod->id); if ($cover) { $pack_products[$k]['id_image'] = $cover['id_image']; } else { $pack_products[$k]['id_image'] = null; } $price = $prod->getPrice(true, null, 2); $price_old = $prod->getPriceWithoutReduct(false, null, 2); if (isset($prod->specificPrice) && is_array($prod->specificPrice)) { $pack_products[$k]['sale_percentage'] = $prod->specificPrice['reduction_type'] == 'percentage' ? $prod->specificPrice['reduction'] * 100 : $prod->specificPrice['reduction'] / $price_old * 100; } $pack_products[$k]['active'] = $prod->active; if ($prod->active) { $act_pack = 1; } $pack_products[$k]['count_reviews'] = (int) ProductComment::getCommentNumber((int) $prod->id); $pack_products[$k]['star_reviews'] = ProductComment::getRatings((int) $prod->id); $pack_products[$k]['price'] = $price; $pack_products[$k]['price_old'] = $price_old; $pack_products[$k]['on_sale'] = (bool) ($price != $price_old); $pack_products[$k]['id_product_pack'] = $prod->id; $pack_products[$k]['link'] = $this->context->link->getProductLink($prod); $pack_products[$k]['name'] = $prod->name; $pack_products[$k]['link_rewrite'] = $prod->link_rewrite; $pack_products[$k]['items'] = Pack::getItemTable($prod->id, $this->context->language->id, true); unset($prod); } } } else { $pack_products = null; } //var_dump($pack_products);exit(); //текстовой блок доставка $cms_block = ''; $cms = new CMS($this->block_cms_id, $this->context->language->id); if (is_object($cms)) { $cms_block = $cms->content; } $sql = "SELECT id_category FROM ps_category_product WHERE id_product={$this->product->id}"; $result_cats = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $params_image = null; foreach ($result_cats as $cat) { $params_image = file_exists(_PS_IMG_DIR_ . '/c_icon/' . $cat['id_category'] . '.png') ? '/img/c_icon/' . $cat['id_category'] . '.png' : null; if (!$params_image) { $params_image = file_exists(_PS_IMG_DIR_ . '/c_icon/' . $cat['id_category'] . '.jpg') ? '/img/c_icon/' . $cat['id_category'] . '.jpg' : null; } if ($params_image) { break; } } //{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if} $this->context->smarty->assign(array('is_bestsaler' => ProductSale::isBestsaler($this->product->id), 'og_type' => 'product', 'params_image' => $params_image, 'cms_block' => $cms_block, 'pack_products' => $pack_products, 'act_pack' => $act_pack, 'url' => $this->context->link->getProductLink($this->product), 'minimal_quantity' => $this->product->minimal_quantity > 1 ? $this->product->minimal_quantity : 1, 'nbComments' => $nbComments, 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'))); } if (isset($_GET['quick_view'])) { $this->ajax = true; if ($flag_pack) { $this->setTemplate(_PS_THEME_DIR_ . 'preview_pack.tpl'); } else { $this->setTemplate(_PS_THEME_DIR_ . 'preview.tpl'); } } else { if ($flag_pack) { $this->setTemplate(_PS_THEME_DIR_ . 'product-pack.tpl'); } else { $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl'); } } }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (!$this->errors) { if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); /* Получаем остатки по складам и передаем в Smarty * TODO - вынести в отдельный модуль * TODO - если надо, добавить обработку атрибутов (товары, отличающиеся цветом, размером и т.д.) * TODO - real_quantity - количество, в котором есть будущие поставки. Если это не нужно, считать по-другому */ $all_warehouses = Warehouse::getWarehouses(true); if ($all_warehouses) { $wh_stock = array(); //ppp($all_warehouses); foreach ($all_warehouses as $warehouse) { $id_warehouse = $warehouse['id_warehouse']; $warehouse = new Warehouse($id_warehouse); $manager = StockManagerFactory::getManager(); $real_quantity = $manager->getProductRealQuantities((int) $this->product->id, 0, $id_warehouse, true); if ($real_quantity > 0) { $wh_stock[$id_warehouse]['real_quantity'] = $real_quantity; /* ppp("остаток: "); ppp($real_quantity); */ $address = new Address($warehouse->id_address); $wh_stock[$id_warehouse]['country'] = $address->country; $wh_stock[$id_warehouse]['address1'] = $address->address1; $wh_stock[$id_warehouse]['address2'] = $address->address2; $wh_stock[$id_warehouse]['postcode'] = $address->postcode; $wh_stock[$id_warehouse]['city'] = $address->city; $wh_stock[$id_warehouse]['phone'] = $address->phone; $wh_stock[$id_warehouse]['reference'] = $warehouse->reference; //ppp($address); } } $this->context->smarty->assign('wh_stock', $wh_stock); } /* Конец получения остатков по складам */ // Assign to the template the id of the virtual product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { // If cart has not been saved, we need to do it so that customization fields can have an id_cart // We check that the cookie exists first to avoid ghost carts if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { $this->context->cart->add(); $this->context->cookie->id_cart = (int) $this->context->cart->id; } $this->pictureUpload(); $this->textRecord(); $this->formTargetFormat(); } else { if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.'); } } $pictures = array(); $text_fields = array(); if ($this->product->customizable) { $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); foreach ($files as $file) { $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value']; } $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); foreach ($texts as $text_field) { $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']); } } $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields)); // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax $this->assignPriceAndTax(); // Assign template vars related to the images $this->assignImages(); // Assign attribute groups to the template $this->assignAttributesGroups(); // Assign attributes combinations to the template $this->assignAttributesCombinations(); // Pack management $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array(); $this->context->smarty->assign('packItems', $pack_items); $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1)); if (isset($this->category->id) && $this->category->id) { $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category)); } else { $return_link = 'javascript: history.back();'; } $features = $this->product->getFrontFeatures($this->context->language->id); if ($this->context->language->id != 1) { foreach ($features as &$feature) { if ($feature['id_feature'] == 9) { $feature['value'] = Tools::rus2translit($feature['value']); } } } $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $features, 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'))); } $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl'); }