Skip to content

Commit

Permalink
Added the ability to specify delivery-options for the offer (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
veezex authored and Bukashk0zzz committed Sep 20, 2019
1 parent abb6bd1 commit 6375fbf
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ protected function addOffer(OfferInterface $offer)
}
}
$this->addOfferParams($offer);
$this->addOfferDeliveryOptions($offer);
$this->addOfferCondition($offer);

$this->writer->fullEndElement();
Expand Down Expand Up @@ -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
*/
Expand Down
27 changes: 27 additions & 0 deletions src/Model/Offer/AbstractOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Bukashk0zzz\YmlGenerator\Model\Offer;

use Bukashk0zzz\YmlGenerator\Model\Delivery;

/**
* Abstract Class Offer
*/
Expand Down Expand Up @@ -101,6 +103,11 @@ abstract class AbstractOffer implements OfferInterface
*/
private $localDeliveryCost;

/**
* @var array
*/
private $deliveryOptions = [];

/**
* @var string
*/
Expand Down Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions src/Model/Offer/OfferInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function getType();
*/
public function isAvailable();

/**
* @return array
*/
public function getDeliveryOptions();

/**
* @return array
*/
Expand Down
52 changes: 52 additions & 0 deletions tests/OfferDeliveryOptionsGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Bukashk0zzzYmlGenerator
*
* (c) Denis Golubovskiy <[email protected]>
*
* 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)
;
}
}
177 changes: 177 additions & 0 deletions tests/dtd/OfferDeliveryOptions.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<!ELEMENT yml_catalog (shop)>
<!ATTLIST yml_catalog
date CDATA #REQUIRED>

<!ELEMENT shop (name, company, url, phone?, platform?, version?, agency?, email*, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

<!ELEMENT currencies (currency+)>
<!ELEMENT currency EMPTY>
<!ATTLIST currency
id (RUR|RUB|USD|BYR|KZT|EUR|UAH) #REQUIRED
rate CDATA "1"
plus CDATA "0">


<!ELEMENT categories (category+)>
<!ELEMENT category (#PCDATA)>
<!ATTLIST category
id CDATA #REQUIRED
parentId CDATA #IMPLIED
tid CDATA #IMPLIED
yid CDATA #IMPLIED>

<!ELEMENT delivery-options (option+)>
<!ELEMENT option EMPTY>
<!ATTLIST option
cost CDATA #REQUIRED
days CDATA #REQUIRED
order-before CDATA #IMPLIED>

<!ELEMENT offers (offer+)>
<!ELEMENT offer (
url?,
buyurl?,
price,
oldprice?,
wprice?,
currencyId,
xCategory?,
categoryId+,
market_category?,
picture*,
pickup?,
delivery?,
local_delivery_cost?,
weight?,
name,
vendor?,
description?,
sales_notes?,
manufacturer_warranty?,
country_of_origin?,
downloadable?,
adult?,
cpa?,
barcode*,
delivery-options,
store?,
deliveryIncluded?,
orderingTime?,
vendorCode?,
aliases?,
additional*,
promo?,
age?,
param*,
related_offer*
)>
<!ATTLIST offer
id CDATA #IMPLIED
group_id CDATA #IMPLIED
type (vendor.model | book | audiobook | artist.title | tour | ticket | event-ticket) #IMPLIED
available (true | false) #IMPLIED
bid CDATA #IMPLIED
cbid CDATA #IMPLIED>

<!ELEMENT url (#PCDATA)>
<!ELEMENT store (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT platform (#PCDATA)>
<!ELEMENT version (#PCDATA)>
<!ELEMENT agency (#PCDATA)>
<!ELEMENT buyurl (#PCDATA)>
<!ELEMENT picture (#PCDATA)>
<!ELEMENT pickup (#PCDATA)>
<!ELEMENT delivery (#PCDATA)>
<!ELEMENT deliveryIncluded EMPTY>
<!ELEMENT local_delivery_cost (#PCDATA)>
<!ELEMENT orderingTime (onstock?, ordering, deliveryTime?)>
<!ELEMENT onstock EMPTY>
<!ELEMENT ordering (#PCDATA)>
<!ATTLIST ordering
hours CDATA #IMPLIED>

<!ELEMENT deliveryTime EMPTY>
<!ELEMENT price (#PCDATA)>
<!ELEMENT oldprice (#PCDATA)>
<!ELEMENT wprice (#PCDATA)>
<!ELEMENT currencyId (#PCDATA)>
<!ELEMENT categoryId (#PCDATA)>
<!ATTLIST categoryId
type (Yandex | Torg | Own) "Own" >

<!ELEMENT market_category (#PCDATA)>
<!ELEMENT typePrefix (#PCDATA)>
<!ELEMENT vendor (#PCDATA)>
<!ELEMENT vendorCode (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT volume (#PCDATA)>
<!ELEMENT part (#PCDATA)>
<!ELEMENT language (#PCDATA)>
<!ELEMENT binding (#PCDATA)>
<!ELEMENT page_extent (#PCDATA)>
<!ELEMENT table_of_contents (#PCDATA)>
<!ELEMENT performed_by (#PCDATA)>
<!ELEMENT performance_type (#PCDATA)>
<!ELEMENT storage (#PCDATA)>
<!ELEMENT format (#PCDATA)>
<!ELEMENT recording_length (#PCDATA)>
<!ELEMENT series (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT artist (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT media (#PCDATA)>
<!ELEMENT starring (#PCDATA)>
<!ELEMENT director (#PCDATA)>
<!ELEMENT originalName (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT sales_notes (#PCDATA)>
<!ELEMENT promo (#PCDATA)>
<!ELEMENT aliases (#PCDATA)>
<!ELEMENT provider (#PCDATA)>
<!ELEMENT tarifplan (#PCDATA)>
<!ELEMENT xCategory (#PCDATA)>
<!ELEMENT additional (#PCDATA)>
<!ELEMENT worldRegion (#PCDATA)>
<!ELEMENT region (#PCDATA)>
<!ELEMENT days (#PCDATA)>
<!ELEMENT dataTour (#PCDATA)>
<!ELEMENT hotel_stars (#PCDATA)>
<!ELEMENT room (#PCDATA)>
<!ELEMENT meal (#PCDATA)>
<!ELEMENT included (#PCDATA)>
<!ELEMENT transport (#PCDATA)>
<!ELEMENT price_min (#PCDATA)>
<!ELEMENT price_max (#PCDATA)>
<!ELEMENT options (#PCDATA)>
<!ELEMENT manufacturer_warranty (#PCDATA)>
<!ELEMENT country_of_origin (#PCDATA)>
<!ELEMENT downloadable (#PCDATA)>
<!ELEMENT adult (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ELEMENT weight (#PCDATA)>
<!ELEMENT barcode (#PCDATA)>
<!ELEMENT param (#PCDATA)>
<!ATTLIST param
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
<!ATTLIST hall
plan CDATA #IMPLIED>

<!ELEMENT hall_part (#PCDATA)>
<!ELEMENT is_premiere (#PCDATA)>
<!ELEMENT is_kids (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT cpa (#PCDATA)>

0 comments on commit 6375fbf

Please sign in to comment.