public function testProductDuplicate()
 {
     $model = StoreProduct::model()->find();
     $duplicator = new SProductsDuplicator();
     $clone = $duplicator->duplicateProduct($model);
     $this->assertEquals($clone->name, $model->name . $duplicator->getSuffix());
 }
Exemplo n.º 2
0
 /**
  * Check creating new orders
  */
 public function testCreateOrder()
 {
     $microTime = microtime();
     $comment = 'test comment ' . $microTime;
     // Find any active product
     $product = StoreProduct::model()->active()->findByAttributes(array('use_configurations' => 0));
     $this->assertTrue($product instanceof StoreProduct);
     // Open product page and add to cart
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->click("//input[@id='buyButton']");
     $this->open('cart');
     $this->assertTrue($this->isTextPresent($product->name));
     $this->click('css=label.radio > span');
     $this->type('id=OrderCreateForm_name', 'Tester Name');
     $this->type('id=OrderCreateForm_email', '*****@*****.**');
     $this->type('id=OrderCreateForm_phone', '0990000000');
     $this->type('id=OrderCreateForm_address', 'test address');
     $this->type('id=OrderCreateForm_comment', $comment);
     $this->clickAtAndWait('name=create');
     // Check if order successfully saved
     $order = Order::model()->findByAttributes(array('user_comment' => $comment));
     $this->assertTrue($order instanceof Order);
     // Check of ordered products
     $this->assertTrue($order->getOrderedProducts() instanceof CActiveDataProvider);
     $this->assertTrue($order->getOrderedProducts()->getTotalItemCount() > 0);
 }
Exemplo n.º 3
0
 public function testSWishlist()
 {
     Yii::import('application.modules.store.components.SWishList');
     $product = StoreProduct::model()->active()->find();
     $user = User::model()->find();
     $this->assertTrue($user instanceof User);
     $this->assertTrue($product instanceof $product);
     $model = new SWishList($user->id);
     $this->assertTrue(is_array($model->getIds()));
     // Add right product if
     $this->assertTrue($model->add($product->id));
     // Add wrong product id
     $this->assertFalse($model->add(time()));
     // Check if product added
     $this->assertNotEmpty($model->getIds());
     $this->assertTrue($model->count() >= 1);
     // Check products loading and we have at least one product
     $products = $model->getProducts();
     $this->assertNotEmpty($products);
     $this->assertTrue($products[0] instanceof StoreProduct);
     // Clear all
     $model->clear();
     $this->assertEmpty($model->getIds());
     // Removing
     $this->assertTrue($model->add($product->id));
     $model->remove($product->id);
     $this->assertEmpty($model->getIds());
 }
Exemplo n.º 4
0
 /**
  * @param array $attributes
  */
 public function export(array $attributes)
 {
     $this->rows[0] = $attributes;
     foreach ($this->rows[0] as &$v) {
         if (substr($v, 0, 4) === 'eav_') {
             $v = substr($v, 4);
         }
     }
     $limit = 10;
     $total = ceil(StoreProduct::model()->count() / $limit);
     $offset = 0;
     for ($i = 0; $i <= $total; ++$i) {
         $products = StoreProduct::model()->findAll(array('limit' => $limit, 'offset' => $offset));
         foreach ($products as $p) {
             $row = array();
             foreach ($attributes as $attr) {
                 if ($attr === 'category') {
                     $value = $this->getCategory($p);
                 } elseif ($attr === 'manufacturer') {
                     $value = $this->getManufacturer($p);
                 } elseif ($attr === 'image') {
                     $value = $p->mainImage ? $p->mainImage->name : '';
                 } elseif ($attr === 'additionalCategories') {
                     $value = $this->getAdditionalCategories($p);
                 } else {
                     $value = $p->{$attr};
                 }
                 $row[$attr] = $value;
             }
             array_push($this->rows, $row);
         }
         $offset += $limit;
     }
     $this->proccessOutput();
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = StoreProduct::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 6
0
 /**
  * @return boolean
  */
 public function afterSave()
 {
     $this->order->updateTotalPrice();
     $this->order->updateDeliveryPrice();
     if ($this->isNewRecord) {
         $product = StoreProduct::model()->findByPk($this->product_id);
         $product->decreaseQuantity();
     }
     return parent::afterSave();
 }
 public function testCompareIsWorkingOk()
 {
     $product = StoreProduct::model()->active()->find();
     $this->assertTrue($product instanceof StoreProduct);
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->clickAndWait('css=div.silver_clean.silver_button > button');
     $this->assertTrue($this->isTextPresent('Продукт успешно добавлен в список сравнения'));
     $this->clickAndWait('xpath=//a[contains(.,"Товары на сравнение")]');
     $this->assertTrue($this->isTextPresent(str_replace('  ', ' ', $product->name)));
     $this->clickAndWait('link=Удалить');
     $this->assertTrue($this->isTextPresent('Нет результатов'));
 }
Exemplo n.º 8
0
 /**
  * Import default demo data
  */
 private function importCsvFiles()
 {
     $files = array('laptops', 'computer_sound', 'monitors', 'phones', 'tablets');
     foreach ($files as $file) {
         $importer = new CsvImporter();
         $importer->file = Yii::getPathOfAlias('application.modules.install.data') . DIRECTORY_SEPARATOR . $file . '.csv';
         if ($importer->validate() && !$importer->hasErrors()) {
             $importer->import();
         }
     }
     StoreProduct::model()->updateAll(array('is_active' => 1));
 }
Exemplo n.º 9
0
 public function testTitle()
 {
     Yii::app()->settings->set('core', array('siteName' => microtime()));
     $this->open('/');
     $this->assertEquals(Yii::app()->settings->get('core', 'siteName'), $this->getTitle());
     // Find any active product
     $product = StoreProduct::model()->active()->find();
     $this->assertTrue($product instanceof StoreProduct);
     // Open product page
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->assertEquals($product->name . ' / ' . Yii::app()->settings->get('core', 'siteName'), $this->getTitle());
 }
Exemplo n.º 10
0
 /**
  * Creates copy of many products.
  *
  * @param array $ids of products to make copy
  * @param array $duplicate list of product parts to copy: images, variants, etc...
  * @return array of new product ids
  */
 public function createCopy(array $ids, array $duplicate = array())
 {
     $this->duplicate = $duplicate;
     $new_ids = array();
     foreach ($ids as $id) {
         $model = StoreProduct::model()->findByPk($id);
         if ($model) {
             $new_ids[] = $this->duplicateProduct($model)->id;
         }
     }
     return $new_ids;
 }
Exemplo n.º 11
0
 /**
  * Add new email to list
  */
 public function actionIndex()
 {
     $product = StoreProduct::model()->findByPk(Yii::app()->request->getPost('product_id'));
     if (!$product) {
         throw new CHttpException(404);
     }
     $record = new ProductNotifications();
     $record->attributes = array('email' => $_POST['email']);
     $record->product_id = $product->id;
     if ($record->validate() && $record->hasEmail() === false) {
         $record->save();
     }
 }
Exemplo n.º 12
0
 /**
  * Rate product
  * @param integer $id product id
  */
 public function actionRateProduct($id)
 {
     $request = Yii::app()->request;
     if ($request->isAjaxRequest) {
         $model = StoreProduct::model()->active()->findByPk($id);
         $cookieName = 'rating_' . $model->id;
         $rating = (int) $_GET['rating'];
         if ($model && in_array($rating, array(1, 2, 3, 4, 5))) {
             $model->saveCounters(array('votes' => 1, 'rating' => $rating));
             $cookie = new CHttpCookie($cookieName, true);
             $cookie->expire = time() + 60 * 60 * 24 * 60;
             Yii::app()->request->cookies[$cookieName] = $cookie;
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Check creating new comment
  */
 public function testCreateComment()
 {
     // Find any active product
     $product = StoreProduct::model()->active()->find();
     $this->assertTrue($product instanceof StoreProduct);
     $email = '*****@*****.**';
     $text = 'this is test comment' . microtime();
     // Open product page and post comment
     $this->open(Yii::app()->createAbsoluteUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->type('id=Comment_name', 'tester');
     $this->type('id=Comment_email', $email);
     $this->type('id=Comment_text', $text);
     $this->clickAndWait("//input[@value='Отправить']");
     $this->open(Yii::app()->createAbsoluteUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->assertTrue($this->isTextPresent('Ваш комментарий успешно добавлен. Он будет опубликован после проверки администратором.'));
     $this->adminLogin();
     $this->open('/admin/store/products/update?id=' . $product->id);
     $this->click('xpath=//a[contains(.,"Отзывы")]');
     $this->assertTrue($this->isTextPresent($email));
     $this->assertTrue($this->isTextPresent($text));
 }
Exemplo n.º 14
0
 /**
  * @static
  * @param $type
  * @param $externalId
  * @param bool $loadModel
  */
 public static function getObject($type, $externalId, $loadModel = true)
 {
     $query = Yii::app()->db->createCommand()->select("*")->from('accounting1c')->where('object_type=:type AND external_id=:externalId', array(':type' => $type, ':externalId' => $externalId))->limit(1)->queryRow();
     if ($query === false) {
         return false;
     }
     if ($loadModel === true && $query['object_id']) {
         switch ($type) {
             case self::OBJECT_TYPE_CATEGORY:
                 return StoreCategory::model()->findByPk($query['object_id']);
                 break;
             case self::OBJECT_TYPE_ATTRIBUTE:
                 return StoreAttribute::model()->findByPk($query['object_id']);
                 break;
             case self::OBJECT_TYPE_PRODUCT:
                 return StoreProduct::model()->findByPk($query['object_id']);
                 break;
         }
     }
     return $query['object_id'];
 }
Exemplo n.º 15
0
 /**
  * Get data to render dropdowns for configurable product.
  * Used on product view.
  * array(
  *      'attributes' // Array of StoreAttribute models used for configurations
  *      'prices'     // Key/value array with configurations prices array(product_id=>price)
  *      'data'       // Array to render dropdowns. array(color=>array('Green'=>'1/3/5/', 'Silver'=>'7/'))
  * )
  * @todo Optimize. Cache queries.
  * @return array
  */
 public function getConfigurableData()
 {
     $attributeModels = StoreAttribute::model()->findAllByPk($this->model->configurable_attributes);
     $models = StoreProduct::model()->findAllByPk($this->model->configurations);
     $data = array();
     $prices = array();
     foreach ($attributeModels as $attr) {
         foreach ($models as $m) {
             $prices[$m->id] = $m->price;
             if (!isset($data[$attr->name])) {
                 $data[$attr->name] = array('---' => '0');
             }
             $method = 'eav_' . $attr->name;
             $value = $m->{$method};
             if (!isset($data[$attr->name][$value])) {
                 $data[$attr->name][$value] = '';
             }
             $data[$attr->name][$value] .= $m->id . '/';
         }
     }
     return array('attributes' => $attributeModels, 'prices' => $prices, 'data' => $data);
 }
Exemplo n.º 16
0
 public function testAccounting1cImport()
 {
     Yii::import('application.modules.accounting1c.components.C1ProductsImport');
     $tempDir = Yii::getPathOfAlias(Yii::app()->settings->get('accounting1c', 'tempdir'));
     $importXml = Yii::getPathOfAlias('application.modules.accounting1c.tests.data') . DIRECTORY_SEPARATOR . 'import.xml';
     $offersXml = Yii::getPathOfAlias('application.modules.accounting1c.tests.data') . DIRECTORY_SEPARATOR . 'offers.xml';
     copy($importXml, $tempDir . DIRECTORY_SEPARATOR . 'import.xml');
     copy($offersXml, $tempDir . DIRECTORY_SEPARATOR . 'offers.xml');
     $_GET['filename'] = 'import.xml';
     ob_start();
     C1ProductsImport::processRequest('catalog', 'import');
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertTrue(trim($result) == 'success');
     // Offers
     $_GET['filename'] = 'offers.xml';
     ob_start();
     C1ProductsImport::processRequest('catalog', 'import');
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertTrue(trim($result) == 'success');
     $import = new C1ProductsImport();
     $xml = $import->getXml('import.xml');
     $this->assertTrue($xml instanceof SimpleXMLElement);
     foreach ($xml->{"Каталог"}->{"Товары"}->{"Товар"} as $product) {
         $cr = new CDbCriteria();
         $cr->condition = 'translate.name=:name';
         $cr->params = array(':name' => $product->{"Наименование"});
         $model = StoreProduct::model()->applyTranslateCriteria()->find($cr);
         $this->assertTrue($model->name == $product->{"Наименование"});
     }
     // Check attribute
     $model = StoreProduct::model()->findByAttributes(array('sku' => 'VAX-8002'));
     $attr = 'eav_kod_virobnika';
     $this->assertTrue($model->{$attr} == 'VAX-8002');
     $this->assertTrue($model->price == '9');
     // Check category
     $this->assertTrue($model->mainCategory->name == 'Сумки для цифрового обладнання');
 }
Exemplo n.º 17
0
 public function testCompare()
 {
     Yii::import('application.modules.store.components.SCompareProducts');
     $product = StoreProduct::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 StoreProduct);
     $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());
 }
 public function testWishlist()
 {
     Yii::import('application.modules.store.models.wishlist.*');
     $wishlist = StoreWishlist::model()->find();
     $product = StoreProduct::model()->active()->find();
     $this->assertTrue($product instanceof StoreProduct);
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->clickAndWait('xpath=//button[contains(.,"Список желаний")]');
     $this->assertTrue($this->isTextPresent('Авторизация'));
     $this->type('id=UserLoginForm_username', 'admin');
     $this->type('id=UserLoginForm_password', 'admin');
     // Click on login button
     $this->clickAndWait('css=input.blue_button');
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->assertTrue($this->isTextPresent('Список желаний'));
     $this->clickAndWait('xpath=//button[contains(.,"Список желаний")]');
     $this->assertTrue($this->isTextPresent('Продукт успешно добавлен в список желаний.'));
     $this->assertTrue($this->isTextPresent(str_replace('  ', ' ', $product->name)));
     // View wishlist view
     $this->open(Yii::app()->createAbsoluteUrl('/store/wishlist/view', array('key' => $wishlist->key)));
     $this->assertTrue($this->isTextPresent('Список желаний'));
     $this->assertTrue($this->isTextPresent($product->name));
 }
Exemplo n.º 19
0
 /**
  * Validate POST data and add product to cart
  */
 public function actionAdd()
 {
     $variants = array();
     // Load product model
     $model = StoreProduct::model()->active()->findByPk(Yii::app()->request->getPost('product_id', 0));
     // Check product
     if (!isset($model)) {
         $this->_addError(Yii::t('OrdersModule.core', 'Ошибка. Продукт не найден'), true);
     }
     // Update counter
     $model->saveCounters(array('added_to_cart_count' => 1));
     // Process variants
     if (!empty($_POST['eav'])) {
         foreach ($_POST['eav'] as $attribute_id => $variant_id) {
             if (!empty($variant_id)) {
                 // Check if attribute/option exists
                 if (!$this->_checkVariantExists($_POST['product_id'], $attribute_id, $variant_id)) {
                     $this->_addError(Yii::t('OrdersModule.core', 'Ошибка. Вариант продукта не найден.'));
                 } else {
                     array_push($variants, $variant_id);
                 }
             }
         }
     }
     // Process configurable products
     if ($model->use_configurations) {
         // Get last configurable item
         $configurable_id = Yii::app()->request->getPost('configurable_id', 0);
         if (!$configurable_id || !in_array($configurable_id, $model->configurations)) {
             $this->_addError(Yii::t('OrdersModule.core', 'Ошибка. Выберите вариант продукта.'), true);
         }
     } else {
         $configurable_id = 0;
     }
     Yii::app()->cart->add(array('product_id' => $model->id, 'variants' => $variants, 'configurable_id' => $configurable_id, 'quantity' => (int) Yii::app()->request->getPost('quantity', 1), 'price' => $model->price));
     $this->_finish();
 }
Exemplo n.º 20
0
 /**
  * Delete attribute
  * @param array $id
  */
 public function actionDelete($id = array())
 {
     if (Yii::app()->request->isPostRequest) {
         $model = StoreAttribute::model()->findAllByPk($_REQUEST['id']);
         if (!empty($model)) {
             foreach ($model as $m) {
                 $count = StoreProduct::model()->withEavAttributes(array($m->name))->count();
                 if ($count) {
                     throw new CHttpException(503, Yii::t('StoreModule.admin', 'Ошибка удаления атрибута - он используется продуктами.'));
                 }
                 $m->delete();
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('index');
         }
     }
 }
Exemplo n.º 21
0
 /**
  * Create/update product from key=>value array
  * @param $data array of product attributes
  */
 protected function importRow($data)
 {
     if (!isset($data['category']) || empty($data['category'])) {
         $data['category'] = 'root';
     }
     $newProduct = false;
     $category_id = $this->getCategoryByPath($data['category']);
     // Search product by name, category
     // or create new one
     $cr = new CDbCriteria();
     $cr->with = array('translate');
     if (isset($data['url']) && !empty($data['url']) && $data['url'] != '') {
         $cr->compare('t.url', $data['url']);
     }
     if (isset($data['sku']) && !empty($data['sku']) && $data['sku'] != '') {
         $cr->compare('t.sku', $data['sku']);
     } else {
         $cr->compare('translate.name', $data['name']);
     }
     $model = StoreProduct::model()->applyCategories($category_id)->find($cr);
     if (!$model) {
         $newProduct = true;
         $model = new StoreProduct();
         $this->stats['created']++;
     } else {
         $this->stats['updated']++;
     }
     // Process product type
     $model->type_id = $this->getTypeIdByName($data['type']);
     // Manufacturer
     if (isset($data['manufacturer']) && !empty($data['manufacturer'])) {
         $model->manufacturer_id = $this->getManufacturerIdByName($data['manufacturer']);
     }
     // Update product variables and eav attributes.
     $attributes = new CsvAttributesProcessor($model, $data);
     if ($model->validate()) {
         $categories = array($category_id);
         if (isset($data['additionalCategories'])) {
             $categories = array_merge($categories, $this->getAdditionalCategories($data['additionalCategories']));
         }
         if (!$newProduct) {
             foreach ($model->categorization as $c) {
                 $categories[] = $c->category;
             }
             $categories = array_unique($categories);
         }
         // Save product
         $model->save();
         // Update EAV data
         $attributes->save();
         // Update categories
         $model->setCategories($categories, $category_id);
         // Process product main image if product doesn't have one
         if (isset($data['image']) && !empty($data['image'])) {
             $image = CsvImage::create($data['image']);
             if ($image && $model->mainImage === null) {
                 $model->addImage($image);
             }
             if ($image && $this->deleteDownloadedImages) {
                 $image->deleteTempFile();
             }
         }
     } else {
         $errors = $model->getErrors();
         $error = array_shift($errors);
         $this->errors[] = array('line' => $this->line, 'error ' => $error[0]);
     }
 }
Exemplo n.º 22
0
 /**
  * @return array of StoreProduct models to compare
  */
 public function getProducts()
 {
     if ($this->_products === null) {
         $this->_products = StoreProduct::model()->findAllByPk(array_values($this->getIds()));
     }
     return $this->_products;
 }
Exemplo n.º 23
0
 public function afterDelete()
 {
     // Clear product relations
     StoreProduct::model()->updateAll(array('manufacturer_id' => new CDbExpression('NULL')), 'manufacturer_id = :id', array(':id' => $this->id));
     return parent::afterDelete();
 }
Exemplo n.º 24
0
 /**
  * Write offers to xml file
  */
 public function loadProducts()
 {
     $limit = $this->limit;
     $total = ceil(StoreProduct::model()->active()->count() / $limit);
     $offset = 0;
     $this->write('<offers>');
     for ($i = 0; $i <= $total; ++$i) {
         $products = StoreProduct::model()->active()->findAll(array('limit' => $limit, 'offset' => $offset));
         $this->renderProducts($products);
         $offset += $limit;
     }
     $this->write('</offers>');
 }
Exemplo n.º 25
0
 /**
  * Load products added to cart
  * @return array
  */
 public function getDataWithModels()
 {
     $data = $this->getData();
     if (empty($data)) {
         return array();
     }
     foreach ($data as $index => &$item) {
         $item['variant_models'] = array();
         $item['model'] = StoreProduct::model()->findByPk($item['product_id']);
         // Load configurable product
         if ($item['configurable_id']) {
             $item['configurable_model'] = StoreProduct::model()->findByPk($item['configurable_id']);
         }
         // Process variants
         if (!empty($item['variants'])) {
             $item['variant_models'] = StoreProductVariant::model()->with(array('attribute', 'option'))->findAllByPk($item['variants']);
         }
         // If product was deleted during user session!.
         if (!$item['model']) {
             unset($data[$index]);
         }
     }
     unset($item);
     return $data;
 }
Exemplo n.º 26
0
 public function afterDelete()
 {
     //Remove all products with this category set as main.
     $products = StoreProductCategoryRef::model()->findAllByAttributes(array('category' => $this->id, 'is_main' => '1'));
     foreach ($products as $p) {
         $productModel = StoreProduct::model()->findByPk($p->product);
         if ($productModel) {
             $productModel->delete();
         }
     }
     // Remove all category-product relations
     StoreProductCategoryRef::model()->deleteAllByAttributes(array('category' => $this->id, 'is_main' => '0'));
     $this->clearRouteCache();
     return parent::afterDelete();
 }
Exemplo n.º 27
0
</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td><?php 
echo $form->labelEx($model, Yii::t('store', 'pr_brand'));
?>
</td>
    <td>&nbsp;</td>
    <td> <?php 
echo $form->dropDownList($model, 'pr_brand', CHtml::listData(StoreProduct::model()->findAll(), 'id', 'product_brand'), array('prompt' => 'Select'));
?>
</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
	
     <tr>
    <td><?php 
echo $form->labelEx($model, Yii::t('store', 'pr_quantity'));
?>
</td>
    <td>&nbsp;</td>
Exemplo n.º 28
0
 /**
  * Calculate product price by its variants, configuration and self price
  * @static
  * @param $product
  * @param array $variants
  * @param $configuration
  */
 public static function calculatePrices($product, array $variants, $configuration)
 {
     if ($product instanceof StoreProduct === false) {
         $product = StoreProduct::model()->findByPk($product);
     }
     if ($configuration instanceof StoreProduct === false && $configuration > 0) {
         $configuration = StoreProduct::model()->findByPk($configuration);
     }
     if ($configuration instanceof StoreProduct) {
         $result = $configuration->price;
     } else {
         $result = $product->price;
     }
     // if $variants contains not models
     if (!empty($variants) && $variants[0] instanceof StoreProductVariant === false) {
         $variants = StoreProductVariant::model()->findAllByPk($variants);
     }
     foreach ($variants as $variant) {
         // Price is percent
         if ($variant->price_type == 1) {
             $result += $result / 100 * $variant->price;
         } else {
             $result += $variant->price;
         }
     }
     return $result;
 }
Exemplo n.º 29
0
 /**
  * @param string $function
  * @return mixed
  */
 public function aggregatePrice($function = 'MIN')
 {
     $current_query = clone $this->currentQuery;
     $current_query->select = $function . '(t.price) as aggregation_price';
     $current_query->limit = 1;
     if ($function === 'MIN') {
         $current_query->order = 't.price';
     } else {
         $current_query->order = 't.price DESC';
     }
     $query = StoreProduct::model();
     $query->getDbCriteria()->mergeWith($current_query);
     $query = $query->find();
     if ($query) {
         return $query->aggregation_price;
     }
     return null;
 }
Exemplo n.º 30
0
 /**
  * @param $limit
  * @return array
  */
 protected function getNewest($limit)
 {
     return StoreProduct::model()->active()->newest()->findAll(array('limit' => $limit));
 }