Skip to content

Commit

Permalink
Add enable_auto_discounts property to offer and shop info (#31)
Browse files Browse the repository at this point in the history
* add autoDiscount property to SiteInfo

* add autoDiscount property to AbstractOffer

* add tests
  • Loading branch information
taarim authored May 6, 2020
1 parent 517bde4 commit 47329ed
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 11 deletions.
28 changes: 27 additions & 1 deletion src/Model/Offer/AbstractOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ abstract class AbstractOffer implements OfferInterface
*/
private $store;

/**
* @var bool
*/
private $autoDiscount;

/**
* Array of custom elements (element types are keys) of arrays of element values
* There may be multiple elements of the same type
Expand Down Expand Up @@ -718,7 +723,7 @@ public function setBarcodes(array $barcodes = [])
*
* @param string $barcode
*
* @return AbstractOffer
* @return $this
*/
public function addBarcode($barcode)
{
Expand Down Expand Up @@ -809,6 +814,26 @@ public function addCondition(OfferCondition $condition)
return $this;
}

/**
* @return bool
*/
public function getAutoDiscount()
{
return $this->autoDiscount;
}

/**
* @param bool $autoDiscount
*
* @return $this
*/
public function setAutoDiscount($autoDiscount)
{
$this->autoDiscount = $autoDiscount;

return $this;
}

/**
* @return array
*/
Expand Down Expand Up @@ -836,6 +861,7 @@ private function getHeaderOptions()
'local_delivery_cost' => $this->getLocalDeliveryCost(),
'weight' => $this->getWeight(),
'name' => $this->getName(),
'enable_auto_discounts' => $this->getAutoDiscount(),
] + $this->getCustomElements();
}

Expand Down
26 changes: 26 additions & 0 deletions src/Model/ShopInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class ShopInfo
*/
private $email;

/**
* @var bool
*/
private $autoDiscount;

/**
* @return array
*/
Expand All @@ -64,6 +69,7 @@ public function toArray()
'version' => $this->getVersion(),
'agency' => $this->getAgency(),
'email' => $this->getEmail(),
'enable_auto_discounts' => $this->getAutoDiscount(),
];
}

Expand Down Expand Up @@ -206,4 +212,24 @@ public function setEmail($email)

return $this;
}

/**
* @return bool
*/
public function getAutoDiscount()
{
return $this->autoDiscount;
}

/**
* @param bool $autoDiscount
*
* @return ShopInfo
*/
public function setAutoDiscount($autoDiscount)
{
$this->autoDiscount = $autoDiscount;

return $this;
}
}
2 changes: 2 additions & 0 deletions tests/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ protected function createOffers()
->setMarketCategory($this->faker->word)
->setCpa($this->faker->numberBetween(0, 1))
->setBarcodes([$this->faker->ean13, $this->faker->ean13])
->setAutoDiscount($this->faker->boolean)
;
}

Expand Down Expand Up @@ -187,6 +188,7 @@ private function createShopInfo()
->setVersion($this->faker->numberBetween(1, 999))
->setAgency($this->faker->name)
->setEmail($this->faker->email)
->setAutoDiscount($this->faker->boolean)
;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/dtd/ArtistTitle.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -43,6 +43,7 @@
delivery?,
local_delivery_cost?,
weight?,
enable_auto_discounts?,
artist?,
title,
year?,
Expand Down Expand Up @@ -168,6 +169,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down
4 changes: 3 additions & 1 deletion tests/dtd/Audiobook.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -44,6 +44,7 @@
local_delivery_cost?,
weight?,
name,
enable_auto_discounts?,
author?,
publisher?,
series?,
Expand Down Expand Up @@ -176,6 +177,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down
5 changes: 4 additions & 1 deletion tests/dtd/Book.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand All @@ -29,6 +29,7 @@
days CDATA #REQUIRED
order-before CDATA #IMPLIED>


<!ELEMENT offers (offer+)>
<!ELEMENT offer (
url?,
Expand All @@ -44,6 +45,7 @@
local_delivery_cost?,
weight?,
name,
enable_auto_discounts?,
author?,
publisher?,
series?,
Expand Down Expand Up @@ -172,6 +174,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down
8 changes: 5 additions & 3 deletions tests/dtd/Custom.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -47,6 +47,7 @@
deliveryIncluded?,
local_delivery_cost?,
weight?,
enable_auto_discounts?,
orderingTime?,
typePrefix?,
vendor,
Expand Down Expand Up @@ -165,6 +166,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand All @@ -178,5 +180,5 @@
<!ELEMENT cpa (#PCDATA)>

<!ELEMENT condition (reason+)>
<!ATTLIST condition type CDATA #REQUIRED>
<!ELEMENT reason (#PCDATA)>
<!ATTLIST condition type CDATA #REQUIRED>
<!ELEMENT reason (#PCDATA)>
4 changes: 3 additions & 1 deletion tests/dtd/EventTicket.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -44,6 +44,7 @@
local_delivery_cost?,
weight?,
name,
enable_auto_discounts?,
place,
date,
is_premiere?,
Expand Down Expand Up @@ -167,6 +168,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down
4 changes: 3 additions & 1 deletion tests/dtd/OfferDeliveryOptions.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -46,6 +46,7 @@
local_delivery_cost?,
weight?,
name,
enable_auto_discounts?,
vendor?,
description?,
sales_notes?,
Expand Down Expand Up @@ -163,6 +164,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down
4 changes: 3 additions & 1 deletion tests/dtd/Simple.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -46,6 +46,7 @@
local_delivery_cost?,
weight?,
name,
enable_auto_discounts?,
vendor?,
description?,
sales_notes?,
Expand Down Expand Up @@ -162,6 +163,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down
4 changes: 3 additions & 1 deletion tests/dtd/Tour.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!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 shop (name, company, url, phone?, platform?, version?, agency?, email*, enable_auto_discounts?, currencies, categories, delivery-options, store?, pickup?, delivery?, deliveryIncluded?, local_delivery_cost?, adult?, offers)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Expand Down Expand Up @@ -44,6 +44,7 @@
local_delivery_cost?,
weight?,
name,
enable_auto_discounts?,
worldRegion?,
country?,
region?,
Expand Down Expand Up @@ -173,6 +174,7 @@
name CDATA #REQUIRED
unit CDATA #IMPLIED>
<!ELEMENT related_offer (#PCDATA)>
<!ELEMENT enable_auto_discounts (#PCDATA)>

<!ELEMENT place (#PCDATA)>
<!ELEMENT hall (#PCDATA)>
Expand Down

0 comments on commit 47329ed

Please sign in to comment.