public function initContent() { parent::initContent(); $shop = NULL; $alias_offer = (int) Tools::getValue('aof'); if (!empty($alias_offer)) { $_o = AphOffer::getByAlias($alias_offer, Context::getContext()->language->id); $id_offer = $_o['id_offer']; } else { $id_offer = (int) Tools::getValue('ido'); } $offer = new AphOffer($id_offer, Context::getContext()->language->id); $offer->new_price = $offer->price_wt < 0 ? $offer->reduction_type == 'percentage' ? '-' . intval($offer->reduction * 100) . '%' : '-' . Tools::displayPrice($offer['reduction'], (int) Context::getContext()->currency->id) : Tools::displayPrice($offer->price_wt, (int) Context::getContext()->currency->id) . ' '; $cover = NULL; $images = AphOfferImage::getImages(Context::getContext()->language->id, $id_offer); foreach ($images as &$image) { if (!empty($image['cover'])) { $cover = $image; } } if (empty($cover) && !empty($images)) { $cover = $images[0]; } $this->context->smarty->tpl_vars['meta_title']->value = $offer->name; $this->context->smarty->tpl_vars['meta_description']->value = $offer->meta_description; $shops = AphOffer::getShopsLight(Context::getContext()->language->id, $offer->id); foreach ($shops as &$shop) { $shop['link'] = Context::getContext()->link->getModuleLink('blockshops', 'shop', array('ash' => $shop['uri'], 'ids' => $shop['id_shop'])); } /*$products = AphOffer::getProductsLight(Context::getContext()->language->id, $offer->id); foreach ($products as &$product) { $product['link'] = Context::getContext()->link->getProductLink((int)$product['id_product'], $product['link_rewrite']); }*/ $products_by_category = array(); $ps = AphOffer::getProductsLight(Context::getContext()->language->id, $offer->id); foreach ($ps as &$p) { $product = new Product($p['id_product'], false, Context::getContext()->language->id); $category = new Category($product->id_category_default, Context::getContext()->language->id); if (empty($products_by_category[$category->id])) { $products_by_category[$category->id] = array('id_category' => $category->id, 'name' => $category->name, 'class' => Tools::link_rewrite($category->name), 'products' => array()); } $products_by_category[$category->id]['products'][$product->id] = array('id_product' => $product->id, 'name' => $product->name, 'link' => Context::getContext()->link->getProductLink((int) $product->id, $product->link_rewrite, $category->id, $product->ean13)); } $this->context->smarty->assign(array('offer' => $offer, 'cover' => $cover, 'images' => $images, 'shops' => $shops, 'products_by_category' => $products_by_category)); $this->setTemplate('offer.tpl'); }
/** * @param Offer $obj * @throws Exception * @throws PrestaShopException * @throws SmartyException */ public function initFormShops($obj) { $offer = $obj; $data = $this->createTemplate($this->tpl_form); // Selected shops $selected_shops = array(); $shops = AphOffer::getShopsLight($this->context->language->id, $offer->id); if (!empty($shops)) { foreach ($shops as $shop) { $selected_shops[] = $shop['id_shop']; } } // Generate category selection tree $tree = new HelperTreeShops('shops-tree', $this->l('Seleziona negozio')); $tree->setNodeFolderTemplate('tree_node_folder.tpl'); $tree->setAttribute('selected_shops', $selected_shops); $tree->setSelectedShops($selected_shops); $data->assign('shop_tree', $tree->render()); $data->assign(array('offer' => $offer, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP)); $this->tpl_form_vars['custom_form'] = $data->fetch(); }