예제 #1
0
 /**
  * Add product to compare list
  * @param $id StoreProduct id
  */
 public function actionAdd($id)
 {
     $this->model->add($id);
     $this->addFlashMessage(Yii::t('StoreModule.core', 'Продукт успешно добавлен в список сравнения.'));
     if (!Yii::app()->request->isAjaxRequest) {
         $this->redirect($this->createUrl('index'));
     }
 }
 public function testCompare()
 {
     Yii::import('application.modules.shop.components.SCompareProducts');
     $product = ShopProduct::model()->active()->find();
     $model = new SCompareProducts();
     $this->assertTrue($model->session instanceof ArrayAccess);
     $this->assertTrue(is_array($model->getIds()));
     $this->assertTrue($model->add($product->id));
     $this->assertFalse($model->add(time()));
     $this->assertNotEmpty($model->getIds());
     $this->assertTrue($model->count() === 1);
     $products = $model->getProducts();
     $this->assertNotEmpty($products);
     $this->assertTrue($products[0] instanceof ShopProduct);
     $this->assertTrue(is_array($model->getAttributes()));
     $model->clear();
     $this->assertEmpty($model->getIds());
     // Removing
     $this->assertTrue($model->add($product->id));
     $model->remove($product->id);
     $this->assertEmpty($model->getIds());
 }