コード例 #1
0
ファイル: ShopModule.php プロジェクト: buildshop/bs-common
 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();
 }
コード例 #2
0
 /**
  * Find or create option by attribute and value.
  *
  * @param ShopAttribute $attribute
  * @param $val
  * @return ShopAttributeOption
  */
 public function getOption(ShopAttribute $attribute, $val)
 {
     $val = trim($val);
     $cacheKey = sha1($attribute->id . $val);
     if (isset($this->optionsCache[$cacheKey])) {
         return $this->optionsCache[$cacheKey];
     }
     // Search for option
     $cr = new CDbCriteria();
     $cr->with = 'option_translate';
     $cr->compare('option_translate.value', $val);
     $cr->compare('t.attribute_id', $attribute->id);
     $option = ShopAttributeOption::model()->find($cr);
     if (!$option) {
         // Create new option
         $option = $this->addOptionToAttribute($attribute->id, $val);
     }
     $this->optionsCache[$cacheKey] = $option;
     return $option;
 }
コード例 #3
0
 /**
  * Import catalog products
  */
 public function importProducts()
 {
     foreach ($this->xml->{"Каталог"}->{"Товары"}->{"Товар"} as $product) {
         $createExId = false;
         $model = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_PRODUCT, $product->{"Ид"});
         if (!$model) {
             $model = new ShopProduct();
             // Add "null" by PANIX
             $model->type_id = self::DEFAULT_TYPE;
             $model->price = 0;
             $model->switch = 1;
             $createExId = true;
         }
         $model->name = $product->{"Наименование"};
         $model->seo_alias = CMS::translit($model->name);
         $model->sku = $product->{"Артикул"};
         if ($model->save(false, false)) {
         } else {
             // Yii::log(CJSON::encode($model->getErrors()),'info','application');
         }
         // Create external id
         if ($createExId === true) {
             $this->createExternalId(C1ExternalFinder::OBJECT_TYPE_PRODUCT, $model->id, $product->{"Ид"});
         }
         // Set category
         $categoryId = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_CATEGORY, $product->{"Группы"}->{"Ид"}, false);
         $model->setCategories(array($categoryId), $categoryId);
         // Set image
         //  $image = C1ProductImage::create($this->buildPathToTempFile($product->{"Картинка"}));
         // if ($image && !$model->mainImage)
         ///     $model->addImage($image);
         if (!empty($product->{"Картинка"})) {
             foreach ($product->{"Картинка"} as $pi) {
                 $image = C1ProductImage::create($this->buildPathToTempFile($pi));
                 if ($image && !$model->mainImage) {
                     $model->addImage($image);
                 }
             }
         }
         // Process properties
         if (isset($product->{"ЗначенияСвойств"}->{"ЗначенияСвойства"})) {
             $attrsdata = array();
             foreach ($product->{"ЗначенияСвойств"}->{"ЗначенияСвойства"} as $attribute) {
                 $attributeModel = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_ATTRIBUTE, $attribute->{"Ид"});
                 if ($attributeModel && $attribute->{"Значение"} != '') {
                     $cr = new CDbCriteria();
                     $cr->with = 'option_translate';
                     $cr->compare('option_translate.value', $attribute->{"Значение"});
                     $option = ShopAttributeOption::model()->find($cr);
                     if (!$option) {
                         $option = $this->addOptionToAttribute($attributeModel->id, $attribute->{"Значение"});
                     }
                     $attrsdata[$attributeModel->name] = $option->id;
                 }
             }
             if (!empty($attrsdata)) {
                 $model->setEavAttributes($attrsdata, true);
             }
         }
     }
 }
コード例 #4
0
 /**
  * Save attribute options
  * @param ShopAttribute $model
  */
 protected function saveOptions($model)
 {
     $dontDelete = array();
     if (!empty($_POST['options'])) {
         foreach ($_POST['options'] as $key => $val) {
             if (isset($val[0]) && $val[0] != '') {
                 $index = 0;
                 $attributeOption = ShopAttributeOption::model()->findByAttributes(array('id' => $key, 'attribute_id' => $model->id));
                 if (!$attributeOption) {
                     $attributeOption = new ShopAttributeOption();
                     $attributeOption->attribute_id = $model->id;
                 }
                 $attributeOption->save(false, false, false);
                 foreach (Yii::app()->languageManager->languages as $lang) {
                     $attributeLangOption = ShopAttributeOption::model()->language($lang->id)->findByAttributes(array('id' => $attributeOption->id));
                     $attributeLangOption->value = $val[$index];
                     $attributeLangOption->save(false, false, false);
                     ++$index;
                 }
                 array_push($dontDelete, $attributeOption->id);
             }
         }
     }
     if (sizeof($dontDelete)) {
         $cr = new CDbCriteria();
         $cr->addNotInCondition('t.id', $dontDelete);
         $optionsToDelete = ShopAttributeOption::model()->findAllByAttributes(array('attribute_id' => $model->id), $cr);
     } else {
         // Clear all attribute options
         $optionsToDelete = ShopAttributeOption::model()->findAllByAttributes(array('attribute_id' => $model->id));
     }
     if (!empty($optionsToDelete)) {
         foreach ($optionsToDelete as $o) {
             $o->delete();
         }
     }
 }