Ejemplo n.º 1
0
 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');
 }