From 6375fbfbe01650e0ff1dfc8e6d25110754912b54 Mon Sep 17 00:00:00 2001 From: veezex Date: Fri, 20 Sep 2019 13:04:56 +0300 Subject: [PATCH] Added the ability to specify delivery-options for the offer (#28) --- src/Generator.php | 12 ++ src/Model/Offer/AbstractOffer.php | 27 +++ src/Model/Offer/OfferInterface.php | 5 + tests/OfferDeliveryOptionsGeneratorTest.php | 52 ++++++ tests/dtd/OfferDeliveryOptions.dtd | 177 ++++++++++++++++++++ 5 files changed, 273 insertions(+) create mode 100644 tests/OfferDeliveryOptionsGeneratorTest.php create mode 100644 tests/dtd/OfferDeliveryOptions.dtd diff --git a/src/Generator.php b/src/Generator.php index 8af334f..9b34016 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -200,6 +200,7 @@ protected function addOffer(OfferInterface $offer) } } $this->addOfferParams($offer); + $this->addOfferDeliveryOptions($offer); $this->addOfferCondition($offer); $this->writer->fullEndElement(); @@ -281,6 +282,17 @@ private function addOffers(array $offers) $this->writer->fullEndElement(); } + /** + * @param OfferInterface $offer + */ + private function addOfferDeliveryOptions(OfferInterface $offer) + { + $options = $offer->getDeliveryOptions(); + if (!empty($options)) { + $this->addDeliveries($options); + } + } + /** * @param OfferInterface $offer */ diff --git a/src/Model/Offer/AbstractOffer.php b/src/Model/Offer/AbstractOffer.php index 15b166e..0b91c70 100644 --- a/src/Model/Offer/AbstractOffer.php +++ b/src/Model/Offer/AbstractOffer.php @@ -11,6 +11,8 @@ namespace Bukashk0zzz\YmlGenerator\Model\Offer; +use Bukashk0zzz\YmlGenerator\Model\Delivery; + /** * Abstract Class Offer */ @@ -101,6 +103,11 @@ abstract class AbstractOffer implements OfferInterface */ private $localDeliveryCost; + /** + * @var array + */ + private $deliveryOptions = []; + /** * @var string */ @@ -482,6 +489,26 @@ public function setDelivery($delivery) return $this; } + /** + * @return array + */ + public function getDeliveryOptions() + { + return $this->deliveryOptions; + } + + /** + * @param Delivery $option + * + * @return $this + */ + public function addDeliveryOption(Delivery $option) + { + $this->deliveryOptions[] = $option; + + return $this; + } + /** * @param bool $store * diff --git a/src/Model/Offer/OfferInterface.php b/src/Model/Offer/OfferInterface.php index 014e92d..858c85b 100644 --- a/src/Model/Offer/OfferInterface.php +++ b/src/Model/Offer/OfferInterface.php @@ -31,6 +31,11 @@ public function getType(); */ public function isAvailable(); + /** + * @return array + */ + public function getDeliveryOptions(); + /** * @return array */ diff --git a/tests/OfferDeliveryOptionsGeneratorTest.php b/tests/OfferDeliveryOptionsGeneratorTest.php new file mode 100644 index 0000000..da80810 --- /dev/null +++ b/tests/OfferDeliveryOptionsGeneratorTest.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Bukashk0zzz\YmlGenerator\Tests; + +use Bukashk0zzz\YmlGenerator\Model\Delivery; +use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple; + +/** + * Generator test + */ +class OfferDeliveryOptionsGeneratorTest extends AbstractGeneratorTest +{ + /** + * Test generate + */ + public function testGenerate() + { + $this->offerType = 'OfferDeliveryOptions'; + $this->runGeneratorTest(); + } + + /** + * {@inheritdoc} + */ + protected function createOffer() + { + $delivery = (new Delivery())->setCost(10)->setDays(1)->setOrderBefore(14); + + return (new OfferSimple()) + ->setName($this->faker->name) + ->setVendor($this->faker->company) + ->setVendorCode(null) + ->setPickup(true) + ->addDeliveryOption($delivery) + ->addDeliveryOption($delivery) + ->setGroupId($this->faker->numberBetween()) + ->addPicture('http://example.com/example.jpeg') + ->addBarcode($this->faker->ean13) + ->setCategoriesId([1, 2, 3]) + ->setCategoryId(999) + ; + } +} diff --git a/tests/dtd/OfferDeliveryOptions.dtd b/tests/dtd/OfferDeliveryOptions.dtd new file mode 100644 index 0000000..d90be5d --- /dev/null +++ b/tests/dtd/OfferDeliveryOptions.dtd @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +