first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
<?php
namespace Empik\Marketplace\Utils;
use Configuration;
use Empik\Marketplace\Adapter\ConfigurationAdapter;
use Empik\Marketplace\Exception\LogicException;
class IdentifierExtractor
{
const IDENTIFIER_EAN = 'EAN';
const IDENTIFIER_SKU = 'SHOP_SKU';
/** @var string */
protected $identifierType;
public function __construct()
{
$this->identifierType = Configuration::get(ConfigurationAdapter::CONF_OFFER_IDENTIFIER);
}
/**
* @return bool|false|string
*/
public function getIdentifierType()
{
return $this->identifierType;
}
/**
* @return string
* @throws LogicException
*/
public function getFilterKey()
{
switch ($this->identifierType) {
case self::IDENTIFIER_EAN:
$key = 'p.ean13';
break;
case self::IDENTIFIER_SKU:
$key = 'p.reference';
break;
default:
throw new LogicException(sprintf('Unknown identifier type: "%s"', $this->identifierType));
}
return $key;
}
/**
* @param array $product
* @return mixed|string
* @throws LogicException
*/
public function extract(array $product)
{
switch ($this->identifierType) {
case self::IDENTIFIER_EAN:
$identifier = isset($product['ean13']) ? $product['ean13'] : '';
break;
case self::IDENTIFIER_SKU:
$identifier = isset($product['reference']) ? $product['reference'] : '';
break;
default:
throw new LogicException(sprintf('Unknown identifier type: "%s"', $this->identifierType));
}
return $identifier;
}
}