Example #1
0
 /**
  * @param	BuyListing $buyListing The buyListing object to add.
  */
 protected function doAddBuyListing($buyListing)
 {
     $this->collBuyListings[] = $buyListing;
     $buyListing->setItem($this);
 }
 protected function updateListings($listings)
 {
     $now = new DateTime();
     $item = ItemQuery::create()->findOneByDataId($listings['id']);
     $item->setLastUpdated($now);
     $sell = $listings['sells'];
     $buy = $listings['buys'];
     $lowestSell = null;
     $maxBuy = null;
     $sellQuantityAmount = 0;
     $sellListingsAmount = 0;
     if (count($sell)) {
         $lowestSell = min(array_map(function ($row) {
             return $row['unit_price'];
         }, $sell));
         foreach ($sell as $s) {
             $sellQuantityAmount += $s['quantity'];
             $sellListingsAmount += $s['listings'];
         }
     }
     $sellListing = new SellListing();
     $sellListing->setItem($item);
     $sellListing->setListingDatetime($now);
     $sellListing->setQuantity($sellQuantityAmount);
     $sellListing->setListings($sellListingsAmount);
     if ($lowestSell) {
         $sellListing->setUnitPrice($lowestSell);
         $item->setMinSaleUnitPrice($lowestSell);
     } else {
         $sellListing->setUnitPrice($item->getMinSaleUnitPrice());
     }
     $item->setSaleAvailability($sellQuantityAmount);
     $sellListing->save();
     $buyQuantityAmount = 0;
     $buyListingsAmount = 0;
     if (count($buy)) {
         $maxBuy = max(array_map(function ($row) {
             return $row['unit_price'];
         }, $buy));
         foreach ($buy as $b) {
             $buyQuantityAmount += $b['quantity'];
             $buyListingsAmount += $b['listings'];
         }
     }
     $buyListing = new BuyListing();
     $buyListing->setItem($item);
     $buyListing->setListingDatetime($now);
     $buyListing->setQuantity($buyQuantityAmount);
     $buyListing->setListings($buyListingsAmount);
     if ($maxBuy) {
         $buyListing->setUnitPrice($maxBuy);
         $item->setMaxOfferUnitPrice($maxBuy);
     } else {
         $buyListing->setUnitPrice($item->getMaxOfferUnitPrice());
     }
     $item->setOfferAvailability($buyQuantityAmount);
     $buyListing->save();
     $item->save();
 }