first commit

This commit is contained in:
2024-11-11 18:46:54 +01:00
commit a630d17338
25634 changed files with 4923715 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,183 @@
<?php
namespace x13allegro\Api\DataProvider;
use Configuration;
use Context;
use Country;
use Currency;
use Language;
use XAllegroConfiguration;
use x13allegro\Api\Model\Marketplace\Enum\Marketplace;
use x13allegro\Api\Model\Marketplace\Enum\MarketplaceCountry;
use x13allegro\Api\Model\Marketplace\Enum\MarketplaceCurrency;
use x13allegro\Api\Model\Marketplace\Enum\MarketplaceCurrencyPrecision;
use x13allegro\Api\Model\Marketplace\Enum\MarketplaceLocalization;
use x13allegro\Api\Model\Marketplace\Enum\MarketplaceOfferUrl;
use x13allegro\Exception\ModuleException;
final class MarketplacesProvider
{
/** @var string */
private $marketplaceId;
/** @var array */
private static $cache = [];
/**
* @param string $marketplaceId
* @throws ModuleException
*/
public function __construct($marketplaceId)
{
if (!Marketplace::isValid($marketplaceId)) {
throw new ModuleException("Invalid Marketplace $marketplaceId");
}
$this->marketplaceId = $marketplaceId;
}
/**
* @return Marketplace
*/
public function getMarketplace()
{
return Marketplace::from($this->marketplaceId);
}
/**
* @return string
*/
public function getMarketplaceName()
{
return $this->getMarketplace()->getValueTranslated();
}
/**
* @param int $offerId
* @param bool $isSandbox
* @return string
*/
public function getMarketplaceOfferUrl($offerId, $isSandbox)
{
$marketplaceId = Marketplace::from($this->marketplaceId)->getKey();
return str_replace(
[
'{sandbox}',
'{offerId}'
],
[
$isSandbox ? '.allegrosandbox.pl' : '',
$offerId
],
MarketplaceOfferUrl::$marketplaceId()->getValue()
);
}
/**
* @return Country
* @throws ModuleException
*/
public function getMarketplaceCountry()
{
if (isset(self::$cache[$this->marketplaceId]['country'])) {
return self::$cache[$this->marketplaceId]['country'];
}
$marketplaceLocalization = self::getMarketplacesLocalization()[$this->marketplaceId];
$countryIso = $marketplaceLocalization['countryIso'];
$countryId = Country::getByIso($countryIso);
if (!$countryId) {
throw new ModuleException("Country $countryIso does not exists");
}
self::$cache[$this->marketplaceId]['country'] = new Country($countryId, Context::getContext()->language->id);
return self::$cache[$this->marketplaceId]['country'];
}
/**
* @return Currency
* @throws ModuleException
*/
public function getMarketplaceCurrency()
{
if (isset(self::$cache[$this->marketplaceId]['currency'])) {
return self::$cache[$this->marketplaceId]['currency'];
}
$marketplaceLocalization = self::getMarketplacesLocalization()[$this->marketplaceId];
$currencyIso = $marketplaceLocalization['currencyIso'];
$currencyId = Currency::getIdByIsoCode($currencyIso);
if (!$currencyId) {
throw new ModuleException("Currency $currencyIso does not exists");
}
$currency = new Currency($currencyId);
// fix for already installed Currency
// PrestaShop may have different currencies precision than Allegro
$currency->decimals = ($marketplaceLocalization['currencyPrecision'] > 0 ? 1 : 0);
$currency->precision = $marketplaceLocalization['currencyPrecision'];
if (XAllegroConfiguration::get('AUCTION_MARKETPLACE_CONVERSION_RATE') === 'VALUE') {
$conversionRate = json_decode(XAllegroConfiguration::get('AUCTION_MARKETPLACE_CONVERSION_RATE_VALUE'), true);
if (!empty($conversionRate[$currency->id])) {
$currency->conversion_rate = $conversionRate[$currency->id];
}
}
// fix for empty conversion_rate OR default currency
if (empty($currency->conversion_rate) || $currency->id === (int)Configuration::get('PS_CURRENCY_DEFAULT')) {
$currency->conversion_rate = 1;
}
self::$cache[$this->marketplaceId]['currency'] = $currency;
return self::$cache[$this->marketplaceId]['currency'];
}
/**
* @return Language
*/
public function getMarketplaceLanguage()
{
if (isset(self::$cache[$this->marketplaceId]['language'])) {
return self::$cache[$this->marketplaceId]['language'];
}
$marketplaceLocalization = self::getMarketplacesLocalization()[$this->marketplaceId];
$languageIso = $marketplaceLocalization['localizationIso'];
self::$cache[$this->marketplaceId]['language'] = new Language(Language::getIdByIso($languageIso));
return self::$cache[$this->marketplaceId]['language'];
}
/**
* @return array
*/
public static function getMarketplacesLocalization()
{
/** @var array $marketplaces */
static $marketplaces = null;
if ($marketplaces !== null) {
return $marketplaces;
}
foreach (Marketplace::toArray() as $key => $value) {
$marketplaces[$value] = [
'localizationIso' => MarketplaceLocalization::$key()->getValue(),
'countryIso' => MarketplaceCountry::$key()->getValue(),
'currencyIso' => MarketplaceCurrency::$key()->getValue(),
'currencyPrecision' => MarketplaceCurrencyPrecision::$key()->getValue()
];
}
return $marketplaces;
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace x13allegro\Api\Model\Command;
interface CommandInterface {}

View File

@@ -0,0 +1,61 @@
<?php
namespace x13allegro\Api\Model\Command;
use JsonSerializable;
final class OfferCriteria implements JsonSerializable
{
const TYPE_CONTAINS_OFFERS = 'CONTAINS_OFFERS';
/** @var Offer[] */
public $offers;
/** @var string */
public $type;
/** @var array */
private $offersCollection = array();
/**
* @param string|array $offers
* @return $this
*/
public function offers($offers)
{
if (!is_array($offers)) {
$offers = array($offers);
}
foreach ($offers as $offer) {
$this->offersCollection[] = new Offer($offer);
}
return $this;
}
/**
* @return array
*/
public function jsonSerialize()
{
return array(
'offers' => $this->offersCollection,
'type' => $this->type
);
}
}
final class Offer
{
/** @var string */
public $id;
/**
* @param string $id
*/
public function __construct($id)
{
$this->id = $id;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace x13allegro\Api\Model\Command\OfferPublication;
use x13allegro\Api\Model\Command\CommandInterface;
final class OfferPublicationCommand implements CommandInterface
{
/** @var Publication */
public $publication;
/** @var \x13allegro\Api\Model\Command\OfferCriteria[] */
public $offerCriteria;
/**
* @return \x13allegro\Api\Model\Command\OfferCriteria
*/
public function offerCriteria()
{
return $this->offerCriteria[0];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace x13allegro\Api\Model\Command\OfferPublication;
final class Publication
{
/** @var string */
public $action;
/** @var \x13allegro\Api\Model\DateTime */
public $scheduledFor;
}

View File

@@ -0,0 +1,9 @@
<?php
namespace x13allegro\Api\Model\Command\OfferPublication;
final class PublicationAction
{
const ACTIVATE = 'ACTIVATE';
const END = 'END';
}

View File

@@ -0,0 +1,50 @@
<?php
namespace x13allegro\Api\Model\Command\PriceChange;
use JsonSerializable;
final class Modification implements JsonSerializable
{
/** @var string */
public $type;
/** @var \x13allegro\Api\Model\Price */
public $price;
/** @var \x13allegro\Api\Model\Price */
public $value;
/** @var string */
public $percentage;
/**
* @return array
*/
public function jsonSerialize()
{
$type = [
'type' => $this->type
];
switch ($this->type)
{
case ModificationType::INCREASE_PRICE:
case ModificationType::DECREASE_PRICE:
return $type + [
'value' => $this->value
];
case ModificationType::INCREASE_PERCENTAGE:
case ModificationType::DECREASE_PERCENTAGE:
return $type + [
'percentage' => (string)$this->percentage
];
default:
return $type + [
'price' => $this->price
];
}
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace x13allegro\Api\Model\Command\PriceChange;
final class ModificationType
{
const FIXED_PRICE = 'FIXED_PRICE';
const INCREASE_PRICE = 'INCREASE_PRICE';
const DECREASE_PRICE = 'DECREASE_PRICE';
const INCREASE_PERCENTAGE = 'INCREASE_PERCENTAGE';
const DECREASE_PERCENTAGE = 'DECREASE_PERCENTAGE';
}

View File

@@ -0,0 +1,22 @@
<?php
namespace x13allegro\Api\Model\Command\PriceChange;
use x13allegro\Api\Model\Command\CommandInterface;
final class PriceChangeCommand implements CommandInterface
{
/** @var Modification */
public $modification;
/** @var \x13allegro\Api\Model\Command\OfferCriteria[] */
public $offerCriteria;
/**
* @return \x13allegro\Api\Model\Command\OfferCriteria
*/
public function offerCriteria()
{
return $this->offerCriteria[0];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace x13allegro\Api\Model\Command\QuantityChange;
final class Modification
{
/** @var string */
public $changeType;
/** @var int */
public $value;
}

View File

@@ -0,0 +1,9 @@
<?php
namespace x13allegro\Api\Model\Command\QuantityChange;
final class ModificationType
{
const FIXED = 'FIXED';
const GAIN = 'GAIN';
}

View File

@@ -0,0 +1,22 @@
<?php
namespace x13allegro\Api\Model\Command\QuantityChange;
use x13allegro\Api\Model\Command\CommandInterface;
final class QuantityChangeCommand implements CommandInterface
{
/** @var Modification */
public $modification;
/** @var \x13allegro\Api\Model\Command\OfferCriteria[] */
public $offerCriteria;
/**
* @return \x13allegro\Api\Model\Command\OfferCriteria
*/
public function offerCriteria()
{
return $this->offerCriteria[0];
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model;
use DateTime as PhpDateTime;
use JsonSerializable;
final class DateTime extends PhpDateTime implements JsonSerializable
{
/**
* @return string
*/
public function jsonSerialize()
{
return $this->format(self::ATOM);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model;
final class Image
{
/** @var string */
public $url;
/**
* @param string $url
*/
public function __construct($url = '')
{
$this->url = $url;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Api\XAllegroApi;
use x13allegro\Component\Enum;
/**
* @method static Marketplace ALLEGRO_PL()
* @method static Marketplace ALLEGRO_CZ()
* @method static Marketplace ALLEGRO_SK()
*/
final class Marketplace extends Enum
{
static $backedEnum = true;
const ALLEGRO_PL = XAllegroApi::MARKETPLACE_PL;
const ALLEGRO_CZ = XAllegroApi::MARKETPLACE_CZ;
const ALLEGRO_SK = XAllegroApi::MARKETPLACE_SK;
/**
* @return string[]
*/
public static function translateValues()
{
return [
self::ALLEGRO_PL => 'Polska - allegro.pl',
self::ALLEGRO_CZ => 'Czechy - allegro.cz',
self::ALLEGRO_SK => 'Słowacja - allegro.sk'
];
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Component\Enum;
/**
* @method static MarketplaceCountry ALLEGRO_PL()
* @method static MarketplaceCountry ALLEGRO_CZ()
* @method static MarketplaceCountry ALLEGRO_SK()
*/
final class MarketplaceCountry extends Enum
{
const ALLEGRO_PL = 'PL';
const ALLEGRO_CZ = 'CZ';
const ALLEGRO_SK = 'SK';
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Component\Enum;
/**
* @method static MarketplaceCurrency ALLEGRO_PL()
* @method static MarketplaceCurrency ALLEGRO_CZ()
* @method static MarketplaceCurrency ALLEGRO_SK()
*/
final class MarketplaceCurrency extends Enum
{
const ALLEGRO_PL = 'PLN';
const ALLEGRO_CZ = 'CZK';
const ALLEGRO_SK = 'EUR';
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Component\Enum;
/**
* @method static MarketplaceCurrencyPrecision ALLEGRO_PL()
* @method static MarketplaceCurrencyPrecision ALLEGRO_CZ()
* @method static MarketplaceCurrencyPrecision ALLEGRO_SK()
*/
final class MarketplaceCurrencyPrecision extends Enum
{
const ALLEGRO_PL = 2;
const ALLEGRO_CZ = 0;
const ALLEGRO_SK = 2;
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Component\Enum;
/**
* @method static MarketplaceLocalization ALLEGRO_PL()
* @method static MarketplaceLocalization ALLEGRO_CZ()
* @method static MarketplaceLocalization ALLEGRO_SK()
*/
final class MarketplaceLocalization extends Enum
{
const ALLEGRO_PL = 'pl';
const ALLEGRO_CZ = 'cz';
const ALLEGRO_SK = 'sk';
}

View File

@@ -0,0 +1,17 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Component\Enum;
/**
* @method static MarketplaceOfferUrl ALLEGRO_PL()
* @method static MarketplaceOfferUrl ALLEGRO_CZ()
* @method static MarketplaceOfferUrl ALLEGRO_SK()
*/
final class MarketplaceOfferUrl extends Enum
{
const ALLEGRO_PL = 'https://allegro.pl{sandbox}/oferta/{offerId}';
const ALLEGRO_CZ = 'https://allegro.cz{sandbox}/nabidka/{offerId}';
const ALLEGRO_SK = 'https://allegro.sk{sandbox}/ponuka/{offerId}';
}

View File

@@ -0,0 +1,35 @@
<?php
namespace x13allegro\Api\Model\Marketplace\Enum;
use x13allegro\Component\Enum;
/**
* @method static MarketplacePublicationStatus APPROVED()
* @method static MarketplacePublicationStatus REFUSED()
* @method static MarketplacePublicationStatus IN_PROGRESS()
* @method static MarketplacePublicationStatus NOT_REQUESTED()
* @method static MarketplacePublicationStatus PENDING()
*/
final class MarketplacePublicationStatus extends Enum
{
const APPROVED = 'APPROVED';
const REFUSED = 'REFUSED';
const IN_PROGRESS = 'IN_PROGRESS';
const NOT_REQUESTED = 'NOT_REQUESTED';
const PENDING = 'PENDING';
/**
* @return array
*/
public static function translateValues()
{
return [
self::APPROVED => 'zatwierdzona',
self::REFUSED => 'odrzucona',
self::IN_PROGRESS => 'przetwarzana',
self::NOT_REQUESTED => 'nie zgłoszona',
self::PENDING => 'w oczekiwaniu'
];
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace x13allegro\Api\Model;
final class OfferPropertyDelete {}

Some files were not shown because too many files have changed in this diff Show More