Esempio n. 1
0
 private function addPropertyValues($propertiesSxe, $goodsId)
 {
     $properties = ArrayHelper::index($this->shop_properties, 'verification_code');
     $goodProperties = ShopGoodProperties::find()->where(['shop_goods_id' => $goodsId])->all();
     if ($goodProperties) {
         ShopGoodProperties::updateAll(['state' => 0], ['id' => ArrayHelper::getColumn($goodProperties, 'id')]);
     }
     foreach ($propertiesSxe as $item) {
         $verification_code = strval($item->{'Ид'});
         $names = preg_split('/\\,/', trim(strval($item->{'Значение'})));
         $propertiesId = $properties[$verification_code]->id;
         foreach ($names as $name) {
             $name = trim($name);
             $propertyValue = ShopPropertyValues::findOne(['shop_properties_id' => $propertiesId, 'name' => $name]);
             if (!$propertyValue) {
                 $propertyValue = new ShopPropertyValues();
                 $propertyValue->shop_properties_id = $propertiesId;
                 $propertyValue->name = $name;
                 $propertyValue->anchor = $name;
                 $propertyValue->url = (new Translit())->slugify($name, $propertyValue->tableName(), 'url', '_', null, 'shop_properties_id', $propertiesId);
                 $propertyValue->save();
             }
             $addPropertyValue = true;
             if ($goodProperties) {
                 foreach ($goodProperties as $id => $goodProperty) {
                     if ($goodProperty->shop_properties_id == $propertiesId && $goodProperty->shop_property_values_id == $propertyValue->id) {
                         $addPropertyValue = false;
                         ShopGoodProperties::updateAll(['state' => 1], ['id' => $goodProperty->id]);
                     }
                 }
             }
             if ($addPropertyValue) {
                 $goodProperty = new ShopGoodProperties();
                 $goodProperty->shop_goods_id = $goodsId;
                 $goodProperty->shop_properties_id = $propertiesId;
                 $goodProperty->shop_property_values_id = $propertyValue->id;
                 $goodProperty->state = 1;
                 $goodProperty->save();
             }
         }
     }
     ShopGoodProperties::deleteAll(['shop_goods_id' => $goodsId, 'state' => 0]);
 }
Esempio n. 2
0
 public function getShopGoodProperties()
 {
     return $this->hasMany(ShopGoodProperties::className(), ['shop_goods_id' => 'id'])->innerJoin('shop_properties')->orderBy(['shop_properties.seq' => SORT_ASC]);
 }