Exemplo n.º 1
0
 private function addItem($goods_id, $verification_code, $item_sxe)
 {
     $item = ShopItems::findOne(['verification_code' => $verification_code]);
     if (!$item) {
         $item = new ShopItems();
         $item->shop_goods_id = $goods_id;
         $item->verification_code = $verification_code;
     }
     $item->state = 1;
     $item->save();
     foreach (ShopItemCharacteristics::findAll(['shop_items_id' => $item->id]) as $item_characteristic) {
         $item_characteristic->state = 0;
         $item_characteristic->save();
     }
     if (isset($item_sxe->{'ХарактеристикиТовара'})) {
         foreach ($item_sxe->{'ХарактеристикиТовара'}->{'ХарактеристикаТовара'} as $characteristic_sxe) {
             $characteristic = ShopCharacteristics::findOne(['name' => strval($characteristic_sxe->{'Наименование'})]);
             if (!$characteristic) {
                 $characteristic = new ShopCharacteristics();
                 $characteristic->name = strval($characteristic_sxe->{'Наименование'});
                 $characteristic->save();
             }
             $item_characteristic = ShopItemCharacteristics::findOne(['shop_items_id' => $item->id, 'shop_characteristics_id' => $characteristic->id]);
             if (!$item_characteristic) {
                 $item_characteristic = new ShopItemCharacteristics();
                 $item_characteristic->shop_items_id = $item->id;
                 $item_characteristic->shop_characteristics_id = $characteristic->id;
             }
             $item_characteristic->name = strval($characteristic_sxe->{'Значение'});
             $item_characteristic->state = 1;
             $item_characteristic->save();
         }
     }
     return ['id' => $item->id];
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopCharacteristic()
 {
     return $this->hasOne(ShopCharacteristics::className(), ['id' => 'shop_characteristics_id']);
 }