diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5a98fda --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: composer + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 diff --git a/composer.json b/composer.json index bc79c2c..4f67c6d 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "nette", "heureka", "zbozi", - "merchant" + "merchant" ], "license": [ "MIT" @@ -17,8 +17,8 @@ ], "require": { "php": ">=5.6", - "nette/di": "~2.4.0", - "nette/utils": ">=2.4.0", + "nette/di": "^3.0", + "nette/utils": "3.1.6", "latte/latte": ">=2.4.0", "kdyby/console": ">=2.6.0", "sergiors/importing": "1.0.1" diff --git a/src/Command/FeedCommand.php b/src/Command/FeedCommand.php index e8c089d..5372287 100644 --- a/src/Command/FeedCommand.php +++ b/src/Command/FeedCommand.php @@ -1,24 +1,25 @@ config = $config; } - protected function configure() + + protected function configure(): void { $this->setName('Feed:export') ->setDescription('Export product feed') @@ -34,33 +36,26 @@ protected function configure() ->addOption('feed', 'f', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL); } + protected function execute(InputInterface $input, OutputInterface $output) { - $show = $input->getOption('show'); - $feeds = $input->getOption('feed'); - - if ($show) { + if ($input->getOption('show')) { $output->writeln('Available exports:'); - foreach ($this->config['exports'] as $k => $v) { if ($v) { $output->writeln('- ' . $k); } } } - - $feeds = $feeds ?: array_keys($this->config['exports']); - if (count($feeds)) { + if (\count($feeds = $input->getOption('feed') ?: array_keys($this->config['exports'])) > 0) { foreach ($feeds as $feed) { if (!isset($this->config['exports'][$feed]) || !$this->config['exports'][$feed]) { $output->writeln('Generator for ' . $feed . ' doesn\'t exist'); } - $generator = $this->container->getService('feed.' . $feed); - $generator->save($feed . '.xml'); $output->writeln('Feed ' . $feed . ' done'); } } } -} \ No newline at end of file +} diff --git a/src/DI/FeedExtension.php b/src/DI/FeedExtension.php index 9a38cb7..58a47cd 100644 --- a/src/DI/FeedExtension.php +++ b/src/DI/FeedExtension.php @@ -1,44 +1,40 @@ - * @package Mk\Feed\DI - */ -class FeedExtension extends Nette\DI\CompilerExtension { - /** @var array */ - private $defaults = array( - 'exportsDir' => '%wwwDir%', - 'exports' => array() - ); - - public function loadConfiguration() - { - parent::loadConfiguration(); - - $builder = $this->getContainerBuilder(); - $config = $this->getConfig($this->defaults); - - $builder->addDefinition($this->prefix('storage')) - ->setClass('\Mk\Feed\Storage', array($config['exportsDir'])); - - foreach ($config['exports'] as $export => $class) { - if (!class_exists($class)) { - } - $builder->addDefinition($this->prefix($export)) - ->setClass($class); - - } - - if (class_exists('\Symfony\Component\Console\Command\Command')) { - $builder->addDefinition($this->prefix('command')) - ->setClass('Mk\Feed\Command\FeedCommand', array($config)) - ->addTag('kdyby.console.command'); - } - } + +use Mk\Feed\Command\FeedCommand; +use Mk\Feed\Storage; +use Nette\DI\CompilerExtension; +use Symfony\Component\Console\Command\Command; + +final class FeedExtension extends CompilerExtension +{ + /** @var string[]|mixed[] */ + private array $defaults = [ + 'exportsDir' => '%wwwDir%', + 'exports' => [], + ]; + + + public function loadConfiguration(): void + { + $builder = $this->getContainerBuilder(); + $config = $this->getConfig($this->defaults); + + $builder->addDefinition($this->prefix('storage')) + ->setFactory(Storage::class, [$config['exportsDir']]); + + foreach ($config['exports'] as $export => $class) { + $builder->addDefinition($this->prefix($export)) + ->setFactory($class); + } + if (class_exists(Command::class)) { + $builder->addDefinition($this->prefix('command')) + ->setFactory(FeedCommand::class, [$config]) + ->addTag('kdyby.console.command'); + } + } } diff --git a/src/Generators/BaseGenerator.php b/src/Generators/BaseGenerator.php index d9bcc78..dd27a6c 100644 --- a/src/Generators/BaseGenerator.php +++ b/src/Generators/BaseGenerator.php @@ -1,115 +1,86 @@ storage = $storage; + } + + + public function addItem(IItem $item) + { + if (!$this->prepared) { + $this->prepare(); + } + if (!$item->validate()) { + throw new ItemIncompletedException('Item is not complete'); + } + + $latte = new Engine; + $xmlItem = $latte->renderToString($this->getTemplate('item'), ['item' => $item]); + fwrite($this->handle, $xmlItem); + } + + + /** Generate file by addItem from db for example. */ + abstract public function generate(): void; + + + public function save(string $filename): void + { + $this->generate(); + if (!$this->prepared) { + throw new FileEmptyException('File has not any items'); + } + + $this->prepareTemplate('footer'); + + $size = ftell($this->handle); + rewind($this->handle); + $this->storage->save($filename, fread($this->handle, $size)); + + fclose($this->handle); + + $this->prepared = false; + } + + + abstract protected function getTemplate(string $name): string; + + + protected function prepare(): void + { + $this->handle = tmpfile(); + $this->prepareTemplate('header'); + $this->prepared = true; + } + -/** - * Class BaseGenerator - * @author Martin Knor - * @package Mk\Feed\Generators - */ -abstract class BaseGenerator implements IGenerator { - - use SmartObject; - - /** @var bool true if some products added */ - private $prepared = false; - - /** @var resource|bool|null temp file */ - private $handle; - - /** @var \Mk\Feed\Storage */ - private $storage; - - /** - * BaseGenerator constructor. - * @param \Mk\Feed\Storage $storage - */ - public function __construct(Storage $storage) - { - $this->storage = $storage; - } - - /** - * @param $name - * @return string path to template - */ - abstract protected function getTemplate($name); - - - /** - * Prepare temp file - */ - protected function prepare() - { - $this->handle = tmpfile(); - $this->prepareTemplate('header'); - $this->prepared = true; - } - - /** - * @param \Mk\Feed\Generators\IItem $item - * @throws \Exception - * @throws \Throwable - */ - public function addItem(IItem $item) - { - if (!$this->prepared) { - $this->prepare(); - } - - if (!$item->validate()) { - throw new ItemIncompletedException('Item is not complete'); - } - - $latte = new Engine; - $xmlItem = $latte->renderToString($this->getTemplate('item'), array('item' => $item)); - fwrite($this->handle, $xmlItem); - } - - /** - * Generate file by addItem from db for example - * @return void - */ - abstract function generate(); - - /** - * @param $filename - * @return void - */ - public function save($filename) - { - $this->generate(); - - if (!$this->prepared) { - throw new FileEmptyException('File has not any items'); - } - - $this->prepareTemplate('footer'); - - $size = ftell($this->handle); - rewind($this->handle); - $this->storage->save($filename, fread($this->handle, $size)); - - fclose($this->handle); - - $this->prepared = false; - } - - /** - * @param $template - */ - protected function prepareTemplate($template) - { - $file = $this->getTemplate($template); - $footerHandle = fopen('safe://' . $file, 'r'); - $footer = fread($footerHandle, filesize($file)); - fclose($footerHandle); - fwrite($this->handle, $footer); - } - -} \ No newline at end of file + protected function prepareTemplate(string $template): void + { + $file = $this->getTemplate($template); + $footerHandle = fopen('safe://' . $file, 'rb'); + $footer = fread($footerHandle, filesize($file)); + fclose($footerHandle); + fwrite($this->handle, $footer); + } +} diff --git a/src/Generators/BaseItem.php b/src/Generators/BaseItem.php index a72bce5..55452a3 100644 --- a/src/Generators/BaseItem.php +++ b/src/Generators/BaseItem.php @@ -1,35 +1,22 @@ - * @package Mk\Feed\Generators\Zbozi - */ -abstract class BaseItem implements Mk\Feed\Generators\IItem +abstract class BaseItem implements IItem { - - use Nette\SmartObject; - - /** - * Validate item - * @return bool return true if item is valid - */ - public function validate() { - $reflection = $this->getReflection(); + public function validate(): bool + { + $reflection = new \ReflectionClass($this); foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $v) { - if ($v->getAnnotation('required')) { - if (!isset($this->{$v->getName()})) { - return FALSE; - } + if ($v->getAnnotation('required') && !isset($this->{$v->getName()})) { + return false; } } - return TRUE; + return true; } } diff --git a/src/Generators/Custom/CategoriesHelper.php b/src/Generators/Custom/CategoriesHelper.php index 834fd99..dfa1072 100644 --- a/src/Generators/Custom/CategoriesHelper.php +++ b/src/Generators/Custom/CategoriesHelper.php @@ -1,56 +1,60 @@ cache = new Cache($storage, __CLASS__); - } - } - - public function getCategories() - { - $categories = array(); - if (!$this->cache || !($categories = $this->cache->load('categories'))) { - $xml = file_get_contents(self::CATEGORY_URL); - $dom = new \DOMDocument(); - - $dom->loadXML($xml); - $xpath = new \DOMXPath($dom); - /** @var \DOMElement[] $_categories */ - $_categories = $xpath->query(".//CATEGORY"); - - foreach ($_categories as $category) { - $categoryIdElement = $xpath->query($category->getNodePath().'/CATEGORY_ID'); - $id = isset($categoryIdElement[0]) ? (int)$categoryIdElement[0]->nodeValue : null; - - $categoryFullNameElement = $xpath->query($category->getNodePath().'/CATEGORY_FULLNAME'); - $_cat = isset($categoryFullNameElement[0]) ? (string)$categoryFullNameElement[0]->nodeValue : null; - - if($id && $_cat) { - $_cat = str_replace('Heureka.cz | ', '', $_cat); - $categories[$id] = $_cat; - } - } - - asort($categories); - - if ($this->cache) { - $this->cache->save('categories', $categories); - } - } - - return $categories; - } -} \ No newline at end of file +final class CategoriesHelper +{ + public const CATEGORY_URL = 'http://www.heureka.cz/direct/xml-export/shops/heureka-sekce.xml'; + + private Cache $cache; + + + function __construct(?IStorage $storage = null) + { + if ($storage !== null) { + $this->cache = new Cache($storage, __CLASS__); + } + } + + + public function getCategories(): array + { + $categories = []; + if (!$this->cache || !($categories = $this->cache->load('categories'))) { + $xml = file_get_contents(self::CATEGORY_URL); + $dom = new \DOMDocument(); + + $dom->loadXML($xml); + $xpath = new \DOMXPath($dom); + /** @var \DOMElement[] $_categories */ + $_categories = $xpath->query(".//CATEGORY"); + + foreach ($_categories as $category) { + $categoryIdElement = $xpath->query($category->getNodePath() . '/CATEGORY_ID'); + $id = isset($categoryIdElement[0]) ? (int) $categoryIdElement[0]->nodeValue : null; + + $categoryFullNameElement = $xpath->query($category->getNodePath() . '/CATEGORY_FULLNAME'); + $_cat = isset($categoryFullNameElement[0]) ? (string) $categoryFullNameElement[0]->nodeValue : null; + + if ($id && $_cat) { + $_cat = str_replace('Heureka.cz | ', '', $_cat); + $categories[$id] = $_cat; + } + } + + asort($categories); + + if ($this->cache) { + $this->cache->save('categories', $categories); + } + } + + return $categories; + } +} diff --git a/src/Generators/Custom/Delivery.php b/src/Generators/Custom/Delivery.php index ccbfbe9..908f099 100644 --- a/src/Generators/Custom/Delivery.php +++ b/src/Generators/Custom/Delivery.php @@ -1,116 +1,96 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Delivery{ - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - CONST CESKA_POSTA = 'CESKA_POSTA', - CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', - CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', - DPD = 'DPD', - DHL = 'DHL', - DSV = 'DSV', - EMS = 'EMS', - FOFR = 'FOFR', - GEBRUDER_WEISS = 'GEBRUDER_WEISS', - GEIS = 'GEIS', - GENERAL_PARCEL = 'GENERAL_PARCEL', - GLS = 'GLS', - HDS = 'HDS', - HEUREKAPOINT = 'HEUREKAPOINT', - INTIME = 'INTIME', - PPL = 'PPL', - RADIALKA = 'RADIALKA', - SEEGMULLER = 'SEEGMULLER', - TNT = 'TNT', - TOPTRANS = 'TOPTRANS', - UPS = 'UPS', - ULOZENKA = 'ULOZENKA', - VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', - ZASILKOVNA = 'ZASILKOVNA'; - - static $ids = array( - self::CESKA_POSTA, - self::CESKA_POSTA_NA_POSTU, - self::CSAD_LOGISTIK_OSTRAVA, - self::DPD, - self::DHL, - self::DSV, - self::EMS, - self::FOFR, - self::GEBRUDER_WEISS, - self::GEIS, - self::GENERAL_PARCEL, - self::GLS, - self::HDS, - self::HEUREKAPOINT, - self::INTIME, - self::PPL, - self::RADIALKA, - self::SEEGMULLER, - self::TNT, - self::TOPTRANS, - self::UPS, - self::ULOZENKA, - self::VLASTNI_PREPRAVA, - self::ZASILKOVNA, - ); - - /** @var string */ - private $id; - /** @var float */ - private $price; - /** @var float|null */ - private $priceCod; - - /** - * Delivery constructor. - * @param $id - * @param $price - * @param null $priceCod - */ - public function __construct($id, $price, $priceCod = null) - { - if (!in_array($id, self::$ids)) { - throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); - } - $this->id = (string) $id; - $this->price = (float) $price; - $this->priceCod = isset($priceCod) ? (float) $priceCod : null; - } - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * @return float|null - */ - public function getPriceCod() - { - return $this->priceCod; - } +class Delivery +{ + public const CESKA_POSTA = 'CESKA_POSTA', + CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', + CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', + DPD = 'DPD', + DHL = 'DHL', + DSV = 'DSV', + EMS = 'EMS', + FOFR = 'FOFR', + GEBRUDER_WEISS = 'GEBRUDER_WEISS', + GEIS = 'GEIS', + GENERAL_PARCEL = 'GENERAL_PARCEL', + GLS = 'GLS', + HDS = 'HDS', + HEUREKAPOINT = 'HEUREKAPOINT', + INTIME = 'INTIME', + PPL = 'PPL', + RADIALKA = 'RADIALKA', + SEEGMULLER = 'SEEGMULLER', + TNT = 'TNT', + TOPTRANS = 'TOPTRANS', + UPS = 'UPS', + ULOZENKA = 'ULOZENKA', + VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', + ZASILKOVNA = 'ZASILKOVNA'; + + private static array $ids = [ + self::CESKA_POSTA, + self::CESKA_POSTA_NA_POSTU, + self::CSAD_LOGISTIK_OSTRAVA, + self::DPD, + self::DHL, + self::DSV, + self::EMS, + self::FOFR, + self::GEBRUDER_WEISS, + self::GEIS, + self::GENERAL_PARCEL, + self::GLS, + self::HDS, + self::HEUREKAPOINT, + self::INTIME, + self::PPL, + self::RADIALKA, + self::SEEGMULLER, + self::TNT, + self::TOPTRANS, + self::UPS, + self::ULOZENKA, + self::VLASTNI_PREPRAVA, + self::ZASILKOVNA, + ]; + + private string $id; + + private float $price; + + private ?float $priceCod; + + + public function __construct(string $id, float $price, ?float $priceCod = null) + { + if (\in_array($id, self::$ids, true) === false) { + throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); + } + $this->id = $id; + $this->price = $price; + $this->priceCod = $priceCod; + } + + + public function getId(): string + { + return $this->id; + } + + + public function getPrice(): float + { + return $this->price; + } + + + public function getPriceCod(): ?float + { + return $this->priceCod; + } } diff --git a/src/Generators/Custom/Generator.php b/src/Generators/Custom/Generator.php index a145492..cefa2a9 100644 --- a/src/Generators/Custom/Generator.php +++ b/src/Generators/Custom/Generator.php @@ -1,24 +1,18 @@ - * @package Mk\Feed\Generators - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -abstract class Generator extends BaseGenerator { +use Mk\Feed\Generators\BaseGenerator; - /** - * @param $name - * @return string - */ - protected function getTemplate($name) - { - $reflection = new \ReflectionClass(__CLASS__); - return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; - } +abstract class Generator extends BaseGenerator +{ + protected function getTemplate(string $name): string + { + $reflection = new \ReflectionClass(__CLASS__); -} \ No newline at end of file + return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; + } +} diff --git a/src/Generators/Custom/Gift.php b/src/Generators/Custom/Gift.php index d526d4f..08e54de 100644 --- a/src/Generators/Custom/Gift.php +++ b/src/Generators/Custom/Gift.php @@ -1,38 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Gift { +namespace Mk\Feed\Generators\Custom; - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - /** @var string */ - protected $name; +class Gift +{ + protected string $name; - /** - * @return string - */ - public function getName() - { - return $this->name; - } - /** - * Gift constructor. - * @param $name - */ - public function __construct($name) - { + public function __construct(string $name) + { + $this->name = $name; + } - $this->name = (string)$name; - } + public function getName(): string + { + return $this->name; + } } diff --git a/src/Generators/Custom/Image.php b/src/Generators/Custom/Image.php index 571ede7..ed3857e 100644 --- a/src/Generators/Custom/Image.php +++ b/src/Generators/Custom/Image.php @@ -1,40 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ class Image { - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - /** @var string */ - private $url; - - /** - * Image constructor. - * @param string $url - */ - public function __construct($url) - { - $this->url = (string) $url; - } + private string $url; - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } + public function __construct(string $url) + { + $this->url = $url; + } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/Generators/Custom/Item.php b/src/Generators/Custom/Item.php index 4c402e6..d6eb959 100644 --- a/src/Generators/Custom/Item.php +++ b/src/Generators/Custom/Item.php @@ -1,988 +1,820 @@ dues; + } + + + public function setDues(float $dues): self + { + $this->dues = $dues; + + return $this; + } + + + public function getVideoUrl(): string + { + return $this->videoUrl; + } + + + public function setVideoUrl(string $videoUrl): self + { + $this->videoUrl = $videoUrl; + + return $this; + } + + + public function addImage(string $url): self + { + $this->images[] = new Image($url); + + return $this; + } + + + public function addDelivery(string $id, float $price, ?float $priceCod = null): self + { + $this->deliveries[] = new Delivery($id, $price, $priceCod); + + return $this; + } + + + /** + * @return Delivery[] + */ + public function getDeliveries(): array + { + return $this->deliveries; + } + + + public function addParameter(string $name, $val, $unit = null): self + { + $this->parameters[] = new Parameter($name, $val, $unit); + + return $this; + } + + + public function addGift(string $name): self + { + $this->gifts[] = new Gift($name); + + return $this; + } + + + public function addAccessory(int $itemId): self + { + $this->accessories[] = $itemId; + + return $this; + } + + + /** + * @return int[] + */ + public function getAccessories(): array + { + return $this->accessories; + } + + + public function getProductName(): string + { + return $this->productName; + } + + + public function setProductName(string $productName): self + { + $this->productName = $productName; + + return $this; + } + + + public function getDescription(): string + { + return $this->description; + } + + + public function setDescription(string $description): self + { + $this->description = $description; + + return $this; + } + + + public function getUrl(): string + { + return $this->url; + } + + + public function setUrl(string $url): self + { + $this->url = $url; + + return $this; + } + + + public function getPriceVat(): float + { + return $this->priceVat; + } + + + public function setPriceVat(float $priceVat): self + { + $this->priceVat = $priceVat; + + return $this; + } + + + public function getDeliveryDate(): ?\DateTime + { + return $this->deliveryDate; + } + + + /** + * @param int|\DateTime|null $deliveryDate + * @return self + */ + public function setDeliveryDate($deliveryDate): self + { + if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { + throw new \InvalidArgumentException('Delivery date must be integer or DateTime, but type "' . \gettype($deliveryDate) . '" given.'); + } + $this->deliveryDate = DateTime::from($deliveryDate); + + return $this; + } + + + public function getItemId(): ?string + { + return $this->itemId; + } + + + public function setItemId(?string $itemId): self + { + $this->itemId = $itemId; + + return $this; + } + + + public function getEan(): ?string + { + return $this->ean; + } + + + public function setEan(?string $ean): self + { + $this->ean = $ean; + + return $this; + } + + + public function getIsbn(): ?string + { + return $this->isbn; + } + + + public function setIsbn(?string $isbn): self + { + $this->isbn = $isbn; + + return $this; + } + + + public function getItemGroupId(): ?string + { + return $this->itemGroupId; + } + + + public function setItemGroupId(?string $itemGroupId): self + { + $this->itemGroupId = $itemGroupId; + + return $this; + } + + + public function getManufacturer(): ?string + { + return $this->manufacturer; + } + + + public function setManufacturer(?string $manufacturer): self + { + $this->manufacturer = $manufacturer; + + return $this; + } + + + public function getCategoryText(): ?string + { + return $this->categoryText; + } + + + public function setCategoryText(?string $categoryText): self + { + $this->categoryText = $categoryText; + + return $this; + } + + + public function getProduct(): ?string + { + return $this->product; + } + + + public function setProduct(?string $product): self + { + $this->product = $product; + + return $this; + } + + + public function getItemType(): ?string + { + return $this->itemType; + } + + + /** + * @return Image[] + */ + public function getImages(): array + { + return $this->images; + } + + + /** + * @return Gift[] + */ + public function getGifts(): array + { + return $this->gifts; + } + + + /** + * @return Parameter[] + */ + public function getParameters(): array + { + return $this->parameters; + } + + + public function getHeurekaCpc(): ?string + { + return $this->heurekaCpc; + } + + + public function setHeurekaCpc(?string $heurekaCpc): self + { + $this->heurekaCpc = $heurekaCpc; + + return $this; + } + + + public function getStatus(): ?bool + { + return $this->status; + } + + + public function setStatus(bool $status): self + { + $this->status = $status; + + return $this; + } + + + public function getName(): ?string + { + return $this->name; + } + + + public function setName(?string $name): self + { + $this->name = $name; + + return $this; + } + + + public function getNameExt(): ?string + { + return $this->nameExt; + } + + + public function setNameExt(?string $nameExt): self + { + $this->nameExt = $nameExt; + + return $this; + } + + + public function getDescriptionShort(): ?string + { + return $this->descriptionShort; + } + + + public function setDescriptionShort(?string $descriptionShort): self + { + $this->descriptionShort = $descriptionShort; + + return $this; + } + + + public function getTitle(): ?string + { + return $this->title; + } + + + public function setTitle(?string $title): self + { + $this->title = $title; + + return $this; + } + + + public function getMetaDescription(): ?string + { + return $this->metaDescription; + } + + + public function setMetaDescription(?string $metaDescription): self + { + $this->metaDescription = $metaDescription; + + return $this; + } + + + public function getMetaKeywords(): ?string + { + return $this->metaKeywords; + } + + + public function setMetaKeywords(?string $metaKeywords): self + { + $this->metaKeywords = $metaKeywords; + + return $this; + } + + + public function getParts(): ?string + { + return $this->parts; + } + + + public function setParts(?string $parts): self + { + $this->parts = $parts; + + return $this; + } + + + public function getPriceOriginal(): ?float + { + return $this->priceOriginal; + } + + + public function setPriceOriginal(?float $priceOriginal): self + { + $this->priceOriginal = $priceOriginal; + + return $this; + } + + + public function getSoldQty(): ?int + { + return $this->soldQty; + } + + + public function setSoldQty(?int $soldQty): self + { + $this->soldQty = $soldQty; + + return $this; + } + + + public function getDefaultCategory(): ?string + { + return $this->defaultCategory; + } + + + public function setDefaultCategory(?string $defaultCategory): self + { + $this->defaultCategory = $defaultCategory; + + return $this; + } + + + public function getWeight(): ?float + { + return $this->weight; + } + + + public function setWeight(?float $weight): self + { + $this->weight = $weight; + + return $this; + } + + + public function getCost(): ?float + { + return $this->cost; + } + + + public function setCost(?float $cost): self + { + $this->cost = $cost; + + return $this; + } + + + public function getMargin(): ?float + { + return $this->margin; + } + + + public function setMargin(?float $margin): self + { + $this->margin = $margin; + + return $this; + } + + + public function getFreeDelivery(): ?bool + { + return $this->freeDelivery; + } + + + public function setFreeDelivery(?bool $freeDelivery): self + { + $this->freeDelivery = $freeDelivery; + + return $this; + } + + + public function getModel(): ?string + { + return $this->model; + } + + + public function setModel(?string $model): self + { + $this->model = $model; + + return $this; + } + + + public function isInSale(): ?bool + { + return $this->inSale; + } + + + public function setInSale(bool $inSale): self + { + $this->inSale = $inSale; + + return $this; + } + + + public function isArchived(): bool + { + return $this->archived; + } + + + public function setArchived(bool $archived): self + { + $this->archived = $archived; + + return $this; + } + + + public function getMinQuantity(): ?int + { + return $this->minQuantity; + } + + + public function setMinQuantity(?int $minQuantity): self + { + $this->minQuantity = $minQuantity; + + return $this; + } + + + public function getMaxQuantity(): ?int + { + return $this->maxQuantity; + } + + + public function setMaxQuantity(?int $maxQuantity): self + { + $this->maxQuantity = $maxQuantity; + + return $this; + } + + + public function getGuarantee(): ?string + { + return $this->guarantee; + } + + + public function setGuarantee(?string $guarantee): self + { + $this->guarantee = $guarantee; + + return $this; + } + + + public function getUnit(): ?string + { + return $this->unit; + } + + + public function setUnit(?string $unit): self + { + $this->unit = $unit; + + return $this; + } + + + public function getAvailability(): ?string + { + return $this->availability; + } + + + public function setAvailability(?string $availability): self + { + $this->availability = $availability; + + return $this; + } + + + public function getVat(): ?string + { + return $this->vat; + } + + + public function setVat(?string $vat): self + { + $this->vat = $vat; + + return $this; + } + + + public function getStock(): ?int + { + return $this->stock; + } + + + public function setStock(?int $stock): self + { + $this->stock = $stock; + + return $this; + } + + + public function getPriceNoVat(): float + { + return $this->priceNoVat; + } + + + public function setPriceNoVat(float $priceNoVat): self + { + $this->priceNoVat = $priceNoVat; + + return $this; + } + + + public function getSku(): ?string + { + return $this->sku; + } + + + public function setSku(?string $sku): self + { + $this->sku = $sku; -/** - * Class Item - * @property itemId - * @property heurekaCpc - * @author Martin Knor - * @package Mk\Feed\Generators\Heureka - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -class Item extends BaseItem { - - /** @var string @required */ - protected $itemId; - - /** @var string @required */ - protected $productName; - - /** @var string|null */ - protected $product; - - /** @var bool */ - protected $status; - - /** @var string|null */ - protected $name; - /** @var string |null*/ - protected $nameExt; - /** @var string |null*/ - protected $descriptionShort; - /** @var string |null*/ - protected $title; - /** @var string|null */ - protected $metaDescription; - /** @var string |null*/ - protected $metaKeywords; - /** @var string |null*/ - protected $parts; - /** @var float|null */ - protected $priceOriginal; - /** @var int |null*/ - protected $soldQty; - /** @var string |null*/ - protected $defaultCategory; - /** @var float|null */ - protected $weight; - /** @var float |null*/ - protected $cost; - /** @var float |null*/ - protected $margin; - /** @var bool|null */ - protected $freeDelivery; - /** @var string|null */ - protected $model; - /** @var bool */ - protected $inSale; - /** @var bool */ - protected $archived; - /** @var int |null*/ - protected $minQuantity; - /** @var int|null */ - protected $maxQuantity; - /** @var string|null */ - protected $guarantee; - /** @var string |null*/ - protected $unit; - /** @var string |null*/ - protected $vat; - /** @var int |null*/ - protected $stock; - /** @var string |null*/ - protected $sku; - - /** @var string[] */ - protected $suppliers; - - /** @var string | null */ - protected $availability; - - /** @var string @required */ - protected $description; - - /** @var string @required */ - protected $url; - - /** @var Image[] */ - protected $images = array(); - - /** @var string|null */ - protected $videoUrl; - - /** @var float @required */ - protected $priceVat; - /** @var float */ - protected $priceNoVat; - - /** @var string|null */ - protected $itemType; - - /** @var Parameter[] */ - protected $parameters = array(); - - /** @var string|null */ - protected $manufacturer; - - /** @var string|null */ - protected $categoryText; - - /** @var string|null */ - protected $ean; - - /** @var string|null */ - protected $isbn; - - /** @var float|null */ - protected $heurekaCpc; - - /** @var \DateTime|int @required */ - protected $deliveryDate; - - /** @var Delivery[] */ - protected $deliveries = array(); - - /** @var string|null */ - protected $itemGroupId; - - /** @var array */ - protected $accessories = array(); - - /** @var float */ - protected $dues = 0; - - /** @var Gift[] */ - protected $gifts = array(); - - /** - * @return float - */ - public function getDues() - { - return $this->dues; - } - - /** - * @param float $dues - * @return Item - */ - public function setDues($dues) - { - $this->dues = (float)$dues; - - return $this; - } - - /** - * @return string - */ - public function getVideoUrl() - { - return $this->videoUrl; - } - - /** - * @param string $videoUrl - * @return $this - */ - public function setVideoUrl($videoUrl) - { - $this->videoUrl = $videoUrl; - - return $this; - } - - /** - * @param $url - * @return $this - */ - public function addImage($url) - { - $this->images[] = new Image($url); - - return $this; - } - - /** - * @param $id - * @param $price - * @param null $priceCod - * @return $this - */ - public function addDelivery($id, $price, $priceCod = null) - { - $this->deliveries[] = new Delivery($id, $price, $priceCod); - - return $this; - } - - /** - * @return Delivery[] - */ - public function getDeliveries() - { - return $this->deliveries; - } - - /** - * @param $name - * @param $val - * @param null $unit - * @return Item - */ - public function addParameter($name, $val, $unit = null) - { - $this->parameters[] = new Parameter($name, $val, $unit); - - return $this; - } - - /** - * @param $name - * @return $this - */ - public function addGift($name) - { - $this->gifts[] = new Gift($name); - - return $this; - } - - /** - * @param $itemId - * @return $this - */ - public function addAccessory($itemId) - { - $this->accessories[] = $itemId; - - return $this; - } - - /** - * @return array - */ - public function getAccessories() - { - return $this->accessories; - } - - /** - * @return string - */ - public function getProductName() - { - return $this->productName; - } - - /** - * @param string $productName - * @return Item - */ - public function setProductName($productName) - { - $this->productName = (string)$productName; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return Item - */ - public function setDescription($description) - { - $this->description = (string)$description; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - * @return Item - */ - public function setUrl($url) - { - $this->url = (string)$url; - - return $this; - } - - /** - * @return float - */ - public function getPriceVat() - { - return $this->priceVat; - } - - /** - * @param float $priceVat - * @return Item - */ - public function setPriceVat($priceVat) - { - $this->priceVat = (float)$priceVat; - - return $this; - } - - /** - * @return int|string - */ - public function getDeliveryDate() - { - return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; - } - - /** - * @param int|\DateTime $deliveryDate - * @return Item - */ - public function setDeliveryDate($deliveryDate) - { - if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { - throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); - } - $this->deliveryDate = $deliveryDate; - - return $this; - } - - /** - * @return null|string - */ - public function getItemId() - { - return $this->itemId; - } - - /** - * @param null|string $itemId - * @return Item - */ - public function setItemId($itemId) - { - $this->itemId = $itemId; - - return $this; - } - - /** - * @return null|string - */ - public function getEan() - { - return $this->ean; - } - - /** - * @param null|string $ean - * @return Item - */ - public function setEan($ean) - { - $this->ean = $ean; - - return $this; - } - - /** - * @return null|string - */ - public function getIsbn() - { - return $this->isbn; - } - - /** - * @param null|string $isbn - * @return Item - */ - public function setIsbn($isbn) - { - $this->isbn = $isbn; - - return $this; - } - - /** - * @return null|string - */ - public function getItemGroupId() - { - return $this->itemGroupId; - } - - /** - * @param null|string $itemGroupId - * @return Item - */ - public function setItemGroupId($itemGroupId) - { - $this->itemGroupId = $itemGroupId; - - return $this; - } - - /** - * @return null|string - */ - public function getManufacturer() - { - return $this->manufacturer; - } - - /** - * @param null|string $manufacturer - * @return Item - */ - public function setManufacturer($manufacturer) - { - $this->manufacturer = $manufacturer; - - return $this; - } - - /** - * @return null|string - */ - public function getCategoryText() - { - return $this->categoryText; - } - - /** - * @param null|string $categoryText - * @return Item - */ - public function setCategoryText($categoryText) - { - $this->categoryText = $categoryText; - - return $this; - } - - /** - * @return null|string - */ - public function getProduct() - { - return $this->product; - } - - /** - * @param null|string $product - * @return Item - */ - public function setProduct($product) - { - $this->product = $product; - - return $this; - } - - /** - * @return null|string - */ - public function getItemType() - { - return $this->itemType; - } - - /** - * @return Image[] - */ - public function getImages() - { - return $this->images; - } - - /** - * @return Gift[] - */ - public function getGifts() - { - return $this->gifts; - } - - /** - * @return Parameter[] - */ - public function getParameters() - { - return $this->parameters; - } - - /** - * @return null|string - */ - public function getHeurekaCpc() - { - return $this->heurekaCpc; - } - - /** - * @param null|string $heurekaCpc - * @return $this - */ - public function setHeurekaCpc($heurekaCpc) - { - $this->heurekaCpc = $heurekaCpc; - - return $this; - } - - /** - * @return bool - */ - public function getStatus(): ?bool { - return $this->status; - } - - /** - * @param bool $status - * @return Item - */ - public function setStatus(bool $status): Item { - $this->status = $status; - return $this; - } - - /** - * @return null|string - */ - public function getName(): ?string { - return $this->name; - } - - /** - * @param null|string $name - * @return Item - */ - public function setName(?string $name): Item { - $this->name = $name; - return $this; - } - - /** - * @return null|string - */ - public function getNameExt(): ?string { - return $this->nameExt; - } - - /** - * @param null|string $nameExt - * @return Item - */ - public function setNameExt(?string $nameExt): Item { - $this->nameExt = $nameExt; - return $this; - } - - /** - * @return null|string - */ - public function getDescriptionShort(): ?string { - return $this->descriptionShort; - } - - /** - * @param null|string $descriptionShort - * @return Item - */ - public function setDescriptionShort(?string $descriptionShort): Item { - $this->descriptionShort = $descriptionShort; - return $this; - } - - /** - * @return null|string - */ - public function getTitle(): ?string { - return $this->title; - } - - /** - * @param null|string $title - * @return Item - */ - public function setTitle(?string $title): Item { - $this->title = $title; - return $this; - } - - /** - * @return null|string - */ - public function getMetaDescription(): ?string { - return $this->metaDescription; - } - - /** - * @param null|string $metaDescription - * @return Item - */ - public function setMetaDescription(?string $metaDescription): Item { - $this->metaDescription = $metaDescription; - return $this; - } - - /** - * @return null|string - */ - public function getMetaKeywords(): ?string { - return $this->metaKeywords; - } - - /** - * @param null|string $metaKeywords - * @return Item - */ - public function setMetaKeywords(?string $metaKeywords): Item { - $this->metaKeywords = $metaKeywords; - return $this; - } - - /** - * @return null|string - */ - public function getParts(): ?string { - return $this->parts; - } - - /** - * @param null|string $parts - * @return Item - */ - public function setParts(?string $parts): Item { - $this->parts = $parts; - return $this; - } - - /** - * @return float|null - */ - public function getPriceOriginal(): ?float { - return $this->priceOriginal; - } - - /** - * @param float|null $priceOriginal - * @return Item - */ - public function setPriceOriginal(?float $priceOriginal): Item { - $this->priceOriginal = $priceOriginal; - return $this; - } - - /** - * @return int|null - */ - public function getSoldQty(): ?int { - return $this->soldQty; - } - - /** - * @param int|null $soldQty - * @return Item - */ - public function setSoldQty(?int $soldQty): Item { - $this->soldQty = $soldQty; - return $this; - } - - /** - * @return null|string - */ - public function getDefaultCategory(): ?string { - return $this->defaultCategory; - } - - /** - * @param null|string $defaultCategory - * @return Item - */ - public function setDefaultCategory(?string $defaultCategory): Item { - $this->defaultCategory = $defaultCategory; - return $this; - } - - /** - * @return float|null - */ - public function getWeight(): ?float { - return $this->weight; - } - - /** - * @param float|null $weight - * @return Item - */ - public function setWeight(?float $weight): Item { - $this->weight = $weight; - return $this; - } - - /** - * @return float|null - */ - public function getCost(): ?float { - return $this->cost; - } - - /** - * @param float|null $cost - * @return Item - */ - public function setCost(?float $cost): Item { - $this->cost = $cost; - return $this; - } - - /** - * @return float|null - */ - public function getMargin(): ?float { - return $this->margin; - } - - /** - * @param float|null $margin - * @return Item - */ - public function setMargin(?float $margin): Item { - $this->margin = $margin; - return $this; - } - - /** - * @return bool|null - */ - public function getFreeDelivery(): ?bool { - return $this->freeDelivery; - } - - /** - * @param bool|null $freeDelivery - * @return Item - */ - public function setFreeDelivery(?bool $freeDelivery): Item { - $this->freeDelivery = $freeDelivery; - return $this; - } - - /** - * @return null|string - */ - public function getModel(): ?string { - return $this->model; - } - - /** - * @param null|string $model - * @return Item - */ - public function setModel(?string $model): Item { - $this->model = $model; - return $this; - } - - /** - * @return bool - */ - public function isInSale(): ?bool { - return $this->inSale; - } - - /** - * @param bool $inSale - * @return Item - */ - public function setInSale(bool $inSale): Item { - $this->inSale = $inSale; - return $this; - } - - /** - * @return bool - */ - public function isArchived(): bool { - return $this->archived; - } - - /** - * @param bool $archived - * @return Item - */ - public function setArchived(bool $archived): Item { - $this->archived = $archived; - return $this; - } - - /** - * @return int|null - */ - public function getMinQuantity(): ?int { - return $this->minQuantity; - } - - /** - * @param int|null $minQuantity - * @return Item - */ - public function setMinQuantity(?int $minQuantity): Item { - $this->minQuantity = $minQuantity; - return $this; - } - - /** - * @return int|null - */ - public function getMaxQuantity(): ?int { - return $this->maxQuantity; - } - - /** - * @param int|null $maxQuantity - * @return Item - */ - public function setMaxQuantity(?int $maxQuantity): Item { - $this->maxQuantity = $maxQuantity; - return $this; - } - - /** - * @return null|string - */ - public function getGuarantee(): ?string { - return $this->guarantee; - } - - /** - * @param null|string $guarantee - * @return Item - */ - public function setGuarantee(?string $guarantee): Item { - $this->guarantee = $guarantee; - return $this; - } - - /** - * @return null|string - */ - public function getUnit(): ?string { - return $this->unit; - } - - /** - * @param null|string $unit - * @return Item - */ - public function setUnit(?string $unit): Item { - $this->unit = $unit; - return $this; - } - - /** - * @return null|string - */ - public function getAvailability(): ?string { - return $this->availability; - } - - /** - * @param null|string $availability - * @return Item - */ - public function setAvailability(?string $availability): Item { - $this->availability = $availability; - return $this; - } - - /** - * @return null|string - */ - public function getVat(): ?string { - return $this->vat; - } - - /** - * @param null|string $vat - * @return Item - */ - public function setVat(?string $vat): Item { - $this->vat = $vat; - return $this; - } - - /** - * @return int|null - */ - public function getStock(): ?int { - return $this->stock; - } - - /** - * @param int|null $stock - * @return Item - */ - public function setStock(?int $stock): Item { - $this->stock = $stock; - return $this; - } - - /** - * @return float - */ - public function getPriceNoVat(){ - return $this->priceNoVat; - } - - /** - * @param float $priceNoVat - * @return Item - */ - public function setPriceNoVat(float $priceNoVat): Item { - $this->priceNoVat = $priceNoVat; - return $this; - } - - /** - * @return null|string - */ - public function getSku(): ?string { - return $this->sku; - } - - /** - * @param null|string $sku - * @return Item - */ - public function setSku(?string $sku): Item { - $this->sku = $sku; - return $this; - } - - /** - * @return string[] - */ - public function getSuppliers(): ?array { - return $this->suppliers; - } - - /** - * @param string[] $supplier - * @return Item - */ - public function addSupplier(string $supplier): Item { - $this->suppliers[] = $supplier; - return $this; - } + return $this; + } + /** + * @return string[]|null + */ + public function getSuppliers(): ?array + { + return $this->suppliers; + } + public function addSupplier(string $supplier): self + { + $this->suppliers[] = $supplier; + return $this; + } } diff --git a/src/Generators/Custom/Parameter.php b/src/Generators/Custom/Parameter.php index 9b00436..688911f 100644 --- a/src/Generators/Custom/Parameter.php +++ b/src/Generators/Custom/Parameter.php @@ -1,59 +1,41 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Parameter { - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - protected $name; - protected $value; - protected $unit; - - /** - * Parameter constructor. - * @param $name - * @param $value - * @param $unit - */ - public function __construct($name, $value, $unit = null) - { - $this->name = $name; - $this->value = $value; - - $this->unit = $unit; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; - } - - /** - * @return mixed - */ - public function getValue() - { - return $this->value; - } - - /** - * @return mixed - */ - public function getUnit() { - return $this->unit; - } + +class Parameter +{ + protected string $name; + + protected $value; + + protected $unit; + + + public function __construct($name, $value, $unit = null) + { + $this->name = $name; + $this->value = $value; + $this->unit = $unit; + } + + + public function getName() + { + return $this->name; + } + + + public function getValue() + { + return $this->value; + } + public function getUnit() + { + return $this->unit; + } } diff --git a/src/Generators/Custom/latte/item.latte b/src/Generators/Custom/latte/item.latte index 2bfc7f0..0001605 100644 --- a/src/Generators/Custom/latte/item.latte +++ b/src/Generators/Custom/latte/item.latte @@ -1,83 +1,90 @@ {contentType xml} - {$item->getItemId()} - {$item->getSku()} - getName()}]]> - getNameExt()}]]> - getDescription()|striptags|noescape}]]> - getDescriptionShort()|striptags|noescape}]]> - <![CDATA[{$item->getTitle()|striptags|noescape}]]> - getMetaDescription()|striptags|noescape}]]> - getMetaKeywords()|striptags|noescape}]]> - {$item->getParts()} - {$item->getSoldQty()} - {$item->getCategoryText()} - {$item->getWeight()} - {$item->getMargin()} - {$item->getFreeDelivery()} - {$item->getModel()} - {$item->isInSale()} - {$item->getMinQuantity()} - {$item->getMaxQuantity()} - {$item->getGuarantee()} - {$item->getUnit()} - {$item->getAvailability()} - {$item->getVat()} - {$item->getStock()} + {$item->getItemId()} + {$item->getSku()} + getName()}]]> + getNameExt()}]]> + getDescription()|striptags|noescape}]]> + + + getDescriptionShort()|striptags|noescape}]]> + + <![CDATA[{$item->getTitle()|striptags|noescape}]]> + + getMetaDescription()|striptags|noescape}]]> + + getMetaKeywords()|striptags|noescape}]]> + + {$item->getParts()} + {$item->getSoldQty()} + {$item->getCategoryText()} + {$item->getWeight()} + {$item->getMargin()} + {$item->getFreeDelivery()} + {$item->getModel()} + {$item->isInSale()} + {$item->getMinQuantity()} + {$item->getMaxQuantity()} + {$item->getGuarantee()} + {$item->getUnit()} + {$item->getAvailability()} + {$item->getVat()} + {$item->getStock()} - {$item->getUrl()} - {intval($item->getStatus())} + {$item->getUrl()} + {intval($item->getStatus())} - {if !empty($images = $item->getImages())} - {foreach $images as $image} - {var tag = $iterator->first ? 'IMGURL' : 'IMGURL_ALTERNATIVE'} - <{$tag}>{$image->getUrl()} - {/foreach} - {/if} + {if !empty($images = $item->getImages())} + {foreach $images as $image} + {var tag = $iterator->first ? 'IMGURL' : 'IMGURL_ALTERNATIVE'} + <{$tag}>{$image->getUrl()} + +{/foreach} +{/if} - {$item->getVideoUrl()} - {$item->getPriceOriginal()} - {$item->getCost()} - {$item->getPriceVat()} - {$item->getPriceNoVat()} +{$item->getVideoUrl()} +{$item->getPriceOriginal()} +{$item->getCost()} +{$item->getPriceVat()} +{$item->getPriceNoVat()} - {if !empty($parameters = $item->getParameters())} - - {$parameter->getName()} - {$parameter->getValue()}{$parameter->getUnit()} - - {/if} +{if !empty($parameters = $item->getParameters())} + +{$parameter->getName()} +{$parameter->getValue()}{$parameter->getUnit()} + +{/if} - getManufacturer()}]]> - {if $item->getSuppliers()} - - - - - - {/if} - getCategoryText()}]]> - {$item->getEan()} - {$item->getIsbn()} - {$item->getHeurekaCpc()} - {$item->getDeliveryDate()} +getManufacturer()}]]> +{if $item->getSuppliers()} + + + + + +{/if} +getCategoryText()}]]> +{$item->getEan()} +{$item->getIsbn()} +{$item->getHeurekaCpc()} + {$item->getDeliveryDate()} - {if !empty($deliveries = $item->getDeliveries())} - - {$delivery->getId()} - {$delivery->getPrice()} - {$delivery->getPriceCod()} - - {/if} +{if !empty($deliveries = $item->getDeliveries())} + + {$delivery->getId()} + {$delivery->getPrice()} + {$delivery->getPriceCod()} + +{/if} - {$item->getItemGroupId()} +{$item->getItemGroupId()} - {if !empty($accessories = $item->getAccessories())} - {$itemId} - {/if} +{if !empty($accessories = $item->getAccessories())} +{$itemId} +{/if} - {$item->getDues()} - {if !empty($gifts = $item->getGifts())} - {$gift->getName()} - {/if} +{$item->getDues()} +{if !empty($gifts = $item->getGifts())} +{$gift->getName()} +{/if} diff --git a/src/Generators/Glami/CategoriesHelper.php b/src/Generators/Glami/CategoriesHelper.php index 6a29324..bb2f137 100644 --- a/src/Generators/Glami/CategoriesHelper.php +++ b/src/Generators/Glami/CategoriesHelper.php @@ -1,56 +1,54 @@ cache = new Cache($storage, __CLASS__); - } - } - - public function getCategories() - { - $categories = array(); - if (!$this->cache || !($categories = $this->cache->load('categories'))) { - $xml = file_get_contents(self::CATEGORY_URL); - $dom = new \DOMDocument(); - - $dom->loadXML($xml); - $xpath = new \DOMXPath($dom); - /** @var \DOMElement[] $_categories */ - $_categories = $xpath->query(".//CATEGORY"); - - foreach ($_categories as $category) { - $categoryIdElement = $xpath->query($category->getNodePath().'/CATEGORY_ID'); - $id = isset($categoryIdElement[0]) ? (int)$categoryIdElement[0]->nodeValue : null; - - $categoryFullNameElement = $xpath->query($category->getNodePath().'/CATEGORY_FULLNAME'); - $_cat = isset($categoryFullNameElement[0]) ? (string)$categoryFullNameElement[0]->nodeValue : null; - - if($id && $_cat) { - $_cat = str_replace('Glami.cz | ', '', $_cat); - $categories[$id] = $_cat; - } - } - - asort($categories); - - if ($this->cache) { - $this->cache->save('categories', $categories); - } - } - - return $categories; - } -} \ No newline at end of file +class CategoriesHelper +{ + public const CATEGORY_URL = 'https://www.glami.cz/category-xml/'; + + private Cache $cache; + + + public function __construct(IStorage $storage = null) + { + if ($storage !== null) { + $this->cache = new Cache($storage, __CLASS__); + } + } + + + public function getCategories() + { + $categories = []; + if (!$this->cache || !($categories = $this->cache->load('categories'))) { + $dom = new \DOMDocument(); + $dom->loadXML(file_get_contents(self::CATEGORY_URL)); + $xpath = new \DOMXPath($dom); + /** @var \DOMElement[] $_categories */ + $_categories = $xpath->query(".//CATEGORY"); + foreach ($_categories as $category) { + $categoryIdElement = $xpath->query($category->getNodePath() . '/CATEGORY_ID'); + $id = isset($categoryIdElement[0]) ? (int) $categoryIdElement[0]->nodeValue : null; + $categoryFullNameElement = $xpath->query($category->getNodePath() . '/CATEGORY_FULLNAME'); + $_cat = isset($categoryFullNameElement[0]) ? (string) $categoryFullNameElement[0]->nodeValue : null; + + if ($id && $_cat) { + $_cat = str_replace('Glami.cz | ', '', $_cat); + $categories[$id] = $_cat; + } + } + asort($categories); + if ($this->cache) { + $this->cache->save('categories', $categories); + } + } + + return $categories; + } +} diff --git a/src/Generators/Google/Generator.php b/src/Generators/Google/Generator.php index 7ba9fc3..a9e4352 100644 --- a/src/Generators/Google/Generator.php +++ b/src/Generators/Google/Generator.php @@ -1,24 +1,19 @@ - * @package Mk\Feed\Generators\Google - * @see https://support.google.com/merchants/answer/188494 Documentation - */ -abstract class Generator extends BaseGenerator { +use Mk\Feed\Generators\BaseGenerator; - /** - * @param $name - * @return string - */ - protected function getTemplate($name) - { - $reflection = new \ReflectionClass(__CLASS__); - return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; - } +/** @see https://support.google.com/merchants/answer/188494 */ +abstract class Generator extends BaseGenerator +{ + protected function getTemplate(string $name): string + { + $reflection = new \ReflectionClass(__CLASS__); -} \ No newline at end of file + return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; + } +} diff --git a/src/Generators/Google/Image.php b/src/Generators/Google/Image.php index 61f3f2d..5d7c326 100644 --- a/src/Generators/Google/Image.php +++ b/src/Generators/Google/Image.php @@ -1,40 +1,23 @@ - * @package Mk\Feed\Generators\Google - */ -class Image +final class Image { + private string $url; - use Nette\SmartObject; - - /** @var string */ - private $url; - - /** - * Image constructor. - * @param string $url - */ - public function __construct($url) - { - $this->url = (string) $url; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } + public function __construct(string $url) + { + $this->url = $url; + } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/Generators/Google/Item.php b/src/Generators/Google/Item.php index 4976d2d..0ce2e02 100644 --- a/src/Generators/Google/Item.php +++ b/src/Generators/Google/Item.php @@ -2,11 +2,13 @@ namespace Mk\Feed\Generators\Google; -use Mk, Nette; + +use Mk; use Mk\Feed\Generators\BaseItem; /** * Class Item + * * @property string $id * @property $title * @property $description @@ -28,431 +30,468 @@ * @author Martin Knor * @package Mk\Feed\Generators\Google */ -class Item extends BaseItem { - - CONST CONDITION_NEW = 'new', - CONDITION_REFURBISHED = 'refurbished', - CONDITION_USED = 'used', - - AVAILABILITY_PREORDER = 'preorder', - AVAILABILITY_IN_STOCK = 'in stock', - AVAILABILITY_OUT_OF_STOCK = 'out of stock'; - - static $conditions = array( - self::CONDITION_NEW, - self::CONDITION_REFURBISHED, - self::CONDITION_USED, - ); - - static $availabilities = array( - self::AVAILABILITY_PREORDER, - self::AVAILABILITY_IN_STOCK, - self::AVAILABILITY_OUT_OF_STOCK, - ); - - /** @var string @required */ - protected $id; - - /** @var string @required */ - protected $title; - - /** @var string @required */ - protected $description; - - /** @var string|null */ - protected $googleProductCategory; - - /** @var ProductType[] */ - protected $productTypes = array(); - - /** @var string @required */ - protected $link; - - /** @var string|null */ - protected $mobileLink; - - /** @var Image[] */ - protected $images = array(); - - /** @var string|null */ - protected $condition = self::CONDITION_NEW; - - /** @var string @required */ - protected $availability = self::AVAILABILITY_IN_STOCK; - - /** @var \DateTime|null */ - protected $availabilityDate; - - /** @var string @required */ - protected $price; - - /** @var string */ - protected $salePrice; - - /** @var string */ - protected $salePriceEffectiveDate; - - /** @var int */ - protected $gtin; - - /** @var string */ - protected $mpn; - - /** @var string */ - protected $brand; - - /** @var bool */ - protected $identifierExists; - - protected $labels = []; - - /** @var string */ - protected $unitPricingMeasure; - - /** @var string */ - protected $itemGroupId; - - /** @var array */ - protected $params; - - /** @var string */ - protected $currency; - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $id - * @return Item - */ - public function setId($id) - { - $this->id = $id; - - return $this; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param string $title - * @return Item - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return Item - */ - public function setDescription($description) - { - $this->description = $description; - - return $this; - } - - /** - * @return null|string - */ - public function getGoogleProductCategory() - { - return $this->googleProductCategory; - } - - /** - * @param null|string $googleProductCategory - * @return Item - */ - public function setGoogleProductCategory($googleProductCategory) - { - $this->googleProductCategory = $googleProductCategory; - - return $this; - } - - /** - * @return string - */ - public function getLink() - { - return $this->link; - } - - /** - * @param string $link - * @return Item - */ - public function setLink($link) - { - $this->link = $link; - - return $this; - } - - /** - * @return null|string - */ - public function getMobileLink() - { - return $this->mobileLink; - } - - /** - * @param null|string $mobileLink - * @return Item - */ - public function setMobileLink($mobileLink) - { - $this->mobileLink = $mobileLink; - - return $this; - } - - /** - * @return string - */ - public function getPrice() - { - return $this->price; - } - - /** - * @param string $price - * @return Item - */ - public function setPrice($price) - { - $this->price = $price; - - return $this; - } - - /** - * @return string - */ - public function getSalePrice() - { - return $this->salePrice; - } - - /** - * @param string $salePrice - * @return Item - */ - public function setSalePrice($salePrice) - { - $this->salePrice = $salePrice; - - return $this; - } - - /** - * @return string - */ - public function getSalePriceEffectiveDate() - { - return $this->salePriceEffectiveDate; - } - - /** - * @param string $salePriceEffectiveDate - * @return Item - */ - public function setSalePriceEffectiveDate($salePriceEffectiveDate) - { - $this->salePriceEffectiveDate = $salePriceEffectiveDate; - - return $this; - } - - /** - * @return int - */ - public function getGtin() - { - return $this->gtin; - } - - /** - * @param int $gtin - * @return Item - */ - public function setGtin($gtin) - { - $this->gtin = $gtin; - - return $this; - } - - /** - * @return string - */ - public function getMpn() - { - return $this->mpn; - } - - /** - * @param string $mpn - * @return Item - */ - public function setMpn($mpn) - { - $this->mpn = $mpn; - - return $this; - } - - /** - * @return string - */ - public function getBrand() - { - return $this->brand; - } - - /** - * @param string $brand - * @return Item - */ - public function setBrand($brand) - { - $this->brand = $brand; - - return $this; - } - - /** - * @return boolean - */ - public function isIdentifierExists() - { - return $this->identifierExists; - } - - /** - * @param boolean $identifierExists - * @return Item - */ - public function setIdentifierExists($identifierExists) - { - $this->identifierExists = $identifierExists; - - return $this; - } - - /** - * @return \DateTime|null - */ - public function getAvailabilityDate() - { - return $this->availabilityDate instanceof \DateTime ? $this->availabilityDate->format('c') : $this->availabilityDate; - } - - /** - * @param \DateTime|null $availabilityDate - * @return Item - */ - public function setAvailabilityDate(\DateTime $availabilityDate = null) - { - $this->availabilityDate = $availabilityDate; - - return $this; - } - - /** - * @return float - */ - public function getAvailability() - { - return $this->availability; - } - - /** - * @param float $availability - * @return Item - */ - public function setAvailability($availability) - { - if (!in_array($availability, self::$availabilities)) { - throw new \InvalidArgumentException("Availability with id $availability doesn\t exist"); - } - $this->availability = $availability; - - return $this; - } - - /** - * @param $url - * @return $this - */ - public function addImage($url) - { - $this->images[] = new Image($url); - - return $this; - } - - public function addProductType($text) - { - $this->productTypes[] = new ProductType($text); - - return $this; - } - - /** - * @return ProductType[] - */ - public function getProductTypes() - { - return $this->productTypes; - } - - /** - * @return null|string - */ - public function getCondition() - { - return $this->condition; - } - - /** - * @param null|string $condition - * @return Item - */ - public function setCondition($condition) - { - if (!in_array($condition, self::$conditions)) { - throw new \InvalidArgumentException("Condition with id $condition doesn\t exist"); - } - $this->condition = $condition; - - return $this; - } +class Item extends BaseItem +{ + + const CONDITION_NEW = 'new', + CONDITION_REFURBISHED = 'refurbished', + CONDITION_USED = 'used', + + AVAILABILITY_PREORDER = 'preorder', + AVAILABILITY_IN_STOCK = 'in stock', + AVAILABILITY_OUT_OF_STOCK = 'out of stock'; + + static $conditions = [ + self::CONDITION_NEW, + self::CONDITION_REFURBISHED, + self::CONDITION_USED, + ]; + + static $availabilities = [ + self::AVAILABILITY_PREORDER, + self::AVAILABILITY_IN_STOCK, + self::AVAILABILITY_OUT_OF_STOCK, + ]; + + /** @var string @required */ + protected $id; + + /** @var string @required */ + protected $title; + + /** @var string @required */ + protected $description; + + /** @var string|null */ + protected $googleProductCategory; + + /** @var ProductType[] */ + protected $productTypes = []; + + /** @var string @required */ + protected $link; + + /** @var string|null */ + protected $mobileLink; + + /** @var Image[] */ + protected $images = []; + + /** @var string|null */ + protected $condition = self::CONDITION_NEW; + + /** @var string @required */ + protected $availability = self::AVAILABILITY_IN_STOCK; + + /** @var \DateTime|null */ + protected $availabilityDate; + + /** @var string @required */ + protected $price; + + /** @var string */ + protected $salePrice; + + /** @var string */ + protected $salePriceEffectiveDate; + + /** @var int */ + protected $gtin; + + /** @var string */ + protected $mpn; + + /** @var string */ + protected $brand; + + /** @var bool */ + protected $identifierExists; + + protected $labels = []; + + /** @var string */ + protected $unitPricingMeasure; + + /** @var string */ + protected $itemGroupId; + + /** @var array */ + protected $params; + + /** @var string */ + protected $currency; + + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + + /** + * @param string $id + * @return Item + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + + /** + * @param string $title + * @return Item + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + + /** + * @param string $description + * @return Item + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + + /** + * @return null|string + */ + public function getGoogleProductCategory() + { + return $this->googleProductCategory; + } + + + /** + * @param null|string $googleProductCategory + * @return Item + */ + public function setGoogleProductCategory($googleProductCategory) + { + $this->googleProductCategory = $googleProductCategory; + + return $this; + } + + + /** + * @return string + */ + public function getLink() + { + return $this->link; + } + + + /** + * @param string $link + * @return Item + */ + public function setLink($link) + { + $this->link = $link; + + return $this; + } + + + /** + * @return null|string + */ + public function getMobileLink() + { + return $this->mobileLink; + } + + + /** + * @param null|string $mobileLink + * @return Item + */ + public function setMobileLink($mobileLink) + { + $this->mobileLink = $mobileLink; + + return $this; + } + + + /** + * @return string + */ + public function getPrice() + { + return $this->price; + } + + + /** + * @param string $price + * @return Item + */ + public function setPrice($price) + { + $this->price = $price; + + return $this; + } + + + /** + * @return string + */ + public function getSalePrice() + { + return $this->salePrice; + } + + + /** + * @param string $salePrice + * @return Item + */ + public function setSalePrice($salePrice) + { + $this->salePrice = $salePrice; + + return $this; + } + + + /** + * @return string + */ + public function getSalePriceEffectiveDate() + { + return $this->salePriceEffectiveDate; + } + + + /** + * @param string $salePriceEffectiveDate + * @return Item + */ + public function setSalePriceEffectiveDate($salePriceEffectiveDate) + { + $this->salePriceEffectiveDate = $salePriceEffectiveDate; + + return $this; + } + + + /** + * @return int + */ + public function getGtin() + { + return $this->gtin; + } + + + /** + * @param int $gtin + * @return Item + */ + public function setGtin($gtin) + { + $this->gtin = $gtin; + + return $this; + } + + + /** + * @return string + */ + public function getMpn() + { + return $this->mpn; + } + + + /** + * @param string $mpn + * @return Item + */ + public function setMpn($mpn) + { + $this->mpn = $mpn; + + return $this; + } + + + /** + * @return string + */ + public function getBrand() + { + return $this->brand; + } + + + /** + * @param string $brand + * @return Item + */ + public function setBrand($brand) + { + $this->brand = $brand; + + return $this; + } + + + /** + * @return boolean + */ + public function isIdentifierExists() + { + return $this->identifierExists; + } + + + /** + * @param boolean $identifierExists + * @return Item + */ + public function setIdentifierExists($identifierExists) + { + $this->identifierExists = $identifierExists; + + return $this; + } + + + /** + * @return \DateTime|null + */ + public function getAvailabilityDate() + { + return $this->availabilityDate instanceof \DateTime ? $this->availabilityDate->format('c') : $this->availabilityDate; + } + + + /** + * @param \DateTime|null $availabilityDate + * @return Item + */ + public function setAvailabilityDate(\DateTime $availabilityDate = null) + { + $this->availabilityDate = $availabilityDate; + + return $this; + } + + + /** + * @return float + */ + public function getAvailability() + { + return $this->availability; + } + + + /** + * @param float $availability + * @return Item + */ + public function setAvailability($availability) + { + if (!in_array($availability, self::$availabilities)) { + throw new \InvalidArgumentException("Availability with id $availability doesn\t exist"); + } + $this->availability = $availability; + + return $this; + } + + + /** + * @param $url + * @return $this + */ + public function addImage($url) + { + $this->images[] = new Image($url); + + return $this; + } + + + public function addProductType($text) + { + $this->productTypes[] = new ProductType($text); + + return $this; + } + + + /** + * @return ProductType[] + */ + public function getProductTypes() + { + return $this->productTypes; + } + + + /** + * @return null|string + */ + public function getCondition() + { + return $this->condition; + } + + + /** + * @param null|string $condition + * @return Item + */ + public function setCondition($condition) + { + if (!in_array($condition, self::$conditions)) { + throw new \InvalidArgumentException("Condition with id $condition doesn\t exist"); + } + $this->condition = $condition; + + return $this; + } + /** * @return Image[] @@ -462,6 +501,7 @@ public function getImages() return $this->images; } + /** * @return array */ @@ -470,16 +510,19 @@ public function getLabels() return $this->labels; } - public function addLabel($label) - { - $this->labels[] = $label; - } public function setLabels(array $labels) { $this->labels = $labels; } - + + + public function addLabel($label) + { + $this->labels[] = $label; + } + + public function getUnitPricingMeasure(): string { return $this->unitPricingMeasure; @@ -491,52 +534,59 @@ public function setUnitPricingMeasure(string $unitPricingMeasure): void $this->unitPricingMeasure = $unitPricingMeasure; } - /** - * @return string - */ - public function getItemGroupId(): ?string { - return $this->itemGroupId; - } - /** - * @param string $itemGroupId - */ - public function setItemGroupId(string $itemGroupId): void { - $this->itemGroupId = $itemGroupId; - } + /** + * @return string + */ + public function getItemGroupId(): ?string + { + return $this->itemGroupId; + } - public function addParam($name, $value){ - $this->params[$name] = $value; - } - /** - * @return array - */ - public function getParams(): array { - return $this->params; - } + /** + * @param string $itemGroupId + */ + public function setItemGroupId(string $itemGroupId): void + { + $this->itemGroupId = $itemGroupId; + } + - /** - * @return string - */ - public function getCurrency(): string { - return $this->currency; - } + public function addParam($name, $value) + { + $this->params[$name] = $value; + } - /** - * @param string $currency - * @return Item - */ - public function setCurrency(string $currency): Item { - $this->currency = $currency; - return $this; - } + /** + * @return array + */ + public function getParams(): array + { + return $this->params; + } + /** + * @return string + */ + public function getCurrency(): string + { + return $this->currency; + } + /** + * @param string $currency + * @return Item + */ + public function setCurrency(string $currency): Item + { + $this->currency = $currency; + return $this; + } } diff --git a/src/Generators/Google/ProductType.php b/src/Generators/Google/ProductType.php index a3ef6f1..4e467de 100644 --- a/src/Generators/Google/ProductType.php +++ b/src/Generators/Google/ProductType.php @@ -1,38 +1,24 @@ - * @package Mk\Feed\Generators\Google - */ -class ProductType{ - - use Nette\SmartObject; - - /** @var string */ - protected $text; - - /** - * ProductType constructor. - * @param $text - */ - public function __construct($text) - { - - $this->text = (string)$text; - } - - /** - * @return string - */ - public function getText() - { - return $this->text; - } +class ProductType +{ + protected string $text; + + + public function __construct(string $text) + { + $this->text = $text; + } + + + public function getText(): string + { + return $this->text; + } } + diff --git a/src/Generators/Google/latte/header.latte b/src/Generators/Google/latte/header.latte index f17c5a9..7025f94 100644 --- a/src/Generators/Google/latte/header.latte +++ b/src/Generators/Google/latte/header.latte @@ -1,6 +1,7 @@ - - - {$storeName} - {$link} - {$description} + + + {$storeName} + + {$link} + {$description} diff --git a/src/Generators/Google/latte/item.latte b/src/Generators/Google/latte/item.latte index dbec1c1..6aefaa4 100644 --- a/src/Generators/Google/latte/item.latte +++ b/src/Generators/Google/latte/item.latte @@ -1,43 +1,50 @@ {contentType xml} - {$item->getId()} - <![CDATA[{$item->getTitle()}]]> - getDescription()|striptags|noescape}]]> - getLink()}]]> + {$item->getId()} + <![CDATA[{$item->getTitle()}]]> + getDescription()|striptags|noescape}]]> + + getLink()}]]> - {if !empty($images = $item->getImages())} - {foreach $images as $image} - {var tag = $iterator->first ? 'g:image_link' : 'g:additional_image_link'} - <{$tag}>getUrl()}]]> - {/foreach} - {/if} + {if !empty($images = $item->getImages())} + {foreach $images as $image} + {var tag = $iterator->first ? 'g:image_link' : 'g:additional_image_link'} + <{$tag}>getUrl()}]]> + +{/foreach} +{/if} - {$item->getCondition()} - {$item->getAvailability()} - {$item->getPrice()} {$item->getCurrency()} - {$item->isIdentifierExists() ? 'TRUE' : 'FALSE'} - {$item->getSalePrice()} - {if $item->getGtin()}{$item->getGtin()}{/if} - {$item->getBrand()} - {$item->getLabels()[0]} - {$item->getLabels()[1]} - {$item->getLabels()[2]} - {$item->getLabels()[3]} - {$item->getLabels()[4]} - {*Female - Adult - Navy - 8 Standard*} - {if $item->getMpn()}{$item->getMpn()}{/if} +{$item->getCondition()} +{$item->getAvailability()} +{$item->getPrice()} {$item->getCurrency()} +{$item->isIdentifierExists() ? 'TRUE' : 'FALSE'} +{$item->getSalePrice()} +{if $item->getGtin()}{$item->getGtin()}{/if} +{$item->getBrand()} +{$item->getLabels()[0]} +{$item->getLabels()[1]} +{$item->getLabels()[2]} +{$item->getLabels()[3]} +{$item->getLabels()[4]} +{* +Female +Adult +Navy +8 Standard*} +{if $item->getMpn()}{$item->getMpn()}{/if} - {if !empty($productTypes = $item->getProductTypes())} - {$productType->getText()} - {/if} +{if !empty($productTypes = $item->getProductTypes())} + + {$productType->getText()} + +{/if} - {$item->getGoogleProductCategory()} - {$item->getItemGroupId()} - {*{$value}*} +{$item->getGoogleProductCategory()} + +{$item->getItemGroupId()} +{* +{$value}*} diff --git a/src/Generators/Heureka/CategoriesHelper.php b/src/Generators/Heureka/CategoriesHelper.php index 2d55a78..d510a24 100644 --- a/src/Generators/Heureka/CategoriesHelper.php +++ b/src/Generators/Heureka/CategoriesHelper.php @@ -2,76 +2,63 @@ namespace Mk\Feed\Generators\Heureka; + use Nette\Caching\Cache; use Nette\Caching\IStorage; -class CategoriesHelper { - - CONST CATEGORY_URL = 'http://www.heureka.cz/direct/xml-export/shops/heureka-sekce.xml'; - CONST CATEGORY_SK_URL = 'http://www.heureka.sk/direct/xml-export/shops/heureka-sekce.xml'; - - /** @var \Nette\Caching\Cache */ - private $cache; - - /** @var bool */ - private $sk; - - function __construct(IStorage $storage = null) - { - if ($storage) { - $this->cache = new Cache($storage, __CLASS__); - } - $this->sk = false; - } - - /** - * @param bool $sk - * @return CategoriesHelper - */ - public function setSk(bool $sk): CategoriesHelper { - $this->sk = $sk; - return $this; - } - - - - - public function getCategories() - { - $categories = array(); - if (!$this->cache || !($categories = $this->cache->load('categories'))) { - if ($this->sk) { - $xml = file_get_contents(self::CATEGORY_SK_URL); - } else { - $xml = file_get_contents(self::CATEGORY_URL); - } - $dom = new \DOMDocument(); - - $dom->loadXML($xml); - $xpath = new \DOMXPath($dom); - /** @var \DOMElement[] $_categories */ - $_categories = $xpath->query(".//CATEGORY"); - - foreach ($_categories as $category) { - $categoryIdElement = $xpath->query($category->getNodePath().'/CATEGORY_ID'); - $id = isset($categoryIdElement[0]) ? (int)$categoryIdElement[0]->nodeValue : null; - - $categoryFullNameElement = $xpath->query($category->getNodePath().'/CATEGORY_FULLNAME'); - $_cat = isset($categoryFullNameElement[0]) ? (string)$categoryFullNameElement[0]->nodeValue : null; - - if($id && $_cat) { - $_cat = str_replace('Heureka.cz | ', '', $_cat); - $categories[$id] = $_cat; - } - } - - asort($categories); - - if ($this->cache) { - $this->cache->save('categories', $categories); - } - } - - return $categories; - } -} \ No newline at end of file +class CategoriesHelper +{ + public const CATEGORY_URL = 'http://www.heureka.cz/direct/xml-export/shops/heureka-sekce.xml'; + + public const CATEGORY_SK_URL = 'http://www.heureka.sk/direct/xml-export/shops/heureka-sekce.xml'; + + private Cache $cache; + + private bool $sk; + + + public function __construct(IStorage $storage = null) + { + if ($storage !== null) { + $this->cache = new Cache($storage, __CLASS__); + } + $this->sk = false; + } + + + public function setSk(bool $sk): CategoriesHelper + { + $this->sk = $sk; + + return $this; + } + + + public function getCategories(): array + { + $categories = []; + if (!$this->cache || !($categories = $this->cache->load('categories'))) { + $dom = new \DOMDocument(); + $dom->loadXML(file_get_contents($this->sk ? self::CATEGORY_SK_URL : self::CATEGORY_URL)); + $xpath = new \DOMXPath($dom); + /** @var \DOMElement[] $_categories */ + $_categories = $xpath->query(".//CATEGORY"); + foreach ($_categories as $category) { + $categoryIdElement = $xpath->query($category->getNodePath() . '/CATEGORY_ID'); + $id = isset($categoryIdElement[0]) ? (int) $categoryIdElement[0]->nodeValue : null; + $categoryFullNameElement = $xpath->query($category->getNodePath() . '/CATEGORY_FULLNAME'); + $_cat = isset($categoryFullNameElement[0]) ? (string) $categoryFullNameElement[0]->nodeValue : null; + if ($id && $_cat) { + $_cat = str_replace('Heureka.cz | ', '', $_cat); + $categories[$id] = $_cat; + } + } + asort($categories); + if ($this->cache) { + $this->cache->save('categories', $categories); + } + } + + return $categories; + } +} diff --git a/src/Generators/Heureka/Delivery.php b/src/Generators/Heureka/Delivery.php index c427d6e..34bfc10 100644 --- a/src/Generators/Heureka/Delivery.php +++ b/src/Generators/Heureka/Delivery.php @@ -1,111 +1,92 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Delivery{ - - use Nette\SmartObject; - - CONST CESKA_POSTA = 'CESKA_POSTA', - CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', - CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', - DPD = 'DPD', - DHL = 'DHL', - DSV = 'DSV', - EMS = 'EMS', - FOFR = 'FOFR', - GEBRUDER_WEISS = 'GEBRUDER_WEISS', - GEIS = 'GEIS', - GENERAL_PARCEL = 'GENERAL_PARCEL', - GLS = 'GLS', - HDS = 'HDS', - HEUREKAPOINT = 'HEUREKAPOINT', - INTIME = 'INTIME', - PPL = 'PPL', - RADIALKA = 'RADIALKA', - SEEGMULLER = 'SEEGMULLER', - TNT = 'TNT', - TOPTRANS = 'TOPTRANS', - UPS = 'UPS', - VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA'; - - static $ids = array( - self::CESKA_POSTA, - self::CESKA_POSTA_NA_POSTU, - self::CSAD_LOGISTIK_OSTRAVA, - self::DPD, - self::DHL, - self::DSV, - self::EMS, - self::FOFR, - self::GEBRUDER_WEISS, - self::GEIS, - self::GENERAL_PARCEL, - self::GLS, - self::HDS, - self::HEUREKAPOINT, - self::INTIME, - self::PPL, - self::RADIALKA, - self::SEEGMULLER, - self::TNT, - self::TOPTRANS, - self::UPS, - self::VLASTNI_PREPRAVA, - ); - - /** @var string */ - private $id; - /** @var float */ - private $price; - /** @var float|null */ - private $priceCod; - - /** - * Delivery constructor. - * @param $id - * @param $price - * @param null $priceCod - */ - public function __construct($id, $price, $priceCod = null) - { - if (!in_array($id, self::$ids)) { - throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); - } - $this->id = (string) $id; - $this->price = (float) $price; - $this->priceCod = isset($priceCod) ? (float) $priceCod : null; - } - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * @return float|null - */ - public function getPriceCod() - { - return $this->priceCod; - } +class Delivery +{ + const CESKA_POSTA = 'CESKA_POSTA', + CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', + CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', + DPD = 'DPD', + DHL = 'DHL', + DSV = 'DSV', + EMS = 'EMS', + FOFR = 'FOFR', + GEBRUDER_WEISS = 'GEBRUDER_WEISS', + GEIS = 'GEIS', + GENERAL_PARCEL = 'GENERAL_PARCEL', + GLS = 'GLS', + HDS = 'HDS', + HEUREKAPOINT = 'HEUREKAPOINT', + INTIME = 'INTIME', + PPL = 'PPL', + RADIALKA = 'RADIALKA', + SEEGMULLER = 'SEEGMULLER', + TNT = 'TNT', + TOPTRANS = 'TOPTRANS', + UPS = 'UPS', + VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA'; + + private static array $ids = [ + self::CESKA_POSTA, + self::CESKA_POSTA_NA_POSTU, + self::CSAD_LOGISTIK_OSTRAVA, + self::DPD, + self::DHL, + self::DSV, + self::EMS, + self::FOFR, + self::GEBRUDER_WEISS, + self::GEIS, + self::GENERAL_PARCEL, + self::GLS, + self::HDS, + self::HEUREKAPOINT, + self::INTIME, + self::PPL, + self::RADIALKA, + self::SEEGMULLER, + self::TNT, + self::TOPTRANS, + self::UPS, + self::VLASTNI_PREPRAVA, + ]; + + private string $id; + + private float $price; + + private ?float $priceCod; + + + public function __construct(string $id, float $price, ?float $priceCod = null) + { + if (\in_array($id, self::$ids, true) === false) { + throw new \InvalidArgumentException('Delivery "' . $id . '" does not exist.'); + } + $this->id = $id; + $this->price = $price; + $this->priceCod = $priceCod; + } + + + public function getId(): string + { + return $this->id; + } + + + public function getPrice(): float + { + return $this->price; + } + + + public function getPriceCod(): ?float + { + return $this->priceCod; + } } diff --git a/src/Generators/Heureka/Generator.php b/src/Generators/Heureka/Generator.php index f65b1ad..fd785bb 100644 --- a/src/Generators/Heureka/Generator.php +++ b/src/Generators/Heureka/Generator.php @@ -1,24 +1,19 @@ - * @package Mk\Feed\Generators - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -abstract class Generator extends BaseGenerator { +use Mk\Feed\Generators\BaseGenerator; - /** - * @param $name - * @return string - */ - protected function getTemplate($name) - { - $reflection = new \ReflectionClass(__CLASS__); - return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; - } +/** @see http://sluzby.heureka.cz/napoveda/xml-feed/ */ +abstract class Generator extends BaseGenerator +{ + protected function getTemplate(string $name): string + { + $reflection = new \ReflectionClass(__CLASS__); -} \ No newline at end of file + return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; + } +} diff --git a/src/Generators/Heureka/Gift.php b/src/Generators/Heureka/Gift.php index 670f477..ef22dd7 100644 --- a/src/Generators/Heureka/Gift.php +++ b/src/Generators/Heureka/Gift.php @@ -1,37 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Gift{ +namespace Mk\Feed\Generators\Heureka; - use Nette\SmartObject; - /** @var string */ - protected $name; +class Gift +{ + protected string $name; - /** - * @return string - */ - public function getName() - { - return $this->name; - } - /** - * Gift constructor. - * @param $name - */ - public function __construct($name) - { + public function __construct(string $name) + { + $this->name = $name; + } - $this->name = (string)$name; - } + public function getName(): string + { + return $this->name; + } } diff --git a/src/Generators/Heureka/Image.php b/src/Generators/Heureka/Image.php index 581cbcb..e11369e 100644 --- a/src/Generators/Heureka/Image.php +++ b/src/Generators/Heureka/Image.php @@ -1,40 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ class Image { + private string $url; - use Nette\SmartObject; - - /** @var string */ - private $url; - - /** - * Image constructor. - * @param string $url - */ - public function __construct($url) - { - $this->url = (string) $url; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } + public function __construct(string $url) + { + $this->url = $url; + } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/Generators/Heureka/Item.php b/src/Generators/Heureka/Item.php index ed6e19d..41bf8d1 100644 --- a/src/Generators/Heureka/Item.php +++ b/src/Generators/Heureka/Item.php @@ -2,473 +2,517 @@ namespace Mk\Feed\Generators\Heureka; -use Mk, Nette; + +use Mk; use Mk\Feed\Generators\BaseItem; /** * Class Item + * * @author Martin Knor * @package Mk\Feed\Generators\Heureka * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation */ -class Item extends BaseItem { +class Item extends BaseItem +{ + + /** @var string @required */ + protected $itemId; + + /** @var string @required */ + protected $productName; + + /** @var string|null */ + protected $product; + + /** @var string @required */ + protected $description; + + /** @var string @required */ + protected $url; + + /** @var Image[] */ + protected $images = []; + + /** @var string|null */ + protected $videoUrl; + + /** @var float @required */ + protected $priceVat; + + /** @var string|null */ + protected $itemType; + + /** @var Parameter[] */ + protected $parameters = []; + + /** @var string|null */ + protected $manufacturer; + + /** @var string|null */ + protected $categoryText; + + /** @var string|null */ + protected $ean; + + /** @var string|null */ + protected $isbn; + + /** @var float|null */ + protected $heurekaCpc; + + /** @var \DateTime|int @required */ + protected $deliveryDate; + + /** @var Delivery[] */ + protected $deliveries = []; + + /** @var string|null */ + protected $itemGroupId; + + /** @var array */ + protected $accessories = []; + + /** @var float */ + protected $dues = 0; + + /** @var Gift[] */ + protected $gifts = []; + + + /** + * @return float + */ + public function getDues() + { + return $this->dues; + } + + + /** + * @param float $dues + * @return Item + */ + public function setDues($dues) + { + $this->dues = (float) $dues; + + return $this; + } + + + /** + * @return string + */ + public function getVideoUrl() + { + return $this->videoUrl; + } + + + /** + * @param string $videoUrl + * @return $this + */ + public function setVideoUrl($videoUrl) + { + $this->videoUrl = $videoUrl; + + return $this; + } - /** @var string @required */ - protected $itemId; - /** @var string @required */ - protected $productName; + /** + * @param $url + * @return $this + */ + public function addImage($url) + { + $this->images[] = new Image($url); - /** @var string|null */ - protected $product; + return $this; + } - /** @var string @required */ - protected $description; - /** @var string @required */ - protected $url; + /** + * @param $id + * @param $price + * @param null $priceCod + * @return $this + */ + public function addDelivery($id, $price, $priceCod = null) + { + $this->deliveries[] = new Delivery($id, $price, $priceCod); - /** @var Image[] */ - protected $images = array(); + return $this; + } - /** @var string|null */ - protected $videoUrl; - /** @var float @required */ - protected $priceVat; + /** + * @return Delivery[] + */ + public function getDeliveries() + { + return $this->deliveries; + } - /** @var string|null */ - protected $itemType; - /** @var Parameter[] */ - protected $parameters = array(); - - /** @var string|null */ - protected $manufacturer; + /** + * @param $name + * @param $val + * @param null $unit + * @return Item + */ + public function addParameter($name, $val, $unit = null, $percentage = null) + { + $this->parameters[] = new Parameter($name, $val, $unit, $percentage); - /** @var string|null */ - protected $categoryText; - - /** @var string|null */ - protected $ean; - - /** @var string|null */ - protected $isbn; - - /** @var float|null */ - protected $heurekaCpc; - - /** @var \DateTime|int @required */ - protected $deliveryDate; - - /** @var Delivery[] */ - protected $deliveries = array(); - - /** @var string|null */ - protected $itemGroupId; - - /** @var array */ - protected $accessories = array(); - - /** @var float */ - protected $dues = 0; - - /** @var Gift[] */ - protected $gifts = array(); - - /** - * @return float - */ - public function getDues() - { - return $this->dues; - } - - /** - * @param float $dues - * @return Item - */ - public function setDues($dues) - { - $this->dues = (float)$dues; - - return $this; - } - - /** - * @return string - */ - public function getVideoUrl() - { - return $this->videoUrl; - } - - /** - * @param string $videoUrl - * @return $this - */ - public function setVideoUrl($videoUrl) - { - $this->videoUrl = $videoUrl; - - return $this; - } - - /** - * @param $url - * @return $this - */ - public function addImage($url) - { - $this->images[] = new Image($url); - - return $this; - } - - /** - * @param $id - * @param $price - * @param null $priceCod - * @return $this - */ - public function addDelivery($id, $price, $priceCod = null) - { - $this->deliveries[] = new Delivery($id, $price, $priceCod); - - return $this; - } - - /** - * @return Delivery[] - */ - public function getDeliveries() - { - return $this->deliveries; - } - - /** - * @param $name - * @param $val - * @param null $unit - * @return Item - */ - public function addParameter($name, $val, $unit = null, $percentage = null) - { - $this->parameters[] = new Parameter($name, $val, $unit, $percentage); - - return $this; - } - - /** - * @param $name - * @return $this - */ - public function addGift($name) - { - $this->gifts[] = new Gift($name); - - return $this; - } - - /** - * @param $itemId - * @return $this - */ - public function addAccessory($itemId) - { - $this->accessories[] = $itemId; - - return $this; - } - - /** - * @return array - */ - public function getAccessories() - { - return $this->accessories; - } - - /** - * @return string - */ - public function getProductName() - { - return $this->productName; - } - - /** - * @param string $productName - * @return Item - */ - public function setProductName($productName) - { - $this->productName = (string)$productName; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return Item - */ - public function setDescription($description) - { - $this->description = (string)$description; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - * @return Item - */ - public function setUrl($url) - { - $this->url = (string)$url; - - return $this; - } - - /** - * @return float - */ - public function getPriceVat() - { - return $this->priceVat; - } - - /** - * @param float $priceVat - * @return Item - */ - public function setPriceVat($priceVat) - { - $this->priceVat = (float)$priceVat; - - return $this; - } - - /** - * @return int|string - */ - public function getDeliveryDate() - { - return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; - } - - /** - * @param int|\DateTime $deliveryDate - * @return Item - */ - public function setDeliveryDate($deliveryDate) - { - if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { - throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); - } - $this->deliveryDate = $deliveryDate; - - return $this; - } - - /** - * @return null|string - */ - public function getItemId() - { - return $this->itemId; - } - - /** - * @param null|string $itemId - * @return Item - */ - public function setItemId($itemId) - { - $this->itemId = $itemId; - - return $this; - } - - /** - * @return null|string - */ - public function getEan() - { - return $this->ean; - } - - /** - * @param null|string $ean - * @return Item - */ - public function setEan($ean) - { - $this->ean = $ean; - - return $this; - } - - /** - * @return null|string - */ - public function getIsbn() - { - return $this->isbn; - } - - /** - * @param null|string $isbn - * @return Item - */ - public function setIsbn($isbn) - { - $this->isbn = $isbn; - - return $this; - } - - /** - * @return null|string - */ - public function getItemGroupId() - { - return $this->itemGroupId; - } - - /** - * @param null|string $itemGroupId - * @return Item - */ - public function setItemGroupId($itemGroupId) - { - $this->itemGroupId = $itemGroupId; - - return $this; - } - - /** - * @return null|string - */ - public function getManufacturer() - { - return $this->manufacturer; - } - - /** - * @param null|string $manufacturer - * @return Item - */ - public function setManufacturer($manufacturer) - { - $this->manufacturer = $manufacturer; - - return $this; - } - - /** - * @return null|string - */ - public function getCategoryText() - { - return $this->categoryText; - } - - /** - * @param null|string $categoryText - * @return Item - */ - public function setCategoryText($categoryText) - { - $this->categoryText = $categoryText; - - return $this; - } - - /** - * @return null|string - */ - public function getProduct() - { - return $this->product; - } - - /** - * @param null|string $product - * @return Item - */ - public function setProduct($product) - { - $this->product = $product; - - return $this; - } - - /** - * @return null|string - */ - public function getItemType() - { - return $this->itemType; - } - - /** - * @return Image[] - */ - public function getImages() - { - return $this->images; - } - - /** - * @return Gift[] - */ - public function getGifts() - { - return $this->gifts; - } - - /** - * @return Parameter[] - */ - public function getParameters() - { - return $this->parameters; - } - - /** - * @return null|string - */ - public function getHeurekaCpc() - { - return $this->heurekaCpc; - } - - /** - * @param null|string $heurekaCpc - * @return $this - */ - public function setHeurekaCpc($heurekaCpc) - { - $this->heurekaCpc = $heurekaCpc; - - return $this; - } + return $this; + } + + + /** + * @param $name + * @return $this + */ + public function addGift($name) + { + $this->gifts[] = new Gift($name); + + return $this; + } + + + /** + * @param $itemId + * @return $this + */ + public function addAccessory($itemId) + { + $this->accessories[] = $itemId; + + return $this; + } + + + /** + * @return array + */ + public function getAccessories() + { + return $this->accessories; + } + + + /** + * @return string + */ + public function getProductName() + { + return $this->productName; + } + + + /** + * @param string $productName + * @return Item + */ + public function setProductName($productName) + { + $this->productName = (string) $productName; + + return $this; + } + + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + + /** + * @param string $description + * @return Item + */ + public function setDescription($description) + { + $this->description = (string) $description; + + return $this; + } + + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + + /** + * @param string $url + * @return Item + */ + public function setUrl($url) + { + $this->url = (string) $url; + + return $this; + } + + + /** + * @return float + */ + public function getPriceVat() + { + return $this->priceVat; + } + + + /** + * @param float $priceVat + * @return Item + */ + public function setPriceVat($priceVat) + { + $this->priceVat = (float) $priceVat; + + return $this; + } + + + /** + * @return int|string + */ + public function getDeliveryDate() + { + return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; + } + + + /** + * @param int|\DateTime $deliveryDate + * @return Item + */ + public function setDeliveryDate($deliveryDate) + { + if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { + throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); + } + $this->deliveryDate = $deliveryDate; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemId() + { + return $this->itemId; + } + + + /** + * @param null|string $itemId + * @return Item + */ + public function setItemId($itemId) + { + $this->itemId = $itemId; + + return $this; + } + + + /** + * @return null|string + */ + public function getEan() + { + return $this->ean; + } + + + /** + * @param null|string $ean + * @return Item + */ + public function setEan($ean) + { + $this->ean = $ean; + + return $this; + } + + + /** + * @return null|string + */ + public function getIsbn() + { + return $this->isbn; + } + + + /** + * @param null|string $isbn + * @return Item + */ + public function setIsbn($isbn) + { + $this->isbn = $isbn; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemGroupId() + { + return $this->itemGroupId; + } + + + /** + * @param null|string $itemGroupId + * @return Item + */ + public function setItemGroupId($itemGroupId) + { + $this->itemGroupId = $itemGroupId; + + return $this; + } + + + /** + * @return null|string + */ + public function getManufacturer() + { + return $this->manufacturer; + } + + + /** + * @param null|string $manufacturer + * @return Item + */ + public function setManufacturer($manufacturer) + { + $this->manufacturer = $manufacturer; + + return $this; + } + + + /** + * @return null|string + */ + public function getCategoryText() + { + return $this->categoryText; + } + + + /** + * @param null|string $categoryText + * @return Item + */ + public function setCategoryText($categoryText) + { + $this->categoryText = $categoryText; + + return $this; + } + + + /** + * @return null|string + */ + public function getProduct() + { + return $this->product; + } + + + /** + * @param null|string $product + * @return Item + */ + public function setProduct($product) + { + $this->product = $product; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemType() + { + return $this->itemType; + } + + + /** + * @return Image[] + */ + public function getImages() + { + return $this->images; + } + + + /** + * @return Gift[] + */ + public function getGifts() + { + return $this->gifts; + } + + + /** + * @return Parameter[] + */ + public function getParameters() + { + return $this->parameters; + } + + + /** + * @return null|string + */ + public function getHeurekaCpc() + { + return $this->heurekaCpc; + } + + + /** + * @param null|string $heurekaCpc + * @return $this + */ + public function setHeurekaCpc($heurekaCpc) + { + $this->heurekaCpc = $heurekaCpc; + + return $this; + } } diff --git a/src/Generators/Heureka/Parameter.php b/src/Generators/Heureka/Parameter.php index 7dcb85f..68964be 100644 --- a/src/Generators/Heureka/Parameter.php +++ b/src/Generators/Heureka/Parameter.php @@ -1,46 +1,32 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Parameter{ - - use Nette\SmartObject; - - protected $name; - protected $value; - - /** - * Parameter constructor. - * @param $name - * @param $value - */ - public function __construct($name, $value) - { - $this->name = $name; - $this->value = $value; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; - } - - /** - * @return mixed - */ - public function getValue() - { - return $this->value; - } +class Parameter +{ + protected string $name; + + protected string $value; + + + public function __construct(string $name, string $value) + { + $this->name = $name; + $this->value = $value; + } + + + public function getName(): string + { + return $this->name; + } + + + public function getValue(): string + { + return $this->value; + } } diff --git a/src/Generators/Heureka/latte/item.latte b/src/Generators/Heureka/latte/item.latte index 882327c..ee30f94 100644 --- a/src/Generators/Heureka/latte/item.latte +++ b/src/Generators/Heureka/latte/item.latte @@ -1,52 +1,53 @@ {contentType xml} - {$item->getItemId()} - getProductName()}]]> - getProduct()}]]> - getDescription()|striptags|noescape}]]> - {$item->getUrl()} - - {if !empty($images = $item->getImages())} - {foreach $images as $image} - {var tag = $iterator->first ? 'IMGURL' : 'IMGURL_ALTERNATIVE'} - <{$tag}>{$image->getUrl()} - {/foreach} - {/if} - - {$item->getVideoUrl()} - {$item->getPriceVat()} - - {if !empty($parameters = $item->getParameters())} - - {$parameter->getName()} - {$parameter->getValue()}{$parameter->getUnit()} - {$parameter->getPercentage()}% - - {/if} - - getManufacturer()}]]> - getCategoryText()}]]> - {$item->getEan()} - {$item->getIsbn()} - {$item->getHeurekaCpc()} - {$item->getDeliveryDate()} - - {if !empty($deliveries = $item->getDeliveries())} - - {$delivery->getId()} - {$delivery->getPrice()} - {$delivery->getPriceCod()} - - {/if} - - {$item->getItemGroupId()} - - {if !empty($accessories = $item->getAccessories())} - {$itemId} - {/if} - - {$item->getDues()} - {if !empty($gifts = $item->getGifts())} - {$gift->getName()} - {/if} + {$item->getItemId()} + getProductName()}]]> + getProduct()}]]> + getDescription()|striptags|noescape}]]> + {$item->getUrl()} + + {if !empty($images = $item->getImages())} + {foreach $images as $image} + {var tag = $iterator->first ? 'IMGURL' : 'IMGURL_ALTERNATIVE'} + <{$tag}>{$image->getUrl()} + +{/foreach} +{/if} + +{$item->getVideoUrl()} +{$item->getPriceVat()} + +{if !empty($parameters = $item->getParameters())} + +{$parameter->getName()} +{$parameter->getValue()}{$parameter->getUnit()} +{$parameter->getPercentage()}% + +{/if} + +getManufacturer()}]]> +getCategoryText()}]]> +{$item->getEan()} +{$item->getIsbn()} +{$item->getHeurekaCpc()} +{$item->getDeliveryDate()} + +{if !empty($deliveries = $item->getDeliveries())} + + {$delivery->getId()} + {$delivery->getPrice()} + {$delivery->getPriceCod()} + +{/if} + +{$item->getItemGroupId()} + +{if !empty($accessories = $item->getAccessories())} +{$itemId} +{/if} + +{$item->getDues()} +{if !empty($gifts = $item->getGifts())} +{$gift->getName()} +{/if} diff --git a/src/Generators/HeurekaAvailability/CategoriesHelper.php b/src/Generators/HeurekaAvailability/CategoriesHelper.php index dd57848..55e3a66 100644 --- a/src/Generators/HeurekaAvailability/CategoriesHelper.php +++ b/src/Generators/HeurekaAvailability/CategoriesHelper.php @@ -1,77 +1,69 @@ cache = new Cache($storage, __CLASS__); - } - $this->sk = false; - } - - /** - * @param bool $sk - * @return CategoriesHelper - */ - public function setSk(bool $sk): CategoriesHelper { - $this->sk = $sk; - return $this; - } - - - - - public function getCategories() - { - $categories = array(); - if (!$this->cache || !($categories = $this->cache->load('categories'))) { - if ($this->sk) { - $xml = file_get_contents(self::CATEGORY_SK_URL); - } else { - $xml = file_get_contents(self::CATEGORY_URL); - } - $dom = new \DOMDocument(); - - $dom->loadXML($xml); - $xpath = new \DOMXPath($dom); - /** @var \DOMElement[] $_categories */ - $_categories = $xpath->query(".//CATEGORY"); - - foreach ($_categories as $category) { - $categoryIdElement = $xpath->query($category->getNodePath().'/CATEGORY_ID'); - $id = isset($categoryIdElement[0]) ? (int)$categoryIdElement[0]->nodeValue : null; - - $categoryFullNameElement = $xpath->query($category->getNodePath().'/CATEGORY_FULLNAME'); - $_cat = isset($categoryFullNameElement[0]) ? (string)$categoryFullNameElement[0]->nodeValue : null; - - if($id && $_cat) { - $_cat = str_replace('Heureka.cz | ', '', $_cat); - $categories[$id] = $_cat; - } - } - - asort($categories); - - if ($this->cache) { - $this->cache->save('categories', $categories); - } - } - - return $categories; - } -} \ No newline at end of file +final class CategoriesHelper +{ + public const CATEGORY_URL = 'http://www.heureka.cz/direct/xml-export/shops/heureka-sekce.xml'; + + public const CATEGORY_SK_URL = 'http://www.heureka.sk/direct/xml-export/shops/heureka-sekce.xml'; + + private Cache $cache; + + private bool $sk; + + + public function __construct(IStorage $storage = null) + { + if ($storage) { + $this->cache = new Cache($storage, __CLASS__); + } + $this->sk = false; + } + + + public function setSk(bool $sk): CategoriesHelper + { + $this->sk = $sk; + + return $this; + } + + + public function getCategories(): array + { + $categories = []; + if (!$this->cache || !($categories = $this->cache->load('categories'))) { + $dom = new \DOMDocument(); + $dom->loadXML(file_get_contents($this->sk ? self::CATEGORY_SK_URL : self::CATEGORY_URL)); + $xpath = new \DOMXPath($dom); + /** @var \DOMElement[] $_categories */ + $_categories = $xpath->query(".//CATEGORY"); + + foreach ($_categories as $category) { + $categoryIdElement = $xpath->query($category->getNodePath() . '/CATEGORY_ID'); + $id = isset($categoryIdElement[0]) ? (int) $categoryIdElement[0]->nodeValue : null; + + $categoryFullNameElement = $xpath->query($category->getNodePath() . '/CATEGORY_FULLNAME'); + $_cat = isset($categoryFullNameElement[0]) ? (string) $categoryFullNameElement[0]->nodeValue : null; + + if ($id && $_cat) { + $_cat = str_replace('Heureka.cz | ', '', $_cat); + $categories[$id] = $_cat; + } + } + asort($categories); + if ($this->cache) { + $this->cache->save('categories', $categories); + } + } + + return $categories; + } +} diff --git a/src/Generators/HeurekaAvailability/Delivery.php b/src/Generators/HeurekaAvailability/Delivery.php index 5778981..ee22e7f 100644 --- a/src/Generators/HeurekaAvailability/Delivery.php +++ b/src/Generators/HeurekaAvailability/Delivery.php @@ -1,123 +1,102 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Delivery{ - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - CONST CESKA_POSTA = 'CESKA_POSTA', - CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', - CESKA_POSTA_DOPORUCENA_ZASILKA = 'CESKA_POSTA_DOPORUCENA_ZASILKA', - CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', - DPD = 'DPD', - DHL = 'DHL', - DSV = 'DSV', - EMS = 'EMS', - FOFR = 'FOFR', - GEBRUDER_WEISS = 'GEBRUDER_WEISS', - GEIS = 'GEIS', - GENERAL_PARCEL = 'GENERAL_PARCEL', - GLS = 'GLS', - HDS = 'HDS', - HEUREKAPOINT = 'HEUREKAPOINT', - INTIME = 'INTIME', - PPL = 'PPL', - RADIALKA = 'RADIALKA', - SEEGMULLER = 'SEEGMULLER', - TNT = 'TNT', - TOPTRANS = 'TOPTRANS', - UPS = 'UPS', - ULOZENKA = 'ULOZENKA', - VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', - ZASILKOVNA = 'ZASILKOVNA', - - SLOVENSKA_POSTA = 'SLOVENSKA_POSTA'; - - - static $ids = array( - self::CESKA_POSTA, - self::CESKA_POSTA_NA_POSTU, - self::CESKA_POSTA_DOPORUCENA_ZASILKA, - self::CSAD_LOGISTIK_OSTRAVA, - self::DPD, - self::DHL, - self::DSV, - self::EMS, - self::FOFR, - self::GEBRUDER_WEISS, - self::GEIS, - self::GENERAL_PARCEL, - self::GLS, - self::HDS, - self::HEUREKAPOINT, - self::INTIME, - self::PPL, - self::RADIALKA, - self::SEEGMULLER, - self::TNT, - self::TOPTRANS, - self::UPS, - self::ULOZENKA, - self::VLASTNI_PREPRAVA, - self::ZASILKOVNA, - - self::SLOVENSKA_POSTA, - ); - - /** @var string */ - private $id; - /** @var float */ - private $price; - /** @var float|null */ - private $priceCod; - - /** - * Delivery constructor. - * @param $id - * @param $price - * @param null $priceCod - */ - public function __construct($id, $price, $priceCod = null) - { - if (!in_array($id, self::$ids)) { - throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); - } - $this->id = (string) $id; - $this->price = (float) $price; - $this->priceCod = isset($priceCod) ? (float) $priceCod : null; - } - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * @return float|null - */ - public function getPriceCod() - { - return $this->priceCod; - } +class Delivery +{ + public const CESKA_POSTA = 'CESKA_POSTA', + CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', + CESKA_POSTA_DOPORUCENA_ZASILKA = 'CESKA_POSTA_DOPORUCENA_ZASILKA', + CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', + DPD = 'DPD', + DHL = 'DHL', + DSV = 'DSV', + EMS = 'EMS', + FOFR = 'FOFR', + GEBRUDER_WEISS = 'GEBRUDER_WEISS', + GEIS = 'GEIS', + GENERAL_PARCEL = 'GENERAL_PARCEL', + GLS = 'GLS', + HDS = 'HDS', + HEUREKAPOINT = 'HEUREKAPOINT', + INTIME = 'INTIME', + PPL = 'PPL', + RADIALKA = 'RADIALKA', + SEEGMULLER = 'SEEGMULLER', + TNT = 'TNT', + TOPTRANS = 'TOPTRANS', + UPS = 'UPS', + ULOZENKA = 'ULOZENKA', + VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', + ZASILKOVNA = 'ZASILKOVNA', + + SLOVENSKA_POSTA = 'SLOVENSKA_POSTA'; + + + private static array $ids = [ + self::CESKA_POSTA, + self::CESKA_POSTA_NA_POSTU, + self::CESKA_POSTA_DOPORUCENA_ZASILKA, + self::CSAD_LOGISTIK_OSTRAVA, + self::DPD, + self::DHL, + self::DSV, + self::EMS, + self::FOFR, + self::GEBRUDER_WEISS, + self::GEIS, + self::GENERAL_PARCEL, + self::GLS, + self::HDS, + self::HEUREKAPOINT, + self::INTIME, + self::PPL, + self::RADIALKA, + self::SEEGMULLER, + self::TNT, + self::TOPTRANS, + self::UPS, + self::ULOZENKA, + self::VLASTNI_PREPRAVA, + self::ZASILKOVNA, + self::SLOVENSKA_POSTA, + ]; + + private string $id; + + private float $price; + + private ?float $priceCod; + + + public function __construct(string $id, float $price, ?float $priceCod = null) + { + if (\in_array($id, self::$ids, true) === false) { + throw new \InvalidArgumentException('Delivery "' . $id . '" does not exist.'); + } + $this->id = $id; + $this->price = $price; + $this->priceCod = $priceCod; + } + + + public function getId(): string + { + return $this->id; + } + + + public function getPrice(): float + { + return $this->price; + } + + + public function getPriceCod(): ?float + { + return $this->priceCod; + } } diff --git a/src/Generators/HeurekaAvailability/Depot.php b/src/Generators/HeurekaAvailability/Depot.php index bf15190..95eb38b 100644 --- a/src/Generators/HeurekaAvailability/Depot.php +++ b/src/Generators/HeurekaAvailability/Depot.php @@ -1,100 +1,66 @@ - * @package Mk\Feed\Generators\Heureka - */ class Depot { - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - - - /** @var string */ - private $id; - /** - * @var int - */ - private $stock; - - - - /** @var \DateTime */ - protected $orderDeadline; - - /** @var \DateTime */ - protected $orderDeliveryTime; - - /** - * Depot constructor. - * @param string $id - * @param int $stock - * @param \DateTime $orderDeadline - * @param \DateTime $orderDeliveryTime - */ - public function __construct(string $id, int $stock, \DateTime $orderDeadline, \DateTime $orderDeliveryTime) { - $this->id = $id; - $this->stock = $stock; - $this->orderDeadline = $orderDeadline; - $this->orderDeliveryTime = $orderDeliveryTime; - } - - - /** - * @return string - */ - public function getId(): string { - return $this->id; - } - - /** - * @return int - */ - public function getStock(): int { - return $this->stock; - } - - /** - * @return \DateTime - */ - public function getOrderDeadline(): \DateTime { - return $this->orderDeadline; - } - - /** - * @param \DateTime $orderDeadline - * @return Depot - */ - public function setOrderDeadline(\DateTime $orderDeadline): Depot { - $this->orderDeadline = $orderDeadline; - return $this; - } - - /** - * @return \DateTime - */ - public function getOrderDeliveryTime(): \DateTime { - return $this->orderDeliveryTime; - } - - /** - * @param \DateTime $orderDeliveryTime - * @return Depot - */ - public function setOrderDeliveryTime(\DateTime $orderDeliveryTime): Depot { - $this->orderDeliveryTime = $orderDeliveryTime; - return $this; - } + protected \DateTime $orderDeadline; + + protected \DateTime $orderDeliveryTime; + + private string $id; + + private int $stock; + + + public function __construct(string $id, int $stock, \DateTime $orderDeadline, \DateTime $orderDeliveryTime) + { + $this->id = $id; + $this->stock = $stock; + $this->orderDeadline = $orderDeadline; + $this->orderDeliveryTime = $orderDeliveryTime; + } + + + public function getId(): string + { + return $this->id; + } + + + public function getStock(): int + { + return $this->stock; + } + + + public function getOrderDeadline(): \DateTime + { + return $this->orderDeadline; + } + + + public function setOrderDeadline(\DateTime $orderDeadline): Depot + { + $this->orderDeadline = $orderDeadline; + + return $this; + } + public function getOrderDeliveryTime(): \DateTime + { + return $this->orderDeliveryTime; + } + public function setOrderDeliveryTime(\DateTime $orderDeliveryTime): Depot + { + $this->orderDeliveryTime = $orderDeliveryTime; + return $this; + } } diff --git a/src/Generators/HeurekaAvailability/Generator.php b/src/Generators/HeurekaAvailability/Generator.php index 4f4486b..a176b81 100644 --- a/src/Generators/HeurekaAvailability/Generator.php +++ b/src/Generators/HeurekaAvailability/Generator.php @@ -1,24 +1,19 @@ - * @package Mk\Feed\Generators - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -abstract class Generator extends BaseGenerator { +use Mk\Feed\Generators\BaseGenerator; - /** - * @param $name - * @return string - */ - protected function getTemplate($name) - { - $reflection = new \ReflectionClass(__CLASS__); - return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; - } +/** @see http://sluzby.heureka.cz/napoveda/xml-feed/ */ +abstract class Generator extends BaseGenerator +{ + protected function getTemplate(string $name): string + { + $reflection = new \ReflectionClass(__CLASS__); -} \ No newline at end of file + return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; + } +} diff --git a/src/Generators/HeurekaAvailability/Gift.php b/src/Generators/HeurekaAvailability/Gift.php index f95a3a2..88e82d0 100644 --- a/src/Generators/HeurekaAvailability/Gift.php +++ b/src/Generators/HeurekaAvailability/Gift.php @@ -1,38 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Gift { +namespace Mk\Feed\Generators\HeurekaAvailability; - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - /** @var string */ - protected $name; +class Gift +{ + protected string $name; - /** - * @return string - */ - public function getName() - { - return $this->name; - } - /** - * Gift constructor. - * @param $name - */ - public function __construct($name) - { + public function __construct(string $name) + { + $this->name = $name; + } - $this->name = (string)$name; - } + public function getName(): string + { + return $this->name; + } } diff --git a/src/Generators/HeurekaAvailability/Image.php b/src/Generators/HeurekaAvailability/Image.php index 2be46a2..ea9e536 100644 --- a/src/Generators/HeurekaAvailability/Image.php +++ b/src/Generators/HeurekaAvailability/Image.php @@ -1,40 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ class Image { - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - /** @var string */ - private $url; - - /** - * Image constructor. - * @param string $url - */ - public function __construct($url) - { - $this->url = (string) $url; - } + private string $url; - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } + public function __construct(string $url) + { + $this->url = $url; + } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/Generators/HeurekaAvailability/Item.php b/src/Generators/HeurekaAvailability/Item.php index b5a51a8..1217261 100644 --- a/src/Generators/HeurekaAvailability/Item.php +++ b/src/Generators/HeurekaAvailability/Item.php @@ -1,551 +1,606 @@ - * @package Mk\Feed\Generators\Heureka - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -class Item extends BaseItem { +/** @see http://sluzby.heureka.cz/napoveda/xml-feed/ */ +class Item extends BaseItem +{ + + /** @var string @required */ + protected $itemId; + + /** @var string @required */ + protected $productName; + + /** @var string|null */ + protected $product; + + /** @var string @required */ + protected $description; + + /** @var string @required */ + protected $url; + + /** @var Image[] */ + protected $images = []; + + /** @var Depot[] */ + protected $depots = []; + + /** @var string|null */ + protected $videoUrl; + + /** @var float @required */ + protected $priceVat; + + /** @var string|null */ + protected $itemType; + + /** @var Parameter[] */ + protected $parameters = []; + + /** @var string|null */ + protected $manufacturer; + + /** @var string|null */ + protected $categoryText; + + /** @var string|null */ + protected $ean; + + /** @var string|null */ + protected $isbn; + + /** @var float|null */ + protected $heurekaCpc; + + /** @var \DateTime|int @required */ + protected $deliveryDate; + + /** @var Delivery[] */ + protected $deliveries = []; + + /** @var string|null */ + protected $itemGroupId; + + /** @var array */ + protected $accessories = []; + + /** @var float */ + protected $dues = 0; + + /** @var Gift[] */ + protected $gifts = []; + + /** @var int */ + protected $stock; + + /** @var \DateTime */ + protected $orderDeadline; + + /** @var \DateTime */ + protected $orderDeliveryTime; + + + /** + * @return float + */ + public function getDues() + { + return $this->dues; + } - /** @var string @required */ - protected $itemId; - /** @var string @required */ - protected $productName; + /** + * @param float $dues + * @return Item + */ + public function setDues($dues) + { + $this->dues = (float) $dues; - /** @var string|null */ - protected $product; + return $this; + } - /** @var string @required */ - protected $description; - /** @var string @required */ - protected $url; + /** + * @return string + */ + public function getVideoUrl() + { + return $this->videoUrl; + } - /** @var Image[] */ - protected $images = array(); - /** @var Depot[] */ - protected $depots = []; + /** + * @param string $videoUrl + * @return $this + */ + public function setVideoUrl($videoUrl) + { + $this->videoUrl = $videoUrl; - /** @var string|null */ - protected $videoUrl; + return $this; + } - /** @var float @required */ - protected $priceVat; - /** @var string|null */ - protected $itemType; + /** + * @param $url + * @return $this + */ + public function addImage($url) + { + $this->images[] = new Image($url); - /** @var Parameter[] */ - protected $parameters = array(); + return $this; + } - /** @var string|null */ - protected $manufacturer; - /** @var string|null */ - protected $categoryText; + public function addDepot($id, $stock, $orderDeadline, $orderDeliveryTime) + { + $this->depots[] = new Depot($id, $stock, $orderDeadline, $orderDeliveryTime); - /** @var string|null */ - protected $ean; + return $this; + } - /** @var string|null */ - protected $isbn; - /** @var float|null */ - protected $heurekaCpc; + /** + * @param $id + * @param $price + * @param null $priceCod + * @return $this + */ + public function addDelivery($id, $price, $priceCod = null) + { + $this->deliveries[] = new Delivery($id, $price, $priceCod); - /** @var \DateTime|int @required */ - protected $deliveryDate; + return $this; + } - /** @var Delivery[] */ - protected $deliveries = array(); - /** @var string|null */ - protected $itemGroupId; - - /** @var array */ - protected $accessories = array(); - - /** @var float */ - protected $dues = 0; - - /** @var Gift[] */ - protected $gifts = array(); - - /** @var int */ - protected $stock; - - /** @var \DateTime */ - protected $orderDeadline; - - /** @var \DateTime */ - protected $orderDeliveryTime; - - /** - * @return float - */ - public function getDues() - { - return $this->dues; - } - - /** - * @param float $dues - * @return Item - */ - public function setDues($dues) - { - $this->dues = (float)$dues; - - return $this; - } - - /** - * @return string - */ - public function getVideoUrl() - { - return $this->videoUrl; - } - - /** - * @param string $videoUrl - * @return $this - */ - public function setVideoUrl($videoUrl) - { - $this->videoUrl = $videoUrl; - - return $this; - } - - /** - * @param $url - * @return $this - */ - public function addImage($url) - { - $this->images[] = new Image($url); - - return $this; - } - - public function addDepot($id, $stock, $orderDeadline, $orderDeliveryTime) { - $this->depots[] = new Depot($id, $stock, $orderDeadline, $orderDeliveryTime); - - return $this; - } - - /** - * @param $id - * @param $price - * @param null $priceCod - * @return $this - */ - public function addDelivery($id, $price, $priceCod = null) - { - $this->deliveries[] = new Delivery($id, $price, $priceCod); - - return $this; - } - - /** - * @return Delivery[] - */ - public function getDeliveries() - { - return $this->deliveries; - } - - /** - * @param $name - * @param $val - * @param null $unit - * @return Item - */ - public function addParameter($name, $val, $unit = null, $percentage = null) - { - $this->parameters[] = new Parameter($name, $val, $unit, $percentage); - - return $this; - } - - /** - * @param $name - * @return $this - */ - public function addGift($name) - { - $this->gifts[] = new Gift($name); - - return $this; - } - - /** - * @param $itemId - * @return $this - */ - public function addAccessory($itemId) - { - $this->accessories[] = $itemId; - - return $this; - } - - /** - * @return array - */ - public function getAccessories() - { - return $this->accessories; - } - - /** - * @return string - */ - public function getProductName() - { - return $this->productName; - } - - /** - * @param string $productName - * @return Item - */ - public function setProductName($productName) - { - $this->productName = (string)$productName; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return Item - */ - public function setDescription($description) - { - $this->description = (string)$description; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - * @return Item - */ - public function setUrl($url) - { - $this->url = (string)$url; - - return $this; - } - - /** - * @return float - */ - public function getPriceVat() - { - return $this->priceVat; - } - - /** - * @param float $priceVat - * @return Item - */ - public function setPriceVat($priceVat) - { - $this->priceVat = (float)$priceVat; - - return $this; - } - - /** - * @return int|string - */ - public function getDeliveryDate() - { - return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; - } - - /** - * @param int|\DateTime $deliveryDate - * @return Item - */ - public function setDeliveryDate($deliveryDate) - { - if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { - throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); - } - $this->deliveryDate = $deliveryDate; - - return $this; - } - - /** - * @return null|string - */ - public function getItemId() - { - return $this->itemId; - } - - /** - * @param null|string $itemId - * @return Item - */ - public function setItemId($itemId) - { - $this->itemId = $itemId; - - return $this; - } - - /** - * @return null|string - */ - public function getEan() - { - return $this->ean; - } - - /** - * @param null|string $ean - * @return Item - */ - public function setEan($ean) - { - $this->ean = $ean; - - return $this; - } - - /** - * @return null|string - */ - public function getIsbn() - { - return $this->isbn; - } - - /** - * @param null|string $isbn - * @return Item - */ - public function setIsbn($isbn) - { - $this->isbn = $isbn; - - return $this; - } - - /** - * @return null|string - */ - public function getItemGroupId() - { - return $this->itemGroupId; - } - - /** - * @param null|string $itemGroupId - * @return Item - */ - public function setItemGroupId($itemGroupId) - { - $this->itemGroupId = $itemGroupId; - - return $this; - } - - /** - * @return null|string - */ - public function getManufacturer() - { - return $this->manufacturer; - } - - /** - * @param null|string $manufacturer - * @return Item - */ - public function setManufacturer($manufacturer) - { - $this->manufacturer = $manufacturer; - - return $this; - } - - /** - * @return null|string - */ - public function getCategoryText() - { - return $this->categoryText; - } - - /** - * @param null|string $categoryText - * @return Item - */ - public function setCategoryText($categoryText) - { - $this->categoryText = $categoryText; - - return $this; - } - - /** - * @return null|string - */ - public function getProduct() - { - return $this->product; - } - - /** - * @param null|string $product - * @return Item - */ - public function setProduct($product) - { - $this->product = $product; - - return $this; - } - - /** - * @return null|string - */ - public function getItemType() - { - return $this->itemType; - } - - /** - * @return Image[] - */ - public function getImages() - { - return $this->images; - } - - /** - * @return Gift[] - */ - public function getGifts() - { - return $this->gifts; - } - - /** - * @return Parameter[] - */ - public function getParameters() - { - return $this->parameters; - } - - /** - * @return null|string - */ - public function getHeurekaCpc() - { - return $this->heurekaCpc; - } - - /** - * @param null|string $heurekaCpc - * @return $this - */ - public function setHeurekaCpc($heurekaCpc) - { - $this->heurekaCpc = $heurekaCpc; - - return $this; - } - - /** - * @return int - */ - public function getStock(): int { - return $this->stock; - } - - /** - * @param int $stock - * @return Item - */ - public function setStock(int $stock): Item { - $this->stock = $stock; - return $this; - } - - /** - * @return \DateTime - */ - public function getOrderDeadline(): ?\DateTime { - return $this->orderDeadline; - } - - /** - * @param \DateTime $orderDeadline - * @return Item - */ - public function setOrderDeadline(\DateTime $orderDeadline): Item { - $this->orderDeadline = $orderDeadline; - return $this; - } - - /** - * @return \DateTime - */ - public function getOrderDeliveryTime(): ?\DateTime { - return $this->orderDeliveryTime; - } - - /** - * @param \DateTime $orderDeliveryTime - * @return Item - */ - public function setOrderDeliveryTime(\DateTime $orderDeliveryTime): Item { - $this->orderDeliveryTime = $orderDeliveryTime; - return $this; - } - - /** - * @return Depot[] - */ - public function getDepots(): array { - return $this->depots; - } + /** + * @return Delivery[] + */ + public function getDeliveries() + { + return $this->deliveries; + } + /** + * @param $name + * @param $val + * @param null $unit + * @return Item + */ + public function addParameter($name, $val, $unit = null, $percentage = null) + { + $this->parameters[] = new Parameter($name, $val, $unit, $percentage); + return $this; + } + + + /** + * @param $name + * @return $this + */ + public function addGift($name) + { + $this->gifts[] = new Gift($name); + + return $this; + } + + + /** + * @param $itemId + * @return $this + */ + public function addAccessory($itemId) + { + $this->accessories[] = $itemId; + + return $this; + } + + + /** + * @return array + */ + public function getAccessories() + { + return $this->accessories; + } + + + /** + * @return string + */ + public function getProductName() + { + return $this->productName; + } + + + /** + * @param string $productName + * @return Item + */ + public function setProductName($productName) + { + $this->productName = (string) $productName; + + return $this; + } + + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + + /** + * @param string $description + * @return Item + */ + public function setDescription($description) + { + $this->description = (string) $description; + + return $this; + } + + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + + /** + * @param string $url + * @return Item + */ + public function setUrl($url) + { + $this->url = (string) $url; + + return $this; + } + + + /** + * @return float + */ + public function getPriceVat() + { + return $this->priceVat; + } + + + /** + * @param float $priceVat + * @return Item + */ + public function setPriceVat($priceVat) + { + $this->priceVat = (float) $priceVat; + + return $this; + } + + + /** + * @return int|string + */ + public function getDeliveryDate() + { + return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; + } + + + /** + * @param int|\DateTime $deliveryDate + * @return Item + */ + public function setDeliveryDate($deliveryDate) + { + if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { + throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); + } + $this->deliveryDate = $deliveryDate; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemId() + { + return $this->itemId; + } + + + /** + * @param null|string $itemId + * @return Item + */ + public function setItemId($itemId) + { + $this->itemId = $itemId; + + return $this; + } + + + /** + * @return null|string + */ + public function getEan() + { + return $this->ean; + } + + + /** + * @param null|string $ean + * @return Item + */ + public function setEan($ean) + { + $this->ean = $ean; + + return $this; + } + + + /** + * @return null|string + */ + public function getIsbn() + { + return $this->isbn; + } + + + /** + * @param null|string $isbn + * @return Item + */ + public function setIsbn($isbn) + { + $this->isbn = $isbn; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemGroupId() + { + return $this->itemGroupId; + } + + + /** + * @param null|string $itemGroupId + * @return Item + */ + public function setItemGroupId($itemGroupId) + { + $this->itemGroupId = $itemGroupId; + + return $this; + } + + + /** + * @return null|string + */ + public function getManufacturer() + { + return $this->manufacturer; + } + + + /** + * @param null|string $manufacturer + * @return Item + */ + public function setManufacturer($manufacturer) + { + $this->manufacturer = $manufacturer; + + return $this; + } + + + /** + * @return null|string + */ + public function getCategoryText() + { + return $this->categoryText; + } + + + /** + * @param null|string $categoryText + * @return Item + */ + public function setCategoryText($categoryText) + { + $this->categoryText = $categoryText; + + return $this; + } + + + /** + * @return null|string + */ + public function getProduct() + { + return $this->product; + } + + + /** + * @param null|string $product + * @return Item + */ + public function setProduct($product) + { + $this->product = $product; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemType() + { + return $this->itemType; + } + + + /** + * @return Image[] + */ + public function getImages() + { + return $this->images; + } + + + /** + * @return Gift[] + */ + public function getGifts() + { + return $this->gifts; + } + + + /** + * @return Parameter[] + */ + public function getParameters() + { + return $this->parameters; + } + + + /** + * @return null|string + */ + public function getHeurekaCpc() + { + return $this->heurekaCpc; + } + + + /** + * @param null|string $heurekaCpc + * @return $this + */ + public function setHeurekaCpc($heurekaCpc) + { + $this->heurekaCpc = $heurekaCpc; + + return $this; + } + + + /** + * @return int + */ + public function getStock(): int + { + return $this->stock; + } + + + /** + * @param int $stock + * @return Item + */ + public function setStock(int $stock): Item + { + $this->stock = $stock; + + return $this; + } + + + /** + * @return \DateTime + */ + public function getOrderDeadline(): ?\DateTime + { + return $this->orderDeadline; + } + + + /** + * @param \DateTime $orderDeadline + * @return Item + */ + public function setOrderDeadline(\DateTime $orderDeadline): Item + { + $this->orderDeadline = $orderDeadline; + + return $this; + } + + + /** + * @return \DateTime + */ + public function getOrderDeliveryTime(): ?\DateTime + { + return $this->orderDeliveryTime; + } + + + /** + * @param \DateTime $orderDeliveryTime + * @return Item + */ + public function setOrderDeliveryTime(\DateTime $orderDeliveryTime): Item + { + $this->orderDeliveryTime = $orderDeliveryTime; + + return $this; + } + + + /** + * @return Depot[] + */ + public function getDepots(): array + { + return $this->depots; + } } diff --git a/src/Generators/HeurekaAvailability/Parameter.php b/src/Generators/HeurekaAvailability/Parameter.php index fe14bcd..082d761 100644 --- a/src/Generators/HeurekaAvailability/Parameter.php +++ b/src/Generators/HeurekaAvailability/Parameter.php @@ -1,70 +1,50 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Parameter { - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - protected $name; - protected $value; - protected $unit; - protected $percentage; - - /** - * Parameter constructor. - * @param $name - * @param $value - * @param $unit - */ - public function __construct($name, $value, $unit = null, $percentage = null) - { - $this->name = $name; - $this->value = $value; - - $this->unit = $unit; - $this->percentage = $percentage; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; - } - - /** - * @return mixed - */ - public function getValue() - { - return $this->value; - } - - /** - * @return mixed - */ - public function getUnit() { - return $this->unit; - } - - /** - * @return null - */ - public function getPercentage() { - return $this->percentage; - } + +class Parameter +{ + protected string $name; + + protected float $value; + + protected ?string $unit; + + protected ?float $percentage; + + + public function __construct(string $name, float $value, ?string $unit = null, ?float $percentage = null) + { + $this->name = $name; + $this->value = $value; + $this->unit = $unit; + $this->percentage = $percentage; + } + + + public function getName(): string + { + return $this->name; + } + + + public function getValue(): float + { + return $this->value; + } + public function getUnit(): ?string + { + return $this->unit; + } + public function getPercentage(): ?float + { + return $this->percentage; + } } diff --git a/src/Generators/HeurekaAvailability/latte/item.latte b/src/Generators/HeurekaAvailability/latte/item.latte index 8f3b4b6..cc88bbb 100644 --- a/src/Generators/HeurekaAvailability/latte/item.latte +++ b/src/Generators/HeurekaAvailability/latte/item.latte @@ -1,11 +1,15 @@ {contentType xml} - {$item->getStock()} - {$item->getOrderDeliveryTime()|date:'Y-m-d H:i'} - - {$depot->getStock()} - {$depot->getOrderDeliveryTime()|date:'Y-m-d H:i'} - + {$item->getStock()} + {$item->getOrderDeliveryTime()|date:'Y-m-d + H:i'} + + + {$depot->getStock()} + + {$depot->getOrderDeliveryTime()|date:'Y-m-d H:i'} + + diff --git a/src/Generators/IGenerator.php b/src/Generators/IGenerator.php index 7092a3e..2f29da2 100644 --- a/src/Generators/IGenerator.php +++ b/src/Generators/IGenerator.php @@ -1,22 +1,20 @@ cache = new Cache($storage, __CLASS__); - } - $this->sk = false; - } - - /** - * @param bool $sk - * @return CategoriesHelper - */ - public function setSk(bool $sk): CategoriesHelper { - $this->sk = $sk; - return $this; - } - - - - - public function getCategories() - { - $categories = array(); - if (!$this->cache || !($categories = $this->cache->load('categories'))) { - if ($this->sk) { - $xml = file_get_contents(self::CATEGORY_SK_URL); - } else { - $xml = file_get_contents(self::CATEGORY_URL); - } - $dom = new \DOMDocument(); - - $dom->loadXML($xml); - $xpath = new \DOMXPath($dom); - /** @var \DOMElement[] $_categories */ - $_categories = $xpath->query(".//CATEGORY"); - - foreach ($_categories as $category) { - $categoryIdElement = $xpath->query($category->getNodePath().'/CATEGORY_ID'); - $id = isset($categoryIdElement[0]) ? (int)$categoryIdElement[0]->nodeValue : null; - - $categoryFullNameElement = $xpath->query($category->getNodePath().'/CATEGORY_FULLNAME'); - $_cat = isset($categoryFullNameElement[0]) ? (string)$categoryFullNameElement[0]->nodeValue : null; - - if($id && $_cat) { - $_cat = str_replace('Heureka.cz | ', '', $_cat); - $categories[$id] = $_cat; - } - } - - asort($categories); - - if ($this->cache) { - $this->cache->save('categories', $categories); - } - } - - return $categories; - } -} \ No newline at end of file +final class CategoriesHelper +{ + public const CATEGORY_URL = 'http://www.heureka.cz/direct/xml-export/shops/heureka-sekce.xml'; + + public const CATEGORY_SK_URL = 'http://www.heureka.sk/direct/xml-export/shops/heureka-sekce.xml'; + + private Cache $cache; + + private bool $sk; + + + public function __construct(IStorage $storage = null) + { + if ($storage) { + $this->cache = new Cache($storage, __CLASS__); + } + $this->sk = false; + } + + + public function setSk(bool $sk): CategoriesHelper + { + $this->sk = $sk; + + return $this; + } + + + public function getCategories(): array + { + $categories = []; + if (!$this->cache || !($categories = $this->cache->load('categories'))) { + $dom = new \DOMDocument(); + $dom->loadXML(file_get_contents($this->sk ? self::CATEGORY_SK_URL : self::CATEGORY_URL)); + $xpath = new \DOMXPath($dom); + /** @var \DOMElement[] $_categories */ + $_categories = $xpath->query(".//CATEGORY"); + + foreach ($_categories as $category) { + $categoryIdElement = $xpath->query($category->getNodePath() . '/CATEGORY_ID'); + $id = isset($categoryIdElement[0]) ? (int) $categoryIdElement[0]->nodeValue : null; + + $categoryFullNameElement = $xpath->query($category->getNodePath() . '/CATEGORY_FULLNAME'); + $_cat = isset($categoryFullNameElement[0]) ? (string) $categoryFullNameElement[0]->nodeValue : null; + + if ($id && $_cat) { + $_cat = str_replace('Heureka.cz | ', '', $_cat); + $categories[$id] = $_cat; + } + } + asort($categories); + if ($this->cache) { + $this->cache->save('categories', $categories); + } + } + + return $categories; + } +} diff --git a/src/Generators/Shoptet/Delivery.php b/src/Generators/Shoptet/Delivery.php index dc1e865..b1315a1 100644 --- a/src/Generators/Shoptet/Delivery.php +++ b/src/Generators/Shoptet/Delivery.php @@ -1,123 +1,101 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Delivery{ - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - CONST CESKA_POSTA = 'CESKA_POSTA', - CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', - CESKA_POSTA_DOPORUCENA_ZASILKA = 'CESKA_POSTA_DOPORUCENA_ZASILKA', - CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', - DPD = 'DPD', - DHL = 'DHL', - DSV = 'DSV', - EMS = 'EMS', - FOFR = 'FOFR', - GEBRUDER_WEISS = 'GEBRUDER_WEISS', - GEIS = 'GEIS', - GENERAL_PARCEL = 'GENERAL_PARCEL', - GLS = 'GLS', - HDS = 'HDS', - HEUREKAPOINT = 'HEUREKAPOINT', - INTIME = 'INTIME', - PPL = 'PPL', - RADIALKA = 'RADIALKA', - SEEGMULLER = 'SEEGMULLER', - TNT = 'TNT', - TOPTRANS = 'TOPTRANS', - UPS = 'UPS', - ULOZENKA = 'ULOZENKA', - VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', - ZASILKOVNA = 'ZASILKOVNA', - - SLOVENSKA_POSTA = 'SLOVENSKA_POSTA'; - - - static $ids = array( - self::CESKA_POSTA, - self::CESKA_POSTA_NA_POSTU, - self::CESKA_POSTA_DOPORUCENA_ZASILKA, - self::CSAD_LOGISTIK_OSTRAVA, - self::DPD, - self::DHL, - self::DSV, - self::EMS, - self::FOFR, - self::GEBRUDER_WEISS, - self::GEIS, - self::GENERAL_PARCEL, - self::GLS, - self::HDS, - self::HEUREKAPOINT, - self::INTIME, - self::PPL, - self::RADIALKA, - self::SEEGMULLER, - self::TNT, - self::TOPTRANS, - self::UPS, - self::ULOZENKA, - self::VLASTNI_PREPRAVA, - self::ZASILKOVNA, - - self::SLOVENSKA_POSTA, - ); - - /** @var string */ - private $id; - /** @var float */ - private $price; - /** @var float|null */ - private $priceCod; - - /** - * Delivery constructor. - * @param $id - * @param $price - * @param null $priceCod - */ - public function __construct($id, $price, $priceCod = null) - { - if (!in_array($id, self::$ids)) { - throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); - } - $this->id = (string) $id; - $this->price = (float) $price; - $this->priceCod = $priceCod !== null ? (float) $priceCod : null; - } - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * @return float|null - */ - public function getPriceCod() - { - return $this->priceCod; - } +class Delivery +{ + public const CESKA_POSTA = 'CESKA_POSTA', + CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', + CESKA_POSTA_DOPORUCENA_ZASILKA = 'CESKA_POSTA_DOPORUCENA_ZASILKA', + CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', + DPD = 'DPD', + DHL = 'DHL', + DSV = 'DSV', + EMS = 'EMS', + FOFR = 'FOFR', + GEBRUDER_WEISS = 'GEBRUDER_WEISS', + GEIS = 'GEIS', + GENERAL_PARCEL = 'GENERAL_PARCEL', + GLS = 'GLS', + HDS = 'HDS', + HEUREKAPOINT = 'HEUREKAPOINT', + INTIME = 'INTIME', + PPL = 'PPL', + RADIALKA = 'RADIALKA', + SEEGMULLER = 'SEEGMULLER', + TNT = 'TNT', + TOPTRANS = 'TOPTRANS', + UPS = 'UPS', + ULOZENKA = 'ULOZENKA', + VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', + ZASILKOVNA = 'ZASILKOVNA', + SLOVENSKA_POSTA = 'SLOVENSKA_POSTA'; + + + private static array $ids = [ + self::CESKA_POSTA, + self::CESKA_POSTA_NA_POSTU, + self::CESKA_POSTA_DOPORUCENA_ZASILKA, + self::CSAD_LOGISTIK_OSTRAVA, + self::DPD, + self::DHL, + self::DSV, + self::EMS, + self::FOFR, + self::GEBRUDER_WEISS, + self::GEIS, + self::GENERAL_PARCEL, + self::GLS, + self::HDS, + self::HEUREKAPOINT, + self::INTIME, + self::PPL, + self::RADIALKA, + self::SEEGMULLER, + self::TNT, + self::TOPTRANS, + self::UPS, + self::ULOZENKA, + self::VLASTNI_PREPRAVA, + self::ZASILKOVNA, + self::SLOVENSKA_POSTA, + ]; + + private string $id; + + private float $price; + + private ?float $priceCod; + + + public function __construct(string $id, float $price, ?float $priceCod = null) + { + if (in_array($id, self::$ids, true) === false) { + throw new \InvalidArgumentException('Delivery "' . $id . '" does not exist.'); + } + $this->id = $id; + $this->price = $price; + $this->priceCod = $priceCod; + } + + + public function getId(): string + { + return $this->id; + } + + + public function getPrice(): float + { + return $this->price; + } + + + public function getPriceCod(): ?float + { + return $this->priceCod; + } } diff --git a/src/Generators/Shoptet/Generator.php b/src/Generators/Shoptet/Generator.php index f9b533a..e4ac281 100644 --- a/src/Generators/Shoptet/Generator.php +++ b/src/Generators/Shoptet/Generator.php @@ -1,24 +1,19 @@ - * @package Mk\Feed\Generators - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -abstract class Generator extends BaseGenerator { +use Mk\Feed\Generators\BaseGenerator; - /** - * @param $name - * @return string - */ - protected function getTemplate($name) - { - $reflection = new \ReflectionClass(__CLASS__); - return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; - } +/** @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation */ +abstract class Generator extends BaseGenerator +{ + protected function getTemplate(string $name): string + { + $reflection = new \ReflectionClass(__CLASS__); -} \ No newline at end of file + return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; + } +} diff --git a/src/Generators/Shoptet/Gift.php b/src/Generators/Shoptet/Gift.php index 1202edb..e83ade7 100644 --- a/src/Generators/Shoptet/Gift.php +++ b/src/Generators/Shoptet/Gift.php @@ -1,38 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Gift { +namespace Mk\Feed\Generators\Shoptet; - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - /** @var string */ - protected $name; +class Gift +{ + protected string $name; - /** - * @return string - */ - public function getName() - { - return $this->name; - } - /** - * Gift constructor. - * @param $name - */ - public function __construct($name) - { + public function __construct(string $name) + { + $this->name = $name; + } - $this->name = (string)$name; - } + public function getName(): string + { + return $this->name; + } } diff --git a/src/Generators/Shoptet/Image.php b/src/Generators/Shoptet/Image.php index 8f84dd6..0587406 100644 --- a/src/Generators/Shoptet/Image.php +++ b/src/Generators/Shoptet/Image.php @@ -1,40 +1,23 @@ - * @package Mk\Feed\Generators\Heureka - */ class Image { - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - /** @var string */ - private $url; - - /** - * Image constructor. - * @param string $url - */ - public function __construct($url) - { - $this->url = (string) $url; - } + private string $url; - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } + public function __construct(string $url) + { + $this->url = $url; + } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/Generators/Shoptet/Item.php b/src/Generators/Shoptet/Item.php index b6d788f..f348886 100644 --- a/src/Generators/Shoptet/Item.php +++ b/src/Generators/Shoptet/Item.php @@ -1,675 +1,763 @@ - * @package Mk\Feed\Generators\Heureka - * @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation - */ -class Item extends BaseItem { +/** @see http://sluzby.heureka.cz/napoveda/xml-feed/ */ +class Item extends BaseItem +{ + + /** @var string @required */ + protected $itemId; + + /** @var string @required */ + protected $productName; + + /** @var string @required */ + protected $name; + + /** @var string @required */ + protected $nameExt; + + /** @var string @required */ + protected $code; + + /** @var string|null */ + protected $product; + + /** @var string @required */ + protected $description; + + /** @var string @required */ + protected $shortDescription; + + /** @var string @required */ + protected $warranty; + + /** @var string @required */ + protected $url; + + /** @var Image[] */ + protected $images = []; + + /** @var string[] */ + protected $categories = []; + + /** @var string|null */ + protected $videoUrl; + + /** @var float @required */ + protected $priceVat; + + /** @var string|null */ + protected $itemType; + + /** @var Parameter[] */ + protected $parameters = []; + + /** @var string|null */ + protected $manufacturer; + + /** @var string|null */ + protected $categoryText; + + /** @var string|null */ + protected $ean; + + /** @var string|null */ + protected $isbn; - /** @var string @required */ - protected $itemId; + /** @var float|null */ + protected $heurekaCpc; - /** @var string @required */ - protected $productName; + /** @var \DateTime|int @required */ + protected $deliveryDate; - /** @var string @required */ - protected $name; + /** @var Delivery[] */ + protected $deliveries = []; - /** @var string @required */ - protected $nameExt; + /** @var string|null */ + protected $itemGroupId; - /** @var string @required */ - protected $code; + /** @var array */ + protected $accessories = []; - /** @var string|null */ - protected $product; + /** @var float */ + protected $dues = 0; - /** @var string @required */ - protected $description; + /** @var Gift[] */ + protected $gifts = []; - /** @var string @required */ - protected $shortDescription; + /** @var string */ + protected $availability; - /** @var string @required */ - protected $warranty; + /** @var string */ + protected $vat; - /** @var string @required */ - protected $url; + /** @var float */ + protected $weight; - /** @var Image[] */ - protected $images = array(); + /** @var Variant[] */ + protected $variants = []; - /** @var string[] */ - protected $categories = array(); - /** @var string|null */ - protected $videoUrl; + /** + * @return float + */ + public function getDues() + { + return $this->dues; + } - /** @var float @required */ - protected $priceVat; - /** @var string|null */ - protected $itemType; + /** + * @param float $dues + * @return Item + */ + public function setDues($dues) + { + $this->dues = (float) $dues; - /** @var Parameter[] */ - protected $parameters = array(); + return $this; + } - /** @var string|null */ - protected $manufacturer; - /** @var string|null */ - protected $categoryText; + /** + * @return string + */ + public function getVideoUrl() + { + return $this->videoUrl; + } - /** @var string|null */ - protected $ean; - /** @var string|null */ - protected $isbn; + /** + * @param string $videoUrl + * @return $this + */ + public function setVideoUrl($videoUrl) + { + $this->videoUrl = $videoUrl; - /** @var float|null */ - protected $heurekaCpc; + return $this; + } - /** @var \DateTime|int @required */ - protected $deliveryDate; - /** @var Delivery[] */ - protected $deliveries = array(); + /** + * @param $url + * @return $this + */ + public function addImage($url) + { + $this->images[] = new Image($url); - /** @var string|null */ - protected $itemGroupId; + return $this; + } - /** @var array */ - protected $accessories = array(); - /** @var float */ - protected $dues = 0; + /** + * @param $id + * @param $price + * @param null $priceCod + * @return $this + */ + public function addDelivery($id, $price, $priceCod = null) + { + $this->deliveries[] = new Delivery($id, $price, $priceCod); - /** @var Gift[] */ - protected $gifts = array(); + return $this; + } - /** @var string */ - protected $availability; - - /** @var string */ - protected $vat; - - /** @var float */ - protected $weight; - /** @var Variant[] */ - protected $variants = []; - - - /** - * @return float - */ - public function getDues() - { - return $this->dues; - } - - /** - * @param float $dues - * @return Item - */ - public function setDues($dues) - { - $this->dues = (float)$dues; - - return $this; - } - - /** - * @return string - */ - public function getVideoUrl() - { - return $this->videoUrl; - } - - /** - * @param string $videoUrl - * @return $this - */ - public function setVideoUrl($videoUrl) - { - $this->videoUrl = $videoUrl; - - return $this; - } - - /** - * @param $url - * @return $this - */ - public function addImage($url) - { - $this->images[] = new Image($url); - - return $this; - } - - /** - * @param $id - * @param $price - * @param null $priceCod - * @return $this - */ - public function addDelivery($id, $price, $priceCod = null) - { - $this->deliveries[] = new Delivery($id, $price, $priceCod); - - return $this; - } - - /** - * @return Delivery[] - */ - public function getDeliveries() - { - return $this->deliveries; - } - - /** - * @param $name - * @param $val - * @param null $unit - * @return Item - */ - public function addParameter($name, $val, $unit = null, $percentage = null) - { - $this->parameters[] = new Parameter($name, $val, $unit, $percentage); - - return $this; - } - - /** - * @param $name - * @return $this - */ - public function addGift($name) - { - $this->gifts[] = new Gift($name); - - return $this; - } - - /** - * @param $itemId - * @return $this - */ - public function addAccessory($itemId) - { - $this->accessories[] = $itemId; - - return $this; - } - - /** - * @return array - */ - public function getAccessories() - { - return $this->accessories; - } - - /** - * @return string - */ - public function getProductName() - { - return $this->productName; - } - - /** - * @param string $productName - * @return Item - */ - public function setProductName($productName) - { - $this->productName = (string)$productName; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return Item - */ - public function setDescription($description) - { - $this->description = (string)$description; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - * @return Item - */ - public function setUrl($url) - { - $this->url = (string)$url; - - return $this; - } - - /** - * @return float - */ - public function getPriceVat() - { - return $this->priceVat; - } - - /** - * @param float $priceVat - * @return Item - */ - public function setPriceVat($priceVat) - { - $this->priceVat = (float)$priceVat; - - return $this; - } - - /** - * @return int|string - */ - public function getDeliveryDate() - { - return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; - } - - /** - * @param int|\DateTime $deliveryDate - * @return Item - */ - public function setDeliveryDate($deliveryDate) - { - if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { - throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); - } - $this->deliveryDate = $deliveryDate; - - return $this; - } - - /** - * @return null|string - */ - public function getItemId() - { - return $this->itemId; - } - - /** - * @param null|string $itemId - * @return Item - */ - public function setItemId($itemId) - { - $this->itemId = $itemId; - - return $this; - } - - /** - * @return null|string - */ - public function getEan() - { - return $this->ean; - } - - /** - * @param null|string $ean - * @return Item - */ - public function setEan($ean) - { - $this->ean = $ean; - - return $this; - } - - /** - * @return null|string - */ - public function getIsbn() - { - return $this->isbn; - } - - /** - * @param null|string $isbn - * @return Item - */ - public function setIsbn($isbn) - { - $this->isbn = $isbn; - - return $this; - } - - /** - * @return null|string - */ - public function getItemGroupId() - { - return $this->itemGroupId; - } - - /** - * @param null|string $itemGroupId - * @return Item - */ - public function setItemGroupId($itemGroupId) - { - $this->itemGroupId = $itemGroupId; - - return $this; - } - - /** - * @return null|string - */ - public function getManufacturer() - { - return $this->manufacturer; - } - - /** - * @param null|string $manufacturer - * @return Item - */ - public function setManufacturer($manufacturer) - { - $this->manufacturer = $manufacturer; - - return $this; - } - - /** - * @return null|string - */ - public function getCategoryText() - { - return $this->categoryText; - } - - /** - * @param null|string $categoryText - * @return Item - */ - public function setCategoryText($categoryText) - { - $this->categoryText = $categoryText; - - return $this; - } - - /** - * @return null|string - */ - public function getProduct() - { - return $this->product; - } - - /** - * @param null|string $product - * @return Item - */ - public function setProduct($product) - { - $this->product = $product; - - return $this; - } - - /** - * @return null|string - */ - public function getItemType() - { - return $this->itemType; - } - - /** - * @return Image[] - */ - public function getImages() - { - return $this->images; - } - - /** - * @return Gift[] - */ - public function getGifts() - { - return $this->gifts; - } - - /** - * @return Parameter[] - */ - public function getParameters() - { - return $this->parameters; - } - - /** - * @return null|string - */ - public function getHeurekaCpc() - { - return $this->heurekaCpc; - } - - /** - * @param null|string $heurekaCpc - * @return $this - */ - public function setHeurekaCpc($heurekaCpc) - { - $this->heurekaCpc = $heurekaCpc; - - return $this; - } - - /** - * @return string - */ - public function getShortDescription(): ?string { - return $this->shortDescription; - } - - /** - * @param string $shortDescription - * @return Item - */ - public function setShortDescription(?string $shortDescription): Item { - $this->shortDescription = $shortDescription; - return $this; - } - - /** - * @return string - */ - public function getWarranty(): ?string { - return $this->warranty; - } - - /** - * @param string $warranty - * @return Item - */ - public function setWarranty(?string $warranty): Item { - $this->warranty = $warranty; - return $this; - } - - /** - * @return string - */ - public function getCode(): ?string { - return $this->code; - } - - /** - * @param string $code - * @return Item - */ - public function setCode(?string $code): Item { - $this->code = $code; - return $this; - } - - public function addCategory(string $category) { - $this->categories[] = $category; - } - - /** - * @return string[] - */ - public function getCategories(): array { - return $this->categories; - } - - /** - * @return string - */ - public function getAvailability(): ?string { - return $this->availability; - } - - /** - * @param string $availability - * @return Item - */ - public function setAvailability(?string $availability): Item { - $this->availability = $availability; - return $this; - } - - /** - * @return string - */ - public function getVat(): ?string { - return $this->vat; - } - - /** - * @param string $vat - * @return Item - */ - public function setVat(?string $vat): Item { - $this->vat = $vat; - return $this; - } - - /** - * @return string - */ - public function getWeight(): ?string { - return $this->weight; - } - - /** - * @param float $weight - * @return Item - */ - public function setWeight(?float $weight): Item { - $this->weight = $weight; - return $this; - } - - /** - * @return string - */ - public function getSku(): ?string { - return $this->sku; - } - - /** - * @param string $sku - * @return Item - */ - public function setSku(?string $sku): Item { - $this->sku = $sku; - return $this; - } - - /** - * @return string - */ - public function getName(): ?string { - return $this->name; - } - - /** - * @param string $name - * @return Item - */ - public function setName(?string $name): Item { - $this->name = $name; - return $this; - } - - /** - * @return string - */ - public function getNameExt(): ?string { - return $this->nameExt; - } - - /** - * @param string $nameExt - * @return Item - */ - public function setNameExt(?string $nameExt): Item { - $this->nameExt = $nameExt; - return $this; - } - - /** - * @return Variant[] - */ - public function getVariants(): array { - return $this->variants; - } - - public function addVariant(Variant $variant) { - $this->variants[] = $variant; - } + /** + * @return Delivery[] + */ + public function getDeliveries() + { + return $this->deliveries; + } + /** + * @param $name + * @param $val + * @param null $unit + * @return Item + */ + public function addParameter($name, $val, $unit = null, $percentage = null) + { + $this->parameters[] = new Parameter($name, $val, $unit, $percentage); + return $this; + } + + + /** + * @param $name + * @return $this + */ + public function addGift($name) + { + $this->gifts[] = new Gift($name); + + return $this; + } + + + /** + * @param $itemId + * @return $this + */ + public function addAccessory($itemId) + { + $this->accessories[] = $itemId; + + return $this; + } + + + /** + * @return array + */ + public function getAccessories() + { + return $this->accessories; + } + + + /** + * @return string + */ + public function getProductName() + { + return $this->productName; + } + + + /** + * @param string $productName + * @return Item + */ + public function setProductName($productName) + { + $this->productName = (string) $productName; + + return $this; + } + + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + + /** + * @param string $description + * @return Item + */ + public function setDescription($description) + { + $this->description = (string) $description; + + return $this; + } + + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + + /** + * @param string $url + * @return Item + */ + public function setUrl($url) + { + $this->url = (string) $url; + + return $this; + } + + + /** + * @return float + */ + public function getPriceVat() + { + return $this->priceVat; + } + + + /** + * @param float $priceVat + * @return Item + */ + public function setPriceVat($priceVat) + { + $this->priceVat = (float) $priceVat; + + return $this; + } + + + /** + * @return int|string + */ + public function getDeliveryDate() + { + return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; + } + + + /** + * @param int|\DateTime $deliveryDate + * @return Item + */ + public function setDeliveryDate($deliveryDate) + { + if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { + throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); + } + $this->deliveryDate = $deliveryDate; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemId() + { + return $this->itemId; + } + + + /** + * @param null|string $itemId + * @return Item + */ + public function setItemId($itemId) + { + $this->itemId = $itemId; + + return $this; + } + + + /** + * @return null|string + */ + public function getEan() + { + return $this->ean; + } + + + /** + * @param null|string $ean + * @return Item + */ + public function setEan($ean) + { + $this->ean = $ean; + + return $this; + } + + + /** + * @return null|string + */ + public function getIsbn() + { + return $this->isbn; + } + + + /** + * @param null|string $isbn + * @return Item + */ + public function setIsbn($isbn) + { + $this->isbn = $isbn; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemGroupId() + { + return $this->itemGroupId; + } + + + /** + * @param null|string $itemGroupId + * @return Item + */ + public function setItemGroupId($itemGroupId) + { + $this->itemGroupId = $itemGroupId; + + return $this; + } + + + /** + * @return null|string + */ + public function getManufacturer() + { + return $this->manufacturer; + } + + + /** + * @param null|string $manufacturer + * @return Item + */ + public function setManufacturer($manufacturer) + { + $this->manufacturer = $manufacturer; + + return $this; + } + + + /** + * @return null|string + */ + public function getCategoryText() + { + return $this->categoryText; + } + + + /** + * @param null|string $categoryText + * @return Item + */ + public function setCategoryText($categoryText) + { + $this->categoryText = $categoryText; + + return $this; + } + + + /** + * @return null|string + */ + public function getProduct() + { + return $this->product; + } + + + /** + * @param null|string $product + * @return Item + */ + public function setProduct($product) + { + $this->product = $product; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemType() + { + return $this->itemType; + } + + + /** + * @return Image[] + */ + public function getImages() + { + return $this->images; + } + + + /** + * @return Gift[] + */ + public function getGifts() + { + return $this->gifts; + } + + + /** + * @return Parameter[] + */ + public function getParameters() + { + return $this->parameters; + } + + + /** + * @return null|string + */ + public function getHeurekaCpc() + { + return $this->heurekaCpc; + } + + + /** + * @param null|string $heurekaCpc + * @return $this + */ + public function setHeurekaCpc($heurekaCpc) + { + $this->heurekaCpc = $heurekaCpc; + + return $this; + } + + + /** + * @return string + */ + public function getShortDescription(): ?string + { + return $this->shortDescription; + } + + + /** + * @param string $shortDescription + * @return Item + */ + public function setShortDescription(?string $shortDescription): Item + { + $this->shortDescription = $shortDescription; + + return $this; + } + + + /** + * @return string + */ + public function getWarranty(): ?string + { + return $this->warranty; + } + + + /** + * @param string $warranty + * @return Item + */ + public function setWarranty(?string $warranty): Item + { + $this->warranty = $warranty; + + return $this; + } + + + /** + * @return string + */ + public function getCode(): ?string + { + return $this->code; + } + + + /** + * @param string $code + * @return Item + */ + public function setCode(?string $code): Item + { + $this->code = $code; + + return $this; + } + + + public function addCategory(string $category) + { + $this->categories[] = $category; + } + + + /** + * @return string[] + */ + public function getCategories(): array + { + return $this->categories; + } + + + /** + * @return string + */ + public function getAvailability(): ?string + { + return $this->availability; + } + + + /** + * @param string $availability + * @return Item + */ + public function setAvailability(?string $availability): Item + { + $this->availability = $availability; + + return $this; + } + + + /** + * @return string + */ + public function getVat(): ?string + { + return $this->vat; + } + + + /** + * @param string $vat + * @return Item + */ + public function setVat(?string $vat): Item + { + $this->vat = $vat; + + return $this; + } + + + /** + * @return string + */ + public function getWeight(): ?string + { + return $this->weight; + } + + + /** + * @param float $weight + * @return Item + */ + public function setWeight(?float $weight): Item + { + $this->weight = $weight; + + return $this; + } + + + /** + * @return string + */ + public function getSku(): ?string + { + return $this->sku; + } + + + /** + * @param string $sku + * @return Item + */ + public function setSku(?string $sku): Item + { + $this->sku = $sku; + + return $this; + } + + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + + /** + * @param string $name + * @return Item + */ + public function setName(?string $name): Item + { + $this->name = $name; + + return $this; + } + + + /** + * @return string + */ + public function getNameExt(): ?string + { + return $this->nameExt; + } + + + /** + * @param string $nameExt + * @return Item + */ + public function setNameExt(?string $nameExt): Item + { + $this->nameExt = $nameExt; + + return $this; + } + + + /** + * @return Variant[] + */ + public function getVariants(): array + { + return $this->variants; + } + + + public function addVariant(Variant $variant) + { + $this->variants[] = $variant; + } } diff --git a/src/Generators/Shoptet/Parameter.php b/src/Generators/Shoptet/Parameter.php index da39994..ec931e7 100644 --- a/src/Generators/Shoptet/Parameter.php +++ b/src/Generators/Shoptet/Parameter.php @@ -1,70 +1,50 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Parameter { - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - protected $name; - protected $value; - protected $unit; - protected $percentage; - - /** - * Parameter constructor. - * @param $name - * @param $value - * @param $unit - */ - public function __construct($name, $value, $unit = null, $percentage = null) - { - $this->name = $name; - $this->value = $value; - - $this->unit = $unit; - $this->percentage = $percentage; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; - } - - /** - * @return mixed - */ - public function getValue() - { - return $this->value; - } - - /** - * @return mixed - */ - public function getUnit() { - return $this->unit; - } - - /** - * @return null - */ - public function getPercentage() { - return $this->percentage; - } + +class Parameter +{ + protected string $name; + + protected $value; + + protected ?string $unit; + + protected ?float $percentage; + + + public function __construct($name, $value, ?string $unit = null, ?float $percentage = null) + { + $this->name = $name; + $this->value = $value; + $this->unit = $unit; + $this->percentage = $percentage; + } + + + public function getName(): string + { + return $this->name; + } + + + public function getValue() + { + return $this->value; + } + public function getUnit(): ?string + { + return $this->unit; + } + public function getPercentage(): ?float + { + return $this->percentage; + } } diff --git a/src/Generators/Shoptet/Variant.php b/src/Generators/Shoptet/Variant.php index 0b46ede..918b6c0 100644 --- a/src/Generators/Shoptet/Variant.php +++ b/src/Generators/Shoptet/Variant.php @@ -1,147 +1,121 @@ - * @package Mk\Feed\Generators\Heureka - */ class Variant { - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - /** @var string */ - private $code; - - /** @var Parameter[] */ - protected $parameters = array(); - - /** @var string */ - protected $vat; - - /** @var float */ - protected $weight; - - /** @var float @required */ - protected $priceVat; - - /** @var string */ - protected $availability; - - /** - * @return string - */ - public function getCode(): ?string { - return $this->code; - } - - /** - * @param string $code - * @return Variant - */ - public function setCode(?string $code): Variant { - $this->code = $code; - return $this; - } - - /** - * @return Parameter[] - */ - public function getParameters(): array { - return $this->parameters; - } - - /** - * @param Parameter[] $parameters - * @return Variant - */ - public function setParameters(array $parameters): Variant { - $this->parameters = $parameters; - return $this; - } - - /** - * @return string - */ - public function getVat(): ?string { - return $this->vat; - } - - /** - * @param string $vat - * @return Variant - */ - public function setVat(?string $vat): Variant { - $this->vat = $vat; - return $this; - } - - /** - * @return float - */ - public function getWeight(): ?float { - return $this->weight; - } - - /** - * @param float $weight - * @return Variant - */ - public function setWeight(?float $weight): Variant { - $this->weight = $weight; - return $this; - } - - /** - * @return float - */ - public function getPriceVat(): float { - return $this->priceVat; - } - - /** - * @param float $priceVat - * @return Variant - */ - public function setPriceVat(float $priceVat): Variant { - $this->priceVat = $priceVat; - return $this; - } - - /** - * @return string - */ - public function getAvailability(): ?string { - return $this->availability; - } - - /** - * @param string $availability - * @return Variant - */ - public function setAvailability(?string $availability): Variant { - $this->availability = $availability; - return $this; - } - - /** - * @param $name - * @param $val - * @return Variant - */ - public function addParameter($name, $val) - { - $this->parameters[] = new Parameter($name, $val); - - return $this; - } + /** @var Parameter[] */ + protected array $parameters = []; + + protected ?string $vat; + + protected ?float $weight; + + protected ?float $priceVat; + + protected ?string $availability; + + private ?string $code; + + + public function getCode(): ?string + { + return $this->code; + } + + + public function setCode(?string $code): self + { + $this->code = $code; + + return $this; + } + + + /** + * @return Parameter[] + */ + public function getParameters(): array + { + return $this->parameters; + } + + + /** + * @param Parameter[] $parameters + * @return self + */ + public function setParameters(array $parameters): self + { + $this->parameters = $parameters; + + return $this; + } + + + public function getVat(): ?string + { + return $this->vat; + } + + + public function setVat(?string $vat): self + { + $this->vat = $vat; + + return $this; + } + + + public function getWeight(): ?float + { + return $this->weight; + } + + + public function setWeight(?float $weight): self + { + $this->weight = $weight; + + return $this; + } + + + public function getPriceVat(): float + { + return $this->priceVat; + } + + + public function setPriceVat(float $priceVat): self + { + $this->priceVat = $priceVat; + + return $this; + } + + + public function getAvailability(): ?string + { + return $this->availability; + } + + + public function setAvailability(?string $availability): self + { + $this->availability = $availability; + return $this; + } + public function addParameter(string $name, $val): self + { + $this->parameters[] = new Parameter($name, $val); + return $this; + } } diff --git a/src/Generators/Shoptet/latte/item.latte b/src/Generators/Shoptet/latte/item.latte index a2a791b..8a597af 100644 --- a/src/Generators/Shoptet/latte/item.latte +++ b/src/Generators/Shoptet/latte/item.latte @@ -1,64 +1,64 @@ {contentType xml} - {$item->getItemId()} - getProductName()}]]> - getProduct()}]]> - getShortDescription()|striptags|noescape}]]> - getDescription()|striptags|noescape}]]> - {$item->getUrl()} + {$item->getItemId()} + getProductName()}]]> + getProduct()}]]> + getShortDescription()|striptags|noescape}]]> + getDescription()|striptags|noescape}]]> + {$item->getUrl()} - - - {$image->getUrl()} - - + + + {$image->getUrl()} + + - {$item->getVideoUrl()} - {$item->getPriceVat()} + {$item->getVideoUrl()} + {$item->getPriceVat()} - {if !empty($parameters = $item->getParameters())} - - - {$parameter->getName()} - {$parameter->getValue()}{$parameter->getUnit()} - - - {/if} + {if !empty($parameters = $item->getParameters())} + + + {$parameter->getName()} + {$parameter->getValue()}{$parameter->getUnit()} + + + {/if} - {$item->getWarranty()} - product - {$item->getCode()} - getManufacturer()}]]> - - - {$category} - - - {$item->getEan()} + {$item->getWarranty()} + product + {$item->getCode()} + getManufacturer()}]]> + + + {$category} + + + {$item->getEan()} - {$item->getAvailability()} - {$item->getItemGroupId()} - {$item->getWeight()} - {$item->getVat()} + {$item->getAvailability()} + {$item->getItemGroupId()} + {$item->getWeight()} + {$item->getVat()} - - - {$variant->getCode()} + + + {$variant->getCode()} - {if !empty($parameters = $variant->getParameters())} - - - {$parameter->getName()} - {$parameter->getValue()}{$parameter->getUnit()} - - - {/if} + {if !empty($parameters = $variant->getParameters())} + + + {$parameter->getName()} + {$parameter->getValue()}{$parameter->getUnit()} + + + {/if} - CZK - {$variant->getVat()} - {$variant->getPriceVat()} - {$variant->getAvailability()} - - + CZK + {$variant->getVat()} + {$variant->getPriceVat()} + {$variant->getAvailability()} + + diff --git a/src/Generators/Zbozi/CategoriesHelper.php b/src/Generators/Zbozi/CategoriesHelper.php index 64a7c01..ebc89e2 100644 --- a/src/Generators/Zbozi/CategoriesHelper.php +++ b/src/Generators/Zbozi/CategoriesHelper.php @@ -1,5 +1,7 @@ cache = new Cache($storage, __CLASS__); - } - } - public function getCategories() - { - $categories = array(); - if (!$this->cache || !($categories = $this->cache->load('categories'))) { - $file = sys_get_temp_dir() . '/file.xls'; - file_put_contents($file, file_get_contents(self::CATEGORY_URL)); + public function __construct(?IStorage $storage = null) + { + if ($storage !== null) { + $this->cache = new Cache($storage, 'feed/zbozi-categories-helper'); + } + } - $loaders = array( - new Excel5FileLoader(new FileLocator()), - ); - $resolver = new LoaderResolver($loaders); - $loader = new DelegatingLoader($resolver); + public function getCategories() + { + $categories = []; + if (!$this->cache || !($categories = $this->cache->load('categories'))) { + $file = sys_get_temp_dir() . '/file.xls'; + file_put_contents($file, file_get_contents(self::CATEGORY_URL)); - $data = $loader->load($file); - #clear header - unset($data[0]); + $loaders = [ + new Excel5FileLoader(new FileLocator()), + ]; - foreach ($data as $row) { - $categories[(int)$row[0]] = trim($row[2]); - } - asort($categories); - unlink($file); + $resolver = new LoaderResolver($loaders); + $loader = new DelegatingLoader($resolver); - if ($this->cache) { - $this->cache->save('categories', $categories); - } - } + $data = $loader->load($file); + #clear header + unset($data[0]); - return $categories; - } -} + foreach ($data as $row) { + $categories[(int) $row[0]] = trim($row[2]); + } + asort($categories); + unlink($file); + if ($this->cache) { + $this->cache->save('categories', $categories); + } + } + return $categories; + } +} diff --git a/src/Generators/Zbozi/CategoryText.php b/src/Generators/Zbozi/CategoryText.php index 3d4f799..a2e216c 100644 --- a/src/Generators/Zbozi/CategoryText.php +++ b/src/Generators/Zbozi/CategoryText.php @@ -1,39 +1,23 @@ - * @package Mk\Feed\Generators\Zbozi - */ -class CategoryText{ +namespace Mk\Feed\Generators\Zbozi; - use Nette\SmartObject; +class CategoryText +{ + protected string $text; - /** @var string */ - protected $text; - /** - * ExtraMessage constructor. - * @param $text - */ - public function __construct($text) - { - - $this->text = (string)$text; - } + public function __construct(string $text) + { + $this->text = $text; + } - /** - * @return string - */ - public function getText() - { - return $this->text; - } + public function getText(): string + { + return $this->text; + } } diff --git a/src/Generators/Zbozi/Delivery.php b/src/Generators/Zbozi/Delivery.php index 5b0a761..653c679 100644 --- a/src/Generators/Zbozi/Delivery.php +++ b/src/Generators/Zbozi/Delivery.php @@ -1,119 +1,99 @@ - * @package Mk\Feed\Generators\Heureka - */ -class Delivery{ - - /* Použití smartobject viz php 7.2 to nette 2.4 */ - use \Nette\SmartObject; - - CONST CESKA_POSTA = 'CESKA_POSTA', - CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', - CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', - SLOVENSKA_POSTA = 'SLOVENSKA_POSTA', - DPD = 'DPD', - DHL = 'DHL', - DSV = 'DSV', - EMS = 'EMS', - FOFR = 'FOFR', - GEBRUDER_WEISS = 'GEBRUDER_WEISS', - GEIS = 'GEIS', - GENERAL_PARCEL = 'GENERAL_PARCEL', - GLS = 'GLS', - HDS = 'HDS', - HEUREKAPOINT = 'HEUREKAPOINT', - INTIME = 'INTIME', - PPL = 'PPL', - RADIALKA = 'RADIALKA', - SEEGMULLER = 'SEEGMULLER', - TNT = 'TNT', - TOPTRANS = 'TOPTRANS', - UPS = 'UPS', - ULOZENKA = 'ULOZENKA', - VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', - ZASILKOVNA = 'ZASILKOVNA'; - - - static $ids = array( - self::CESKA_POSTA, - self::CESKA_POSTA_NA_POSTU, - self::CSAD_LOGISTIK_OSTRAVA, - self::DPD, - self::DHL, - self::DSV, - self::EMS, - self::FOFR, - self::GEBRUDER_WEISS, - self::GEIS, - self::GENERAL_PARCEL, - self::GLS, - self::HDS, - self::HEUREKAPOINT, - self::INTIME, - self::PPL, - self::RADIALKA, - self::SEEGMULLER, - self::TNT, - self::TOPTRANS, - self::UPS, - self::ULOZENKA, - self::VLASTNI_PREPRAVA, - self::ZASILKOVNA, - self::SLOVENSKA_POSTA, - ); - - /** @var string */ - private $id; - /** @var float */ - private $price; - /** @var float|null */ - private $priceCod; - - /** - * Delivery constructor. - * @param $id - * @param $price - * @param null $priceCod - */ - public function __construct($id, $price, $priceCod = null) - { - if (!in_array($id, self::$ids)) { - throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); - } - $this->id = (string) $id; - $this->price = (float) $price; - $this->priceCod = isset($priceCod) ? (float) $priceCod : null; - } - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * @return float|null - */ - public function getPriceCod() - { - return $this->priceCod; - } +class Delivery +{ + const CESKA_POSTA = 'CESKA_POSTA', + CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', + CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', + SLOVENSKA_POSTA = 'SLOVENSKA_POSTA', + DPD = 'DPD', + DHL = 'DHL', + DSV = 'DSV', + EMS = 'EMS', + FOFR = 'FOFR', + GEBRUDER_WEISS = 'GEBRUDER_WEISS', + GEIS = 'GEIS', + GENERAL_PARCEL = 'GENERAL_PARCEL', + GLS = 'GLS', + HDS = 'HDS', + HEUREKAPOINT = 'HEUREKAPOINT', + INTIME = 'INTIME', + PPL = 'PPL', + RADIALKA = 'RADIALKA', + SEEGMULLER = 'SEEGMULLER', + TNT = 'TNT', + TOPTRANS = 'TOPTRANS', + UPS = 'UPS', + ULOZENKA = 'ULOZENKA', + VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', + ZASILKOVNA = 'ZASILKOVNA'; + + + private static array $ids = [ + self::CESKA_POSTA, + self::CESKA_POSTA_NA_POSTU, + self::CSAD_LOGISTIK_OSTRAVA, + self::DPD, + self::DHL, + self::DSV, + self::EMS, + self::FOFR, + self::GEBRUDER_WEISS, + self::GEIS, + self::GENERAL_PARCEL, + self::GLS, + self::HDS, + self::HEUREKAPOINT, + self::INTIME, + self::PPL, + self::RADIALKA, + self::SEEGMULLER, + self::TNT, + self::TOPTRANS, + self::UPS, + self::ULOZENKA, + self::VLASTNI_PREPRAVA, + self::ZASILKOVNA, + self::SLOVENSKA_POSTA, + ]; + + private string $id; + + private float $price; + + private ?float $priceCod; + + + public function __construct(string $id, float $price, ?float $priceCod = null) + { + if (\in_array($id, self::$ids, true) === false) { + throw new \InvalidArgumentException('Delivery with "' . $id . '" does not exist.'); + } + $this->id = $id; + $this->price = $price; + $this->priceCod = $priceCod; + } + + + public function getId(): string + { + return $this->id; + } + + + public function getPrice(): float + { + return $this->price; + } + + + public function getPriceCod(): ?float + { + return $this->priceCod; + } } diff --git a/src/Generators/Zbozi/ExtraMessage.php b/src/Generators/Zbozi/ExtraMessage.php index 1e5e8e2..b88619d 100644 --- a/src/Generators/Zbozi/ExtraMessage.php +++ b/src/Generators/Zbozi/ExtraMessage.php @@ -1,60 +1,54 @@ - * @package Mk\Feed\Generators\Zbozi - */ -class ExtraMessage{ - - use Nette\SmartObject; - - CONST EXTENDED_WARRANTY = 'extended_warranty', - FREE_ACCESSORIES = 'free_accessories', - FREE_CASE = 'free_case', - FREE_DELIVERY = 'free_delivery', - FREE_GIFT = 'free_gift', - FREE_INSTALLATION = 'free_installation', - FREE_STORE_PICKUP = 'free_store_pickup', - VOUCHER = 'voucher'; - - static $types = array( - self::EXTENDED_WARRANTY, - self::FREE_ACCESSORIES, - self::FREE_CASE, - self::FREE_DELIVERY, - self::FREE_GIFT, - self::FREE_INSTALLATION, - self::FREE_STORE_PICKUP, - self::VOUCHER, - ); - - /** @var string */ - protected $type; - - /** - * ExtraMessage constructor. - * @param $type - */ - public function __construct($type) - { - if (!in_array($type, self::$types)) { - throw new \InvalidArgumentException("Extra message with type $type doesn\t exist"); - } - $this->type = (string)$type; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } +final class ExtraMessage +{ + public const EXTENDED_WARRANTY = 'extended_warranty'; + + public const FREE_ACCESSORIES = 'free_accessories'; + + public const FREE_CASE = 'free_case'; + + public const FREE_DELIVERY = 'free_delivery'; + + public const FREE_GIFT = 'free_gift'; + + public const FREE_INSTALLATION = 'free_installation'; + + public const FREE_STORE_PICKUP = 'free_store_pickup'; + + public const VOUCHER = 'voucher'; + + /** @var string[] */ + private static array $types = [ + self::EXTENDED_WARRANTY, + self::FREE_ACCESSORIES, + self::FREE_CASE, + self::FREE_DELIVERY, + self::FREE_GIFT, + self::FREE_INSTALLATION, + self::FREE_STORE_PICKUP, + self::VOUCHER, + ]; + + private string $type; + + + public function __construct(string $type) + { + if (in_array($type, self::$types, true) === false) { + throw new \InvalidArgumentException('Extra message with type "' . $type . '" does not exist.'); + } + $this->type = $type; + } + + + public function getType(): string + { + return $this->type; + } } diff --git a/src/Generators/Zbozi/Generator.php b/src/Generators/Zbozi/Generator.php index 8530291..7b2ac4d 100644 --- a/src/Generators/Zbozi/Generator.php +++ b/src/Generators/Zbozi/Generator.php @@ -1,24 +1,19 @@ - * @package Mk\Feed\Generators - * @see http://napoveda.seznam.cz/cz/zbozi/specifikace-xml-pro-obchody/specifikace-xml-feedu/ Documentation - */ -abstract class Generator extends BaseGenerator { +use Mk\Feed\Generators\BaseGenerator; - /** - * @param $name - * @return string - */ - protected function getTemplate($name) - { - $reflection = new \ReflectionClass(__CLASS__); - return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; - } +/** @see http://napoveda.seznam.cz/cz/zbozi/specifikace-xml-pro-obchody/specifikace-xml-feedu/ */ +abstract class Generator extends BaseGenerator +{ + protected function getTemplate(string $name): string + { + $reflection = new \ReflectionClass(__CLASS__); -} \ No newline at end of file + return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; + } +} diff --git a/src/Generators/Zbozi/Image.php b/src/Generators/Zbozi/Image.php index b0cf858..be5d70e 100644 --- a/src/Generators/Zbozi/Image.php +++ b/src/Generators/Zbozi/Image.php @@ -1,30 +1,23 @@ url = $url; - } + public function __construct(string $url) + { + $this->url = $url; + } - /** - * @return mixed - */ - public function getUrl() - { - return $this->url; - } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/Generators/Zbozi/Item.php b/src/Generators/Zbozi/Item.php index 4c988cc..496705e 100644 --- a/src/Generators/Zbozi/Item.php +++ b/src/Generators/Zbozi/Item.php @@ -2,645 +2,732 @@ namespace Mk\Feed\Generators\Zbozi; + use Mk; use Mk\Feed\Generators\BaseItem; -use Nette; /** * Class Item + * * @author Martin Knor * @package Mk\Feed\Generators\Zbozi * @see http://napoveda.seznam.cz/cz/zbozi/specifikace-xml-pro-obchody/specifikace-xml-feedu/ Documentation */ -class Item extends BaseItem { - - #required - /** @var string @required */ - protected $productName; - /** @var string @required */ - protected $description; - /** @var string @required */ - protected $url; - /** @var float @required */ - protected $priceVat; - /** @var \DateTime|int @required */ - protected $deliveryDate; - - /** @var Delivery|null */ - protected $delivery; - - - /** @var Delivery[] */ - protected $deliveries; - - #recomanded - /** @var string|null */ - protected $itemId; - /** @var Image[] */ - protected $images; - /** @var string|null */ - protected $ean; - /** @var string|null */ - protected $isbn; - /** @var string|null */ - protected $productNo; - /** @var string|null */ - protected $itemGroupId; - /** @var string|null */ - protected $manufacturer; - - #optional - /** @var string|null */ - protected $brand; - /** @var int|null */ - protected $categoryId; - /** @var CategoryText[] */ - protected $categoryTexts = array(); - /** @var string|null */ - protected $product; - /** @var string|null */ - protected $itemType = 'new'; - /** @var ExtraMessage[] */ - protected $extraMessages; - /** @var ShopDepot[] */ - protected $shopDepots; - /** @var bool */ - protected $visibility = true; - /** @var string|null */ - protected $customLabel; - /** @var string|null */ - protected $customLabel1; - /** @var string|null */ - protected $maxCpc; - /** @var float|null */ - protected $maxCpcSearch; - /** @var Parameter[] */ - protected $parameters = array(); - - #product database - /** @var string|null */ - protected $productLine; - /** @var float|null */ - protected $listPrice; - /** @var \DateTime|null */ - protected $releaseDate; - - /** - * @param $url - * @return $this - */ - public function addImage($url) - { - $this->images[] = new Image($url); - - return $this; - } - - /** - * @param $text - * @return $this - */ - public function addCategoryText($text) - { - $this->categoryTexts[] = new CategoryText($text); - - return $this; - } - - /** - * @param $name - * @param $val - * @param null $unit - * @return Item - */ - public function addParameter($name, $val, $unit = null) - { - $this->parameters[] = new Parameter($name, $val, $unit); - - return $this; - } - - public function addExtraMessage($type) - { - $this->extraMessages[] = new ExtraMessage($type); - - return $this; - } - - public function addShopDepot($id) - { - $this->shopDepots[] = new ShopDepot($id); - - return $this; - } - - /** - * @return ShopDepot[] - */ - public function getShopDepots() - { - return $this->shopDepots; - } - - /** - * @return string - */ - public function getProductName() - { - return $this->productName; - } - - /** - * @param string $productName - * @return Item - */ - public function setProductName($productName) - { - $this->productName = (string)$productName; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return Item - */ - public function setDescription($description) - { - $this->description = (string)$description; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - * @return Item - */ - public function setUrl($url) - { - $this->url = (string)$url; - - return $this; - } - - /** - * @return float - */ - public function getPriceVat() - { - return $this->priceVat; - } - - /** - * @param float $priceVat - * @return Item - */ - public function setPriceVat($priceVat) - { - $this->priceVat = (float)$priceVat; - - return $this; - } - - /** - * @return int|string - */ - public function getDeliveryDate() - { - return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; - } - - /** - * @param int|\DateTime $deliveryDate - * @return Item - */ - public function setDeliveryDate($deliveryDate) - { - if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { - throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); - } - $this->deliveryDate = $deliveryDate; - - return $this; - } - - /** - * @return null|string - */ - public function getItemId() - { - return $this->itemId; - } - - /** - * @param null|string $itemId - * @return Item - */ - public function setItemId($itemId) - { - $this->itemId = $itemId; - - return $this; - } - - /** - * @return null|string - */ - public function getEan() - { - return $this->ean; - } - - /** - * @param null|string $ean - * @return Item - */ - public function setEan($ean) - { - $this->ean = $ean; - - return $this; - } - - /** - * @return null|string - */ - public function getIsbn() - { - return $this->isbn; - } - - /** - * @param null|string $isbn - * @return Item - */ - public function setIsbn($isbn) - { - $this->isbn = $isbn; - - return $this; - } - - /** - * @return null|string - */ - public function getProductNo() - { - return $this->productNo; - } - - /** - * @param null|string $productNo - * @return Item - */ - public function setProductNo($productNo) - { - $this->productNo = $productNo; - - return $this; - } - - /** - * @return null|string - */ - public function getItemGroupId() - { - return $this->itemGroupId; - } - - /** - * @param null|string $itemGroupId - * @return Item - */ - public function setItemGroupId($itemGroupId) - { - $this->itemGroupId = $itemGroupId; - - return $this; - } - - /** - * @return null|string - */ - public function getManufacturer() - { - return $this->manufacturer; - } - - /** - * @param null|string $manufacturer - * @return Item - */ - public function setManufacturer($manufacturer) - { - $this->manufacturer = $manufacturer; - - return $this; - } - - /** - * @return null|string - */ - public function getBrand() - { - return $this->brand; - } - - /** - * @param null|string $brand - * @return Item - */ - public function setBrand($brand) - { - $this->brand = $brand; - - return $this; - } - - /** - * @return int|null - */ - public function getCategoryId() - { - return $this->categoryId; - } - - /** - * @param int|null $categoryId - * @return Item - */ - public function setCategoryId($categoryId) - { - $this->categoryId = $categoryId; - - return $this; - } - - /** - * @return null|string - */ - public function getCategoryTexts() - { - return $this->categoryTexts; - } - - - /** - * @return null|string - */ - public function getProduct() - { - return $this->product; - } - - /** - * @param null|string $product - * @return Item - */ - public function setProduct($product) - { - $this->product = $product; - - return $this; - } - - /** - * @return null|string - */ - public function getItemType() - { - return $this->itemType; - } - - /** - * @return boolean - */ - public function isVisibility() - { - return $this->visibility; - } - - /** - * @param boolean $visibility - * @return Item - */ - public function setVisibility($visibility) - { - $this->visibility = $visibility; - - return $this; - } - - /** - * @return null|string - */ - public function getCustomLabel() - { - return $this->customLabel; - } - - /** - * @param null|string $customLabel - * @return Item - */ - public function setCustomLabel($customLabel) - { - $this->customLabel = $customLabel; - - return $this; - } - - /** - * @return null|string - */ - public function getCustomLabel1() - { - return $this->customLabel1; - } - - /** - * @param null|string $customLabel1 - * @return Item - */ - public function setCustomLabel1($customLabel1) - { - $this->customLabel1 = $customLabel1; - - return $this; - } - - /** - * @return null|string - */ - public function getMaxCpc() - { - return $this->maxCpc; - } - - /** - * @param null|string $maxCpc - * @return Item - */ - public function setMaxCpc($maxCpc) - { - $this->maxCpc = $maxCpc; - - return $this; - } - - /** - * @return float|null - */ - public function getMaxCpcSearch() - { - return $this->maxCpcSearch; - } - - /** - * @param float|null $maxCpcSearch - * @return Item - */ - public function setMaxCpcSearch($maxCpcSearch) - { - $this->maxCpcSearch = $maxCpcSearch; - - return $this; - } - - /** - * @return mixed - */ - public function getProductLine() - { - return $this->productLine; - } - - /** - * @param mixed $productLine - * @return Item - */ - public function setProductLine($productLine) - { - $this->productLine = $productLine; - - return $this; - } - - /** - * @return mixed - */ - public function getListPrice() - { - return $this->listPrice; - } - - /** - * @param mixed $listPrice - * @return Item - */ - public function setListPrice($listPrice) - { - $this->listPrice = $listPrice; - - return $this; - } - - /** - * @return mixed - */ - public function getReleaseDate() - { - return $this->releaseDate; - } - - /** - * @param mixed $releaseDate - * @return Item - */ - public function setReleaseDate(\DateTime $releaseDate) - { - $this->releaseDate = $releaseDate; - - return $this; - } - - /** - * @return Image[] - */ - public function getImages() - { - return $this->images; - } - - /** - * @return ExtraMessage[] - */ - public function getExtraMessages() - { - return $this->extraMessages; - } - - /** - * @return Parameter[] - */ - public function getParameters() - { - return $this->parameters; - } - - /** - * @return Delivery|null - */ - public function getDelivery() { - return $this->delivery; - } - - /** - * @param Delivery|null $delivery - * @return Item - */ - public function setDelivery($delivery) { - $this->delivery = $delivery; - return $this; - } - - - /** - * @param Delivery $delivery - * @return $this - */ - public function addDelivery(Delivery $delivery) - { - $this->deliveries[] = $delivery; - - return $this; - } - - /** - * @return Delivery[] - */ - public function getDeliveries() - { - return $this->deliveries; - } +class Item extends BaseItem +{ + + #required + /** @var string @required */ + protected $productName; + + /** @var string @required */ + protected $description; + + /** @var string @required */ + protected $url; + + /** @var float @required */ + protected $priceVat; + + /** @var \DateTime|int @required */ + protected $deliveryDate; + + /** @var Delivery|null */ + protected $delivery; + + + /** @var Delivery[] */ + protected $deliveries; + + #recomanded + + /** @var string|null */ + protected $itemId; + + /** @var Image[] */ + protected $images; + + /** @var string|null */ + protected $ean; + + /** @var string|null */ + protected $isbn; + + /** @var string|null */ + protected $productNo; + + /** @var string|null */ + protected $itemGroupId; + + /** @var string|null */ + protected $manufacturer; + + #optional + + /** @var string|null */ + protected $brand; + + /** @var int|null */ + protected $categoryId; + + /** @var CategoryText[] */ + protected $categoryTexts = []; + + /** @var string|null */ + protected $product; + + /** @var string|null */ + protected $itemType = 'new'; + + /** @var ExtraMessage[] */ + protected $extraMessages; + + /** @var ShopDepot[] */ + protected $shopDepots; + + /** @var bool */ + protected $visibility = true; + + /** @var string|null */ + protected $customLabel; + + /** @var string|null */ + protected $customLabel1; + + /** @var string|null */ + protected $maxCpc; + + /** @var float|null */ + protected $maxCpcSearch; + + /** @var Parameter[] */ + protected $parameters = []; + + #product database + + /** @var string|null */ + protected $productLine; + + /** @var float|null */ + protected $listPrice; + + /** @var \DateTime|null */ + protected $releaseDate; + + + /** + * @param $url + * @return $this + */ + public function addImage($url) + { + $this->images[] = new Image($url); + + return $this; + } + + + /** + * @param $text + * @return $this + */ + public function addCategoryText($text) + { + $this->categoryTexts[] = new CategoryText($text); + + return $this; + } + + + /** + * @param $name + * @param $val + * @param null $unit + * @return Item + */ + public function addParameter($name, $val, $unit = null) + { + $this->parameters[] = new Parameter($name, $val, $unit); + + return $this; + } + + + public function addExtraMessage($type) + { + $this->extraMessages[] = new ExtraMessage($type); + + return $this; + } + + + public function addShopDepot($id) + { + $this->shopDepots[] = new ShopDepot($id); + + return $this; + } + + + /** + * @return ShopDepot[] + */ + public function getShopDepots() + { + return $this->shopDepots; + } + + + /** + * @return string + */ + public function getProductName() + { + return $this->productName; + } + + + /** + * @param string $productName + * @return Item + */ + public function setProductName($productName) + { + $this->productName = (string) $productName; + + return $this; + } + + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + + /** + * @param string $description + * @return Item + */ + public function setDescription($description) + { + $this->description = (string) $description; + + return $this; + } + + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + + /** + * @param string $url + * @return Item + */ + public function setUrl($url) + { + $this->url = (string) $url; + + return $this; + } + + + /** + * @return float + */ + public function getPriceVat() + { + return $this->priceVat; + } + /** + * @param float $priceVat + * @return Item + */ + public function setPriceVat($priceVat) + { + $this->priceVat = (float) $priceVat; + + return $this; + } + + + /** + * @return int|string + */ + public function getDeliveryDate() + { + return $this->deliveryDate instanceof \DateTime ? $this->deliveryDate->format('Y-m-d') : $this->deliveryDate; + } + + + /** + * @param int|\DateTime $deliveryDate + * @return Item + */ + public function setDeliveryDate($deliveryDate) + { + if (!is_int($deliveryDate) && !($deliveryDate instanceof \DateTime)) { + throw new \InvalidArgumentException("Delivery date must be integer or DateTime"); + } + $this->deliveryDate = $deliveryDate; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemId() + { + return $this->itemId; + } + + + /** + * @param null|string $itemId + * @return Item + */ + public function setItemId($itemId) + { + $this->itemId = $itemId; + + return $this; + } + + + /** + * @return null|string + */ + public function getEan() + { + return $this->ean; + } + + + /** + * @param null|string $ean + * @return Item + */ + public function setEan($ean) + { + $this->ean = $ean; + + return $this; + } + + + /** + * @return null|string + */ + public function getIsbn() + { + return $this->isbn; + } + + + /** + * @param null|string $isbn + * @return Item + */ + public function setIsbn($isbn) + { + $this->isbn = $isbn; + + return $this; + } + + + /** + * @return null|string + */ + public function getProductNo() + { + return $this->productNo; + } + + + /** + * @param null|string $productNo + * @return Item + */ + public function setProductNo($productNo) + { + $this->productNo = $productNo; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemGroupId() + { + return $this->itemGroupId; + } + + + /** + * @param null|string $itemGroupId + * @return Item + */ + public function setItemGroupId($itemGroupId) + { + $this->itemGroupId = $itemGroupId; + + return $this; + } + + + /** + * @return null|string + */ + public function getManufacturer() + { + return $this->manufacturer; + } + + + /** + * @param null|string $manufacturer + * @return Item + */ + public function setManufacturer($manufacturer) + { + $this->manufacturer = $manufacturer; + + return $this; + } + + + /** + * @return null|string + */ + public function getBrand() + { + return $this->brand; + } + + + /** + * @param null|string $brand + * @return Item + */ + public function setBrand($brand) + { + $this->brand = $brand; + + return $this; + } + + + /** + * @return int|null + */ + public function getCategoryId() + { + return $this->categoryId; + } + + + /** + * @param int|null $categoryId + * @return Item + */ + public function setCategoryId($categoryId) + { + $this->categoryId = $categoryId; + + return $this; + } + + + /** + * @return null|string + */ + public function getCategoryTexts() + { + return $this->categoryTexts; + } + + + /** + * @return null|string + */ + public function getProduct() + { + return $this->product; + } + + + /** + * @param null|string $product + * @return Item + */ + public function setProduct($product) + { + $this->product = $product; + + return $this; + } + + + /** + * @return null|string + */ + public function getItemType() + { + return $this->itemType; + } + + + /** + * @return boolean + */ + public function isVisibility() + { + return $this->visibility; + } + + + /** + * @param boolean $visibility + * @return Item + */ + public function setVisibility($visibility) + { + $this->visibility = $visibility; + + return $this; + } + + + /** + * @return null|string + */ + public function getCustomLabel() + { + return $this->customLabel; + } + + + /** + * @param null|string $customLabel + * @return Item + */ + public function setCustomLabel($customLabel) + { + $this->customLabel = $customLabel; + + return $this; + } + + + /** + * @return null|string + */ + public function getCustomLabel1() + { + return $this->customLabel1; + } + + + /** + * @param null|string $customLabel1 + * @return Item + */ + public function setCustomLabel1($customLabel1) + { + $this->customLabel1 = $customLabel1; + + return $this; + } + + + /** + * @return null|string + */ + public function getMaxCpc() + { + return $this->maxCpc; + } + + + /** + * @param null|string $maxCpc + * @return Item + */ + public function setMaxCpc($maxCpc) + { + $this->maxCpc = $maxCpc; + + return $this; + } + + + /** + * @return float|null + */ + public function getMaxCpcSearch() + { + return $this->maxCpcSearch; + } + + + /** + * @param float|null $maxCpcSearch + * @return Item + */ + public function setMaxCpcSearch($maxCpcSearch) + { + $this->maxCpcSearch = $maxCpcSearch; + + return $this; + } + + + /** + * @return mixed + */ + public function getProductLine() + { + return $this->productLine; + } + + + /** + * @param mixed $productLine + * @return Item + */ + public function setProductLine($productLine) + { + $this->productLine = $productLine; + + return $this; + } + + + /** + * @return mixed + */ + public function getListPrice() + { + return $this->listPrice; + } + + + /** + * @param mixed $listPrice + * @return Item + */ + public function setListPrice($listPrice) + { + $this->listPrice = $listPrice; + + return $this; + } + + + /** + * @return mixed + */ + public function getReleaseDate() + { + return $this->releaseDate; + } + + + /** + * @param mixed $releaseDate + * @return Item + */ + public function setReleaseDate(\DateTime $releaseDate) + { + $this->releaseDate = $releaseDate; + + return $this; + } + + + /** + * @return Image[] + */ + public function getImages() + { + return $this->images; + } + + + /** + * @return ExtraMessage[] + */ + public function getExtraMessages() + { + return $this->extraMessages; + } + + + /** + * @return Parameter[] + */ + public function getParameters() + { + return $this->parameters; + } + + + /** + * @return Delivery|null + */ + public function getDelivery() + { + return $this->delivery; + } + + + /** + * @param Delivery|null $delivery + * @return Item + */ + public function setDelivery($delivery) + { + $this->delivery = $delivery; + + return $this; + } + + + /** + * @param Delivery $delivery + * @return $this + */ + public function addDelivery(Delivery $delivery) + { + $this->deliveries[] = $delivery; + + return $this; + } + + + /** + * @return Delivery[] + */ + public function getDeliveries() + { + return $this->deliveries; + } } diff --git a/src/Generators/Zbozi/Parameter.php b/src/Generators/Zbozi/Parameter.php index 1c9d6df..26e2646 100644 --- a/src/Generators/Zbozi/Parameter.php +++ b/src/Generators/Zbozi/Parameter.php @@ -1,58 +1,42 @@ - * @package Mk\Feed\Generators\Zbozi - * @see http://napoveda.seznam.cz/cz/zbozi/specifikace-xml-pro-obchody/specifikace-xml-feedu/#PARAM - */ -class Parameter{ - - use Nette\SmartObject; - - protected $name; - protected $value; - protected $unit; - - /** - * Parameter constructor. - * @param $name - * @param $value - * @param $unit - */ - public function __construct($name, $value, $unit = null) - { - $this->name = (string)$name; - $this->value = (string)$value; - $this->unit = isset($unit) ? (string) $unit : null; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; - } - - /** - * @return mixed - */ - public function getValue() - { - return $this->value; - } - - /** - * @return null - */ - public function getUnit() - { - return $this->unit; - } +/** @see http://napoveda.seznam.cz/cz/zbozi/specifikace-xml-pro-obchody/specifikace-xml-feedu/#PARAM */ +class Parameter +{ + protected string $name; + + protected string $value; + + protected ?string $unit; + + + public function __construct(string $name, string $value, ?string $unit) + { + $this->name = $name; + $this->value = $value; + $this->unit = $unit; + } + + + public function getName(): string + { + return $this->name; + } + + + public function getValue(): string + { + return $this->value; + } + + + public function getUnit(): ?string + { + return $this->unit; + } } diff --git a/src/Generators/Zbozi/ShopDepot.php b/src/Generators/Zbozi/ShopDepot.php index 1714086..8aef6c0 100644 --- a/src/Generators/Zbozi/ShopDepot.php +++ b/src/Generators/Zbozi/ShopDepot.php @@ -1,26 +1,23 @@ id = $id; - } + public function __construct(int $id) + { + $this->id = $id; + } - /** - * @return mixed - */ - public function getId() - { - return $this->id; - } + public function getId(): int + { + return $this->id; + } } diff --git a/src/Generators/Zbozi/latte/footer.latte b/src/Generators/Zbozi/latte/footer.latte index 5cfd1ab..ed10ee2 100644 --- a/src/Generators/Zbozi/latte/footer.latte +++ b/src/Generators/Zbozi/latte/footer.latte @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/Generators/Zbozi/latte/header.latte b/src/Generators/Zbozi/latte/header.latte index 4d0e1c5..70b102b 100644 --- a/src/Generators/Zbozi/latte/header.latte +++ b/src/Generators/Zbozi/latte/header.latte @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/src/Generators/Zbozi/latte/item.latte b/src/Generators/Zbozi/latte/item.latte index 33222c9..97181c0 100644 --- a/src/Generators/Zbozi/latte/item.latte +++ b/src/Generators/Zbozi/latte/item.latte @@ -1,60 +1,62 @@ {contentType xml} - {$item->getProductName()} - getDescription()|striptags|noescape}]]> - {$item->getUrl()} - {$item->getPriceVat()} - {$item->getDeliveryDate()} - - {$delivery->getId()} - {$delivery->getPrice()} - {$delivery->getPriceCod()} - - - {$item->getItemId()} - - {if !empty($images = $item->getImages())} - {$image->getUrl()} - {/if} - - {$item->getEan()} - {$item->getIsbn()} - {$item->getProductNo()} - {$item->getItemGroupId()} - {$item->getManufacturer()} - {$item->getBrand()} - {$item->getCategoryId()} - - {if !empty($categoryTexts = $item->getCategoryTexts())} - {$categoryText->getText()} - {/if} - - {$item->getProduct()} - {*{$item->type}*} - - {if !empty($extraMessages = $item->getExtraMessages())} - {$extraMessage->getType()} - {/if} - - {if !empty($shopDepots = $item->getShopDepots())} - {$shopDepot->getId()} - {/if} - - {$item->isVisibility() ? 1 : 0} - {$item->getCustomLabel()} - {$item->getCustomLabel()} - {$item->getMaxCpc()} - {$item->getMaxCpcSearch()} - - {if !empty($parameters = $item->getParameters())} - - {$parameter->getName()} - {$parameter->getValue()} - {$parameter->getUnit()} - - {/if} - - {$item->getProductLine()} - {$item->getListPrice()} - {$item->getReleaseDate()|date:'c'} + {$item->getProductName()} + getDescription()|striptags|noescape}]]> + {$item->getUrl()} + {$item->getPriceVat()} + {$item->getDeliveryDate()} + + {$delivery->getId()} + {$delivery->getPrice()} + {$delivery->getPriceCod()} + + + {$item->getItemId()} + + {if !empty($images = $item->getImages())} + {$image->getUrl()} + {/if} + + {$item->getEan()} + {$item->getIsbn()} + {$item->getProductNo()} + {$item->getItemGroupId()} + {$item->getManufacturer()} + {$item->getBrand()} + {$item->getCategoryId()} + + {if !empty($categoryTexts = $item->getCategoryTexts())} + + {$categoryText->getText()} + + {/if} + + {$item->getProduct()} + + {if !empty($extraMessages = $item->getExtraMessages())} + {$extraMessage->getType()} + {/if} + + {if !empty($shopDepots = $item->getShopDepots())} + {$shopDepot->getId()} + {/if} + + {$item->isVisibility() ? 1 : 0} + {$item->getCustomLabel()} + {$item->getCustomLabel()} + {$item->getMaxCpc()} + {$item->getMaxCpcSearch()} + + + {if !empty($parameters = $item->getParameters())} + + {$parameter->getName()} + {$parameter->getValue()} + {$parameter->getUnit()} + + {/if} + + {$item->getProductLine()} + {$item->getListPrice()} + {$item->getReleaseDate()|date:'c'} diff --git a/src/IStorage.php b/src/IStorage.php index 571281c..9f64300 100644 --- a/src/IStorage.php +++ b/src/IStorage.php @@ -1,19 +1,13 @@ - * @package Mk\Feed - */ -class Storage implements IStorage { - /** @var */ - private $dir; - - /** - * Storage constructor. - * @param $dir - */ - function __construct($dir) - { - $this->dir = $dir; - } - - /** - * @param $filename - * @param $content - */ - public function save($filename, $content) - { - if(!is_dir($this->dir)) { - mkdir($this->dir); - } - file_put_contents(realpath($this->dir) . DIRECTORY_SEPARATOR . $filename, $this->formatXml($content)); - } - - /** - * @param $xml - * @return string - */ - protected function formatXml($xml) - { - $dom = new \DOMDocument('1.0'); - $dom->preserveWhiteSpace = false; - $dom->formatOutput = true; - $dom->loadXML($xml); - - return $dom->saveXML(); - } + +use Nette\Utils\FileSystem; + +final class Storage implements IStorage +{ + private string $dir; + + + public function __construct(string $dir) + { + $this->dir = $dir; + } + + + public function save(string $filename, string $content): void + { + FileSystem::createDir($this->dir); + file_put_contents(realpath($this->dir) . DIRECTORY_SEPARATOR . $filename, $this->formatXml($content)); + } + + + protected function formatXml(string $xml): string + { + $dom = new \DOMDocument('1.0'); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($xml); + + return $dom->saveXML(); + } } diff --git a/src/exceptions.php b/src/exceptions.php index a29e8c3..9bf555e 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -1,26 +1,20 @@