/** * @param Part $part * @return Offer|null */ public function getPartBestPriceOffer(Part $part) { $bestPrice = null; $bestOffer = null; foreach ($part->getOffers() as $offer) { $offerCurrency = $offer->getProvider()->getCurrency(); $price = $this->priceConverter->convert($offer->getPrice(), $offerCurrency, 'RUB'); if (!$bestPrice || $price < $bestPrice) { $bestPrice = $price; $bestOffer = $offer; } } return $bestOffer; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $parts = ['Generator' => [[1, 'ROTOR ASSY', '5SL-81450-01-00'], [2, 'BOLT, FLANGE', '90105-126A8-00'], [3, 'WASHER, PLATE', '90201-12008-00'], [4, 'CLAMP 2', '5SL-15484-00-00'], [5, 'SCREW', '90149-06018-00'], [6, 'STATOR ASSY', '5SL-81410-00-00'], [7, 'SCREW', '90149-06031-00'], [8, 'SCREW', '90149-08003-00']], 'Headlight' => [[1, 'HEADLIGHT ASSY', '5SL-84300-21-00'], [2, 'BULB (12V-55W)\\(H7) HALOGEN', '4SV-84314-00-00'], [3, 'GRILL, AIR INTAKE 1', '5SL-2837N-00-00'], [4, 'COVER, SOCKET', '5SL-84397-00-00'], [5, 'COVER (L.H)', '5SL-84196-00-00'], [6, 'COVER (R.H)', '5SL-84396-00-00'], [7, 'RIVET', '90269-06008-00'], [8, 'SCREW, RIM ADJUSTING', '5SL-84331-00-00'], [9, 'SCREW, ADJUSTING', '5SL-8433E-00-00'], [10, 'SCREW, ROUND TAPPING', '90160-05006-00'], [11, 'CORD, HEADLIGHT', '5SL-84359-10-00']]]; foreach ($parts as $component => $items) { foreach ($items as $item) { list($partPointer, $partName, $partNumber) = $item; $part = new Part(); $part->setPointer($partPointer); $part->setName($partName); $part->setNumber($partNumber); foreach (range(2003, 2005) as $yearNumber) { $part->addComponent($this->getReference('edition-YZF-R6-' . $yearNumber . '-' . $component)); } $this->addReference('part-' . $part->getNumber(), $part); $manager->persist($part); } } $manager->flush(); }