This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39b0b30
commit 62ee4eb
Showing
22 changed files
with
848 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
|
@@ -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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.