Example #1
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         $links = Links::find()->where(['hashId' => $this->id])->all();
         foreach ($links as $link) {
             $link->delete();
         }
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 private function addToBD($ebayResponse)
 {
     date_default_timezone_set('Europe/Moscow');
     $today = date("YmdHis");
     $hash = new Hash();
     $hash->hash = $this->queryHash;
     $hash->life_time = $today;
     $hash->page_count = $this->pageCount;
     $hash->page = $this->queryPage;
     $hash->save();
     $hashID = $hash->id;
     foreach ($ebayResponse['searchResult']['item'] as $itemEbay) {
         $ebay_item = Item::findOne(['ebay_item_id' => $itemEbay['itemId']]);
         if (!empty($ebay_item->ebay_item_id)) {
             continue;
         }
         $item = new Item();
         $item->ebay_item_id = $itemEbay['itemId'];
         $item->title = $itemEbay['title'];
         $item->categoryId = $itemEbay['primaryCategory']['categoryId'];
         $item->categoryName = $itemEbay['primaryCategory']['categoryName'];
         if (isset($itemEbay['galleryURL'])) {
             $item->galleryURL = $itemEbay['galleryURL'];
         }
         $item->viewItemURL = $itemEbay['viewItemURL'];
         $item->sellingState = $itemEbay['sellingStatus']['sellingState'];
         $item->timeLeft = $itemEbay['sellingStatus']['timeLeft'];
         $item->current_price_value = $itemEbay['sellingStatus']['convertedCurrentPrice']['value'];
         $item->condition_id = $itemEbay['condition']['conditionId'];
         $item->condition_display_name = $itemEbay['condition']['conditionDisplayName'];
         $item->shipping_service_cost = $this->calculateShipping($itemEbay);
         $item->price_shipping_sum = $this->calculateValidPrice($itemEbay, $item->shipping_service_cost);
         $item->save();
         $itemID = $item->id;
         $links = new Links();
         $links->itemId = $itemID;
         $links->hashId = $hashID;
         $links->save();
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUpLinks()
 {
     return $this->hasMany(Links::className(), ['to' => 'id']);
 }