Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Feat: Multistore
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed Oct 17, 2021
1 parent 39b0b30 commit 62ee4eb
Show file tree
Hide file tree
Showing 22 changed files with 848 additions and 410 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Trovaprezzi.it XML feed export module for [PrestaShop](https://github.com/presta

## Copyright

(c) 2020, [Pittica S.r.l.s.](https://pittica.com).
(c) 2020-2021, [Pittica S.r.l.](https://pittica.com).
42 changes: 39 additions & 3 deletions classes/GoogleProvider.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
<?php

/**
* prestashop-trovaprezzi
* PrestaShop Module - pitticatrovaprezzi
*
* Copyright 2020 Pittica S.r.l.s.
* Copyright 2020-2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/Trovaprezzi
* @author Lucio Benini <[email protected]>
* @copyright 2020 Pittica S.r.l.s.
* @copyright 2020-2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-trovaprezzi
*/

require_once(dirname(__FILE__) . '/Provider.php');

/**
* Google provider class.
*
* @category Provider
* @package Pittica/Trovaprezzi
* @author Lucio Benini <[email protected]>
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-trovaprezzi/blob/main/classes/GoogleProvider.php
* @since 1.2.0
*/
class GoogleProvider extends Provider
{
protected $country;
protected $context;
protected $carrier;
protected $locale;

/**
* {@inheritDoc}
*
* @since 1.2.0
*/
public function __construct()
{
$this->country = Country::getIsoById((int)Configuration::get('PS_COUNTRY_DEFAULT'));
Expand All @@ -27,16 +45,34 @@ public function __construct()
$this->locale = Tools::getContextLocale($this->context);
}

/**
* {@inheritDoc}
*
* @return string
* @since 1.2.0
*/
public function getElementRoot()
{
return 'rss';
}

/**
* {@inheritDoc}
*
* @return string
* @since 1.2.0
*/
public function getElementItem()
{
return 'item';
}

/**
* {@inheritDoc}
*
* @return string
* @since 1.2.0
*/
public function getFilename()
{
return 'google';
Expand Down
202 changes: 135 additions & 67 deletions classes/Provider.php
Original file line number Diff line number Diff line change
@@ -1,80 +1,148 @@
<?php

/**
* prestashop-trovaprezzi
* PrestaShop Module - pitticatrovaprezzi
*
* Copyright 2020 Pittica S.r.l.s.
* Copyright 2020-2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/Trovaprezzi
* @author Lucio Benini <[email protected]>
* @copyright 2020 Pittica S.r.l.s.
* @copyright 2020-2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-trovaprezzi
*/

require_once(dirname(__FILE__) . '/TrovaprezziOffer.php');
require_once dirname(__FILE__) . '/TrovaprezziOffer.php';

/**
* Base provider class.
*
* @category Provider
* @package Pittica/Trovaprezzi
* @author Lucio Benini <[email protected]>
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-trovaprezzi/blob/main/classes/Provider.php
* @since 1.2.0
*/
abstract class Provider
{
public static function getProvider($name)
{
$class = ucfirst($name) . 'Provider';

require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . $class . '.php');

return new $class;
}

public static function getProviders()
{
return array(
'trovaprezzi',
'google'
);
}

public abstract function getFilename();

public abstract function getElementRoot();

public abstract function getElementItem();

public function renderAttributes($xml)
{
return $xml;
}

public abstract function renderItem($xml, $offer);

public function renderBody($xml)
{
$offers = TrovaprezziOffer::getOffers();

foreach ($offers as $offer) {
if ($offer->active) {
$xml->startElement($this->getElementItem());

$this->renderItem($xml, $offer);

$xml->endElement();
}
}

return $xml;
}

public function generate($path)
{
$xml = new XmlWriter();
$xml->openUri($path);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement($this->getElementRoot());

$this->renderAttributes($xml);
$this->renderBody($xml);

$xml->endElement();
$xml->endDocument();
$xml->flush();

return true;
}
/**
* Gets the provider with the given name.
*
* @param string $name The provider's name.
*
* @return Provider
*/
public static function getProvider($name)
{
$class = ucfirst($name) . 'Provider';

include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . $class . '.php';

return new $class;
}

/**
* Gets the available providers.
*
* @return array
*/
public static function getProviders()
{
return array(
'trovaprezzi',
'google'
);
}

/**
* Gets the filename.
*
* @return string
* @since 1.2.0
*/
public abstract function getFilename();

/**
* Gets the element root name.
*
* @return string
* @since 1.2.0
*/
public abstract function getElementRoot();

/**
* Gets the element item name.
*
* @return string
* @since 1.2.0
*/
public abstract function getElementItem();

public function renderAttributes($xml)
{
return $xml;
}

/**
* Renders an offer object.
*
* @param XmlWriter $xml XML object.
* @param TrovaprezziOffer $offer Offer item.
*
* @return XmlWriter
* @since 1.2.0
*/
public abstract function renderItem($xml, $offer);

/**
* Renders the XML body.
*
* @param XmlWriter $xml XML object.
*
* @return XmlWriter
* @since 1.2.0
*/
public function renderBody($xml)
{
$offers = TrovaprezziOffer::getOffers();

foreach ($offers as $offer) {
if ($offer->active) {
$xml->startElement($this->getElementItem());

$this->renderItem($xml, $offer);

$xml->endElement();
}
}

return $xml;
}

/**
* Writes the XML document.
*
* @param string $path Document path.
*
* @return boolean
* @since 1.2.0
*/
public function generate($path)
{
$xml = new XmlWriter();
$xml->openUri($path);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement($this->getElementRoot());

$this->renderAttributes($xml);
$this->renderBody($xml);

$xml->endElement();
$xml->endDocument();
$xml->flush();

return true;
}
}
Loading

0 comments on commit 62ee4eb

Please sign in to comment.