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];
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopItems()
 {
     return $this->hasMany(ShopItems::className(), ['shop_goods_id' => 'id']);
 }
Exemplo n.º 3
0
 private function parserOffers($offers_sxe)
 {
     /* Поиск и удаление цен для товара и его характеристик */
     foreach ($offers_sxe as $item_sxe) {
         if (preg_match('/(.+)#(.+)/', $item_sxe->{'Ид'}, $matches)) {
             $good_verification_code = strval($matches[1]);
             $item_verification_code = strval($matches[2]);
             $prices_item = ShopPriceItem::find()->innerJoinWith('shopItem')->where(['shop_items.verification_code' => $item_verification_code])->all();
             if ($prices_item) {
                 ShopPriceItem::deleteAll(['id' => ArrayHelper::getColumn($prices_item, 'id')]);
             }
         } else {
             $good_verification_code = strval($item_sxe->{'Ид'});
         }
         $price_good = ShopPriceGood::find()->innerJoinWith('shopGood')->where(['shop_goods.verification_code' => $good_verification_code])->all();
         if ($price_good) {
             ShopPriceGood::deleteAll(['id' => ArrayHelper::getColumn($price_good, 'id')]);
         }
     }
     $price_types = ArrayHelper::map(ShopPriceTypes::find()->all(), 'verification_code', 'id');
     $good_min_price = array();
     foreach ($offers_sxe as $item_sxe) {
         $item_verification_code = false;
         if (preg_match('/(.+)#(.+)/', $item_sxe->{'Ид'}, $matches)) {
             $good_verification_code = strval($matches[1]);
             $item_verification_code = strval($matches[2]);
         } else {
             $good_verification_code = strval($item_sxe->{'Ид'});
         }
         if (!isset($good_min_price[$good_verification_code])) {
             $good_min_price[$good_verification_code] = array();
         }
         foreach ($item_sxe->{'Цены'}->{'Цена'} as $item_price) {
             $verification_code = strval($item_price->{'ИдТипаЦены'});
             if (!isset($good_min_price[$good_verification_code][$price_types[$verification_code]])) {
                 $good_min_price[$good_verification_code][$price_types[$verification_code]] = floatval($item_price->{'ЦенаЗаЕдиницу'});
             } else {
                 if ($good_min_price[$good_verification_code][$price_types[$verification_code]] > floatval($item_price->{'ЦенаЗаЕдиницу'})) {
                     $good_min_price[$good_verification_code][$price_types[$verification_code]] = floatval($item_price->{'ЦенаЗаЕдиницу'});
                 }
             }
             if ($item_verification_code) {
                 $item = ShopItems::findOne(['verification_code' => $item_verification_code]);
                 if ($item) {
                     $price_item = new ShopPriceItem();
                     $price_item->shop_items_id = $item->id;
                     $price_item->shop_price_types_id = $price_types[$verification_code];
                     $price_item->price = floatval($item_price->{'ЦенаЗаЕдиницу'});
                     $price_item->save();
                 }
             }
         }
     }
     foreach ($good_min_price as $good_verification_code => $good_prices) {
         $good = ShopGoods::findOne(['verification_code' => $good_verification_code]);
         if ($good) {
             foreach ($good_prices as $price_types_id => $good_price) {
                 $price_good = new ShopPriceGood();
                 $price_good->shop_goods_id = $good->id;
                 $price_good->shop_price_types_id = $price_types_id;
                 $price_good->price = $good_price;
                 $price_good->save();
             }
         }
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopItem()
 {
     return $this->hasOne(ShopItems::className(), ['id' => 'shop_items_id']);
 }