示例#1
0
文件: CartForm.php 项目: arduanov/eco
 public function existProduct($attribute, $params)
 {
     if (!ModuleCatalogProduct::model()->existsProduct($this->id)) {
         $this->addError('id', 'Данный товар отсутствует в каталоге');
     }
 }
示例#2
0
 public function productXmlAdd($product)
 {
     $model = new ModuleCatalogProduct();
     $album_id = false;
     foreach ($product as $key => $value) {
         if ($key == 'Ид') {
             $model->xml_id = $value;
         } else {
             if ($key == 'Наименование') {
                 $model->name = $value;
             } else {
                 if ($key == 'БазоваяЕдиница') {
                     $model->unit = $value;
                 } else {
                     if ($key == 'Картинка') {
                         if (!is_array($value)) {
                             $value = array($value);
                         }
                         foreach ($value as $value_img) {
                             $name = explode('\\', $value_img);
                             $src = $_SERVER['DOCUMENT_ROOT'] . '/upload/xml/extract/e' . str_replace('\\', '//', $value_img);
                             $folder = $_SERVER['DOCUMENT_ROOT'] . '/' . Files::model()->getUploadFolder('catalog', true, true);
                             if (count($name) - 1 > 0 && file_exists($src) && $name[count($name) - 1] != 'www.eldorado.ru') {
                                 $thumb = Yii::app()->thumb->create($src);
                                 $iname = explode('.', $name[count($name) - 1]);
                                 //&& copy($src, $folder.'/'.$name[count($name) - 1])
                                 if (empty($album_id)) {
                                     $album_id = ModuleGalleryAlbums::model()->createAlbum('catalog');
                                 }
                                 $thumb->resize(320, 340);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_large.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_large.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                                 $thumb->resize(190, 190);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_catalog.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_catalog.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                                 $thumb->resize(100, 100);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_small.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_small.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                             }
                         }
                     } else {
                         if ($key == 'Группы' && is_array($value)) {
                             $value_group = $this->getProductGroupXmlId($value);
                             $category_id = ModuleCatalogCategory::model()->getCategoryIdByXmlCode($value_group);
                             if (!empty($category_id)) {
                                 $model->category_id = $category_id;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($album_id)) {
         $model->album_id = $album_id;
     }
     if ($model->save() && isset($product["ХарактеристикиТовара"]["ХарактеристикаТовара"])) {
         $this->addProperties($product["ХарактеристикиТовара"]["ХарактеристикаТовара"], $model->id, $product);
     }
 }