Example #1
0
 public function afterUninstall()
 {
     Yii::app()->settings->clear('shop');
     Yii::app()->unintallComponent('currency');
     $db = Yii::app()->db;
     $tablesArray = array(ShopTypeAttribute::model()->tableName(), ShopAttribute::model()->tableName(), ShopAttributeOption::model()->tableName(), ShopAttributeOptionTranslate::model()->tableName(), ShopAttributeTranslate::model()->tableName(), ShopCategory::model()->tableName(), ShopCategoryTranslate::model()->tableName(), ShopCurrency::model()->tableName(), ShopManufacturer::model()->tableName(), ShopManufacturerTranslate::model()->tableName(), ShopProduct::model()->tableName(), ShopProductCategoryRef::model()->tableName(), ShopProductImage::model()->tableName(), ShopProductTranslate::model()->tableName(), ShopProductType::model()->tableName(), ShopProductVariant::model()->tableName(), ShopRelatedProduct::model()->tableName(), ShopSuppliers::model()->tableName(), $db->tablePrefix . 'shop_product_attribute_eav', $db->tablePrefix . 'shop_product_configurable_attributes', $db->tablePrefix . 'shop_product_configurations');
     foreach ($tablesArray as $table) {
         $db->createCommand()->dropTable($table);
     }
     CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.product'), array('traverseSymlinks' => true));
     CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.categories'), array('traverseSymlinks' => true));
     CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.manufacturer'), array('traverseSymlinks' => true));
     return parent::afterUninstall();
 }
Example #2
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'] = ShopProduct::model()->cache(Yii::app()->controller->cacheTime)->findByPk($item['product_id']);
         // Load configurable product
         if ($item['configurable_id']) {
             $item['configurable_model'] = ShopProduct::model()->cache(Yii::app()->controller->cacheTime)->findByPk($item['configurable_id']);
         }
         // Process variants
         if (!empty($item['variants'])) {
             $item['variant_models'] = ShopProductVariant::model()->cache(Yii::app()->controller->cacheTime)->with(array('attribute', 'option'))->findAllByPk($item['variants']);
         }
         // If product was deleted during user session!.
         if (!$item['model']) {
             unset($data[$index]);
         }
     }
     unset($item);
     return $data;
 }
Example #3
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 ShopProduct === false) {
         $product = ShopProduct::model()->findByPk($product);
     }
     if ($configuration instanceof ShopProduct === false && $configuration > 0) {
         $configuration = ShopProduct::model()->findByPk($configuration);
     }
     if ($configuration instanceof ShopProduct) {
         $result = $configuration->price;
     } else {
         //$result = ($product->currency_id)? $product->price: $product->price;
         $result = $product->price;
     }
     // if $variants contains not models
     if (!empty($variants) && $variants[0] instanceof ShopProductVariant === false) {
         $variants = ShopProductVariant::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;
 }
 /**
  * Check if product variantion exists
  * @param $product_id
  * @param $attribute_id
  * @param $variant_id
  * @return string
  */
 protected function _checkVariantExists($product_id, $attribute_id, $variant_id)
 {
     return ShopProductVariant::model()->cache($this->cacheTime)->countByAttributes(array('id' => $variant_id, 'product_id' => $product_id, 'attribute_id' => $attribute_id));
 }
 /**
  * Save product variants
  * @param ShopProduct $model
  */
 protected function processVariants(ShopProduct $model)
 {
     $dontDelete = array();
     if (!empty($_POST['variants'])) {
         foreach ($_POST['variants'] as $attribute_id => $values) {
             $i = 0;
             foreach ($values['option_id'] as $option_id) {
                 // Try to load variant from DB
                 $variant = ShopProductVariant::model()->findByAttributes(array('product_id' => $model->id, 'attribute_id' => $attribute_id, 'option_id' => $option_id));
                 // If not - create new.
                 if (!$variant) {
                     $variant = new ShopProductVariant();
                 }
                 $variant->setAttributes(array('attribute_id' => $attribute_id, 'option_id' => $option_id, 'product_id' => $model->id, 'price' => $values['price'][$i], 'price_type' => $values['price_type'][$i], 'sku' => $values['sku'][$i]), false);
                 $variant->save(false, false, false);
                 array_push($dontDelete, $variant->id);
                 $i++;
             }
         }
     }
     if (!empty($dontDelete)) {
         $cr = new CDbCriteria();
         $cr->addNotInCondition('id', $dontDelete);
         $cr->addCondition('product_id=' . $model->id);
         ShopProductVariant::model()->deleteAll($cr);
     } else {
         ShopProductVariant::model()->deleteAllByAttributes(array('product_id' => $model->id));
     }
 }
 /**
  * Copy product variants
  *
  * @param ShopProduct $original
  * @param ShopProduct $copy
  */
 public function copyVariants(ShopProduct $original, ShopProduct $copy)
 {
     $variants = $original->variants;
     if (!empty($variants)) {
         foreach ($variants as $v) {
             $record = new ShopProductVariant();
             $record->product_id = $copy->id;
             $record->attribute_id = $v->attribute_id;
             $record->option_id = $v->option_id;
             $record->price = $v->price;
             $record->price_type = $v->price_type;
             $record->sku = $v->sku;
             $record->save();
         }
     }
 }