function viewAction() { $this->filter(); $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params)); $models = AFActiveDataProvider::models('CampaignProduct', $this->params, $pagination); $dataProvider = $models->getAll(); $camprodModel = new CampaignProduct(); $camprodModel->campaign_id = AF::get($this->params, 'campaign_id', 0); $productsUpsellsMain = $camprodModel->getUpsellProducts(); //eg: Array ( [321] => Array ( [product_id] => 321 [yes_upsell_id] => 0 ) ) //fb($productsUpsellsMain); $arr = array(); foreach ($productsUpsellsMain as $upsellArray) { $arr[] = $upsellArray['yes_upsell_id']; } // $arr[0] = 0 //$upsellModel = new Upsell(); $productsUpsells = array(); while (!empty($arr)) { $upsels = Upsells::getUpsellByArrayIDs($arr); $arr = array(); foreach ($upsels as $item) { $productsUpsells[$item['upsell_id']] = $item; if ($item['yes_upsell_id'] && !isset($productsUpsells[$item['yes_upsell_id']])) { $arr[] = $item['yes_upsell_id']; } if ($item['no_upsell_id'] && !isset($productsUpsells[$item['no_upsell_id']])) { $arr[] = $item['no_upsell_id']; } } } $products = Product::model()->cache()->findAllInArray(); $shippings = Shipping::model()->cache()->findAllInArray(); Assets::js('jquery.form'); $this->addToPageTitle('Campaigns Products'); $this->render('view', array('dataProvider' => $dataProvider, 'pagination' => $pagination, 'models' => $models, 'productsUpsells' => $productsUpsells, 'productsUpsellsMain' => $productsUpsellsMain, 'products' => $products, 'shippings' => $shippings, 'campaign_id' => AF::get($this->params, 'campaign_id'))); }
public function hasUpsells() { // load upsells $campUpsells = new Upsells('Upsell'); $campUpsells->loadUpsellsByCampaignId($this->campaign_id); if (!empty($campUpsells->upsells)) { return true; } else { return false; } }