Skip to content

Commit

Permalink
Расширение функционала, добавление дополнительных тегов (Bukashk0zzz#23)
Browse files Browse the repository at this point in the history
* Добавляет возможность управлять тегом store

* Добавил возможность добавлять несколько категорий

* Добавил возможность добавлять name для offer

* Исправил ошибку после правки конфликта

* Добавил тег condition описывающий работу с уцененными товарами

* phpcs, php-cs-fixer

* Tests
  • Loading branch information
remitmaster authored and Bukashk0zzz committed Jul 10, 2019
1 parent 9b1caf8 commit f1fc38e
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 86 deletions.
16 changes: 16 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Bukashk0zzz\YmlGenerator\Model\Category;
use Bukashk0zzz\YmlGenerator\Model\Currency;
use Bukashk0zzz\YmlGenerator\Model\Delivery;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferCondition;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferGroupAwareInterface;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferInterface;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferParam;
Expand Down Expand Up @@ -199,6 +200,7 @@ protected function addOffer(OfferInterface $offer)
}
}
$this->addOfferParams($offer);
$this->addOfferCondition($offer);

$this->writer->fullEndElement();
}
Expand Down Expand Up @@ -300,6 +302,20 @@ private function addOfferParams(OfferInterface $offer)
}
}

/**
* @param OfferInterface $offer
*/
private function addOfferCondition(OfferInterface $offer)
{
$params = $offer->getCondition();
if ($params instanceof OfferCondition) {
$this->writer->startElement('condition');
$this->writer->writeAttribute('type', $params->getType());
$this->writer->writeElement('reason', $params->getReasonText());
$this->writer->endElement();
}
}

/**
* @param string $name
* @param mixed $value
Expand Down
106 changes: 93 additions & 13 deletions src/Model/Offer/AbstractOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ abstract class AbstractOffer implements OfferInterface
*/
private $categoryId;

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

/**
* @var string
*/
private $name;

/**
* @var string
*/
Expand Down Expand Up @@ -134,10 +144,16 @@ abstract class AbstractOffer implements OfferInterface
/**
* Array of custom elements (element types are keys) of arrays of element values
* There may be multiple elements of the same type
*
* @var array[]
*/
private $customElements;

/**
* @var OfferCondition
*/
private $condition;

/**
* @return array
*/
Expand Down Expand Up @@ -286,6 +302,46 @@ public function setCategoryId($categoryId)
return $this;
}

/**
* @return array
*/
public function getCategoriesId()
{
return $this->categoriesId;
}

/**
* @param array $categoriesId
*
* @return $this
*/
public function setCategoriesId(array $categoriesId)
{
$this->categoriesId = $categoriesId;

return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -706,6 +762,26 @@ public function getCustomElementByType($elementType)
return [];
}

/**
* @return OfferCondition
*/
public function getCondition()
{
return $this->condition;
}

/**
* @param OfferCondition $condition
*
* @return $this
*/
public function addCondition(OfferCondition $condition)
{
$this->condition = $condition;

return $this;
}

/**
* @return array
*/
Expand All @@ -717,19 +793,23 @@ abstract protected function getOptions();
private function getHeaderOptions()
{
return [
'url' => $this->getUrl(),
'price' => $this->getPrice(),
'oldprice' => $this->getOldPrice(),
'currencyId' => $this->getCurrencyId(),
'categoryId' => $this->getCategoryId(),
'market_category' => $this->getMarketCategory(),
'picture' => $this->getPictures(),
'pickup' => $this->isPickup(),
'store' => $this->isStore(),
'delivery' => $this->isDelivery(),
'weight' => $this->getWeight(),
'local_delivery_cost' => $this->getLocalDeliveryCost(),
] + $this->getCustomElements();
'url' => $this->getUrl(),
'price' => $this->getPrice(),
'oldprice' => $this->getOldPrice(),
'currencyId' => $this->getCurrencyId(),
'categoryId' => \array_merge(
[$this->getCategoryId()],
$this->getCategoriesId()
),
'market_category' => $this->getMarketCategory(),
'picture' => $this->getPictures(),
'pickup' => $this->isPickup(),
'store' => $this->isStore(),
'delivery' => $this->isDelivery(),
'local_delivery_cost' => $this->getLocalDeliveryCost(),
'weight' => $this->getWeight(),
'name' => $this->getName(),
] + $this->getCustomElements();
}

/**
Expand Down
72 changes: 72 additions & 0 deletions src/Model/Offer/OfferCondition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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\Model\Offer;

/**
* Class OfferCondition
*/
class OfferCondition
{
/**
* @var string
*/
private $type;

/**
* @var string
*/
private $reasonText;

/**
* @return string
*/
public function getReasonText()
{
return $this->reasonText;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* Description text for the reason for markdowns
*
* @param string $reasonText
*
* @return $this
*/
public function setReasonText($reasonText)
{
$this->reasonText = $reasonText;

return $this;
}

/**
* Set product condition
*
* @param string $type
*
* @return $this
*/
public function setType($type)
{
$this->type = $type;

return $this;
}
}
5 changes: 5 additions & 0 deletions src/Model/Offer/OfferInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function isAvailable();
*/
public function getParams();

/**
* @return object
*/
public function getCondition();

/**
* @return array
*/
Expand Down
8 changes: 5 additions & 3 deletions tests/OfferCdataGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace Bukashk0zzz\YmlGenerator\Tests;

use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple;
use Bukashk0zzz\YmlGenerator\Cdata;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple;

/**
* Generator test
Expand All @@ -34,7 +34,8 @@ public function testGenerate()
* Need to override parent::createOffers() in order to avoid setting description
* after calling self::createOffer()
*
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffers()
*/
protected function createOffers()
Expand All @@ -54,7 +55,8 @@ protected function createOffers()
/**
* Set the test description with CDATA here
*
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffer()
*/
protected function createOffer()
Expand Down
10 changes: 6 additions & 4 deletions tests/OfferCustomElementsGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace Bukashk0zzz\YmlGenerator\Tests;

use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple;
use Bukashk0zzz\YmlGenerator\Cdata;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple;

/**
* Generator test
Expand All @@ -34,7 +34,8 @@ public function testGenerate()
* Need to override parent::createOffers() in order to avoid setting description
* after calling self::createOffer()
*
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffers()
*/
protected function createOffers()
Expand All @@ -54,7 +55,8 @@ protected function createOffers()
/**
* Set the test description with CDATA here
*
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffer()
*/
protected function createOffer()
Expand Down Expand Up @@ -111,7 +113,7 @@ private function checkCustomElements()

$offers = $yml->shop->offers->offer;
$this->assertNotEmpty($offers);
$this->assertEquals(self::OFFER_COUNT, count($offers));
$this->assertEquals(self::OFFER_COUNT, \count($offers));

foreach ($offers as $offer) {
$prop = 'stock_quantity';
Expand Down
6 changes: 6 additions & 0 deletions tests/OfferCustomGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Bukashk0zzz\YmlGenerator\Model\Offer\OfferCustom;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferParam;
use Bukashk0zzz\YmlGenerator\Model\Offer\OfferCondition;

/**
* Generator test
Expand Down Expand Up @@ -47,6 +48,11 @@ protected function createOffer()
->setValue($this->faker->text(10))
)
->setPictures(['http://example.com/example.jpeg', 'http://example.com/example2.jpeg'])
->addCondition(
(new OfferCondition())
->setType($this->faker->text(5))
->setReasonText($this->faker->text(10))
)
;
}
}
2 changes: 2 additions & 0 deletions tests/OfferSimpleGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ protected function createOffer()
->setGroupId($this->faker->numberBetween())
->addPicture('http://example.com/example.jpeg')
->addBarcode($this->faker->ean13)
->setCategoriesId([1, 2, 3])
->setCategoryId(999)
;
}
}
Loading

0 comments on commit f1fc38e

Please sign in to comment.