public function displayContent($params) { $alias_shop = (int) Tools::getValue('ash'); if (!empty($alias_shop)) { $_s = AphStore::getByAlias($alias_shop, Context::getContext()->language->id); $id_shop = $_s['id_shop']; } else { $id_shop = (int) Tools::getValue('ids'); } $shop = new AphStore($id_shop, Context::getContext()->language->id); $this->nbOffers = AphOffer::getOffers('store', $id_shop, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->orderBy, $this->orderWay, true); $this->pagination((int) $this->nbOffers); // Pagination must be call after "getStoresByProduct" $this->offerSort(); $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT'); $offers = AphOffer::getOffers('store', $id_shop, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->orderBy, $this->orderWay); foreach ($offers as &$offer) { $offer = new AphOffer($offer['id_offer'], (int) Context::getContext()->language->id, (int) $id_shop); $offer['price_from'] = Tools::displayPrice($offer->price_wt, $id_currency); error_log($o->reduction . ' ' . $o->id); $offer['new_price'] = $o->price_wt < 0 ? $o->reduction_type == 'percentage' ? '-' . intval(round($o->reduction)) . '%' : '-' . Tools::displayPrice($o['reduction'], (int) Context::getContext()->currency->id) : Tools::displayPrice($o->price_wt, (int) Context::getContext()->currency->id) . ' '; $offer['url'] = Context::getContext()->link->getModuleLink('blockoffers', 'offer', array('aof' => $offer['link_rewrite'], 'ido' => $offer['id_offer'])); $offer['img_link_rewrite'] = Tools::link_rewrite($offer['legend']); } $this->context->smarty->assign(array('offers' => $offers, 'nb_offers' => $this->nbOffers)); $this->context->controller->addJS($this->_path . 'blockoffer.js'); return $this->display(__FILE__, 'blockoffers.tpl', $this->getCacheId()); }
public function initContent() { parent::initContent(); $this->module->nbOffers = AphOffer::getOffers(NULL, NULL, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->module->orderBy, $this->module->orderWay, true); $this->module->pagination((int) $this->module->nbOffers); // Pagination must be call after "getStoresByProduct" $this->module->offerSort(); $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT'); $offers = AphOffer::getOffers(NULL, NULL, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->module->orderBy, $this->module->orderWay); foreach ($offers as &$offer) { $o = new AphOffer($offer['id_offer'], (int) Context::getContext()->language->id, (int) $id_shop); $offer['description_short'] = $o->description_short; $offer['available_from_date'] = $o->available_from_date; $offer['available_to_date'] = $o->available_to_date; $offer['price_from'] = Tools::displayPrice($o->price_wt, $id_currency); $offer['new_price'] = $o->price_wt < 0 ? $o->reduction_type == 'percentage' ? '-' . intval(round($o->reduction)) . '%' : '-' . Tools::displayPrice($o->reduction, (int) Context::getContext()->currency->id) : Tools::displayPrice($o->price_wt, (int) Context::getContext()->currency->id) . ' '; $offer['url'] = Context::getContext()->link->getModuleLink('blockoffers', 'offer', array('aof' => $offer['link_rewrite'], 'ido' => $offer['id_offer'])); $offer['img_link_rewrite'] = Tools::link_rewrite($offer['legend']); } $this->context->smarty->assign(array('offers' => $offers, 'nb_offers' => $this->module->nbOffers)); $this->context->controller->addJS('blockoffers.js'); $this->setTemplate('blockoffers.tpl'); }