Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions urbitinventoryfeed/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function getCombinations($productId)
*/
public static function getCategoryFilters()
{
$filterValue = Configuration::get('URBITINVENTORYFEED_FILTER_CATEGORIES', null);
$filterValue = self::getConfigValue('URBITINVENTORYFEED_FILTER_CATEGORIES');

return $filterValue ? explode(',', $filterValue) : null;
}
Expand All @@ -191,7 +191,7 @@ public static function getCategoryFilters()
*/
public static function getTagsFilters()
{
$filterValue = Configuration::get('URBITINVENTORYFEED_TAGS_IDS', null);
$filterValue = self::getConfigValue('URBITINVENTORYFEED_TAGS_IDS');

return $filterValue ? explode(',', $filterValue) : null;
}
Expand All @@ -202,7 +202,7 @@ public static function getTagsFilters()
*/
public static function getProductFilters()
{
$filterValue = Configuration::get('URBITINVENTORYFEED_PRODUCT_ID_FILTER', null);
$filterValue = self::getConfigValue('URBITINVENTORYFEED_PRODUCT_ID_FILTER');

return $filterValue ? explode(',', $filterValue) : null;
}
Expand All @@ -212,7 +212,7 @@ public static function getProductFilters()
*/
public static function getMinimalStockFilter()
{
$filterValue = Configuration::get('URBITINVENTORYFEED_MINIMAL_STOCK', null);
$filterValue = self::getConfigValue('URBITINVENTORYFEED_MINIMAL_STOCK');

return $filterValue ? : null;
}
Expand All @@ -231,6 +231,8 @@ public static function getMinimalStockFilter()
* @param bool $only_active
* @param Context|null $context
* @return array|false|mysqli_result|null|PDOStatement|resource
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @internal param bool $product_id
*/
public static function getFilteredProducts(
Expand Down Expand Up @@ -352,4 +354,17 @@ public function getFeedVersion()
{
return static::FEED_VERSION;
}

/**
* Get value from ps_configuration for this key
* If multistore enable => get config value only for current store
* @param $key
* @return string
*/
protected static function getConfigValue($key)
{
return (version_compare(_PS_VERSION_, '1.5', '>') && Shop::isFeatureActive()) ?
Configuration::get($key, null, null, Context::getContext()->shop->id) :
Configuration::get($key, null);
}
}
15 changes: 14 additions & 1 deletion urbitinventoryfeed/Model/Feed/Fields/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getInventoryInputs()
*/
public static function getInputConfig($name)
{
return Configuration::get($name, null);
return self::getConfigValue($name);
}

/**
Expand Down Expand Up @@ -258,4 +258,17 @@ public static function getModule()
{
return Urbitinventoryfeed::getInstance();
}

/**
* Get value from ps_configuration for this key
* If multistore enable => get config value only for current store
* @param $key
* @return string
*/
protected static function getConfigValue($key)
{
return (version_compare(_PS_VERSION_, '1.5', '>') && Shop::isFeatureActive()) ?
Configuration::get($key, null, null, Context::getContext()->shop->id) :
Configuration::get($key, null);
}
}
4 changes: 2 additions & 2 deletions urbitinventoryfeed/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<module>
<name>urbitinventoryfeed</name>
<displayName><![CDATA[Urbit Inventory Feed]]></displayName>
<version><![CDATA[1.0.3]]></version>
<version><![CDATA[1.0.3.5]]></version>
<description><![CDATA[Urbit Inventory Feed Module]]></description>
<author><![CDATA[Urbit]]></author>
<tab><![CDATA[administration]]></tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
</module>
4 changes: 2 additions & 2 deletions urbitinventoryfeed/config_fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<module>
<name>urbitinventoryfeed</name>
<displayName><![CDATA[Urbit Flux de Stock]]></displayName>
<version><![CDATA[1.0.3]]></version>
<version><![CDATA[1.0.3.5]]></version>
<description><![CDATA[Module Urbit Flux de stock]]></description>
<author><![CDATA[Urbit]]></author>
<tab><![CDATA[administration]]></tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
</module>
12 changes: 12 additions & 0 deletions urbitinventoryfeed/config_gb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>urbitinventoryfeed</name>
<displayName><![CDATA[Urbit Inventory Feed]]></displayName>
<version><![CDATA[1.0.3.5]]></version>
<description><![CDATA[Urbit Inventory Feed Module]]></description>
<author><![CDATA[Urbit]]></author>
<tab><![CDATA[administration]]></tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
108 changes: 100 additions & 8 deletions urbitinventoryfeed/controllers/front/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,35 @@ public function initContent()
parent::initContent();

if ($this->ajax) {
$result = Tools::getIsset(Tools::getValue(array('configValues'))) ?
$result = Tools::getValue('configValues') ?
$this->getAjaxOptionsForResultFilter() : $this->getAjaxOptionsForProductFilter();

die(Tools::jsonEncode($result));
}

$token = Tools::getValue('token');

if (version_compare(_PS_VERSION_, '1.5', '>') && Shop::isFeatureActive()) {

$id_shop = $this->context->shop->id;
$tokenInConfig = Configuration::get('URBITINVENTORYFEED_FEED_TOKEN', null, null, $id_shop);

$allTokens_raw = $this->getAllTokensOfShop();

$allTokens = array();

foreach ($allTokens_raw as $allTokens_subraw) {
$allTokens[$allTokens_subraw['token']] = $allTokens_subraw['token'];
}
} else {
$tokenInConfig = Configuration::get('URBITINVENTORYFEED_FEED_TOKEN');
$allTokens[$tokenInConfig]=$tokenInConfig;
}

if ($token == '' || ($token != $tokenInConfig && !in_array($token, $allTokens))) {
die("<?xml version='1.0' encoding='utf-8'?><error>Invalid Token</error>");
}

header('Content-Type: application/json');

if (version_compare(_PS_VERSION_, "1.7", "<")) {
Expand All @@ -70,9 +93,9 @@ public function initContent()
*/
protected function getAjaxOptionsForProductFilter()
{
$categoryFilters = Tools::getValue(array('categoriesFromAjax'));
$tagFilters = Tools::getValue(array('tagsFromAjax'));
$minimalStockFilter = Tools::getValue(array('minimalStockFromAjax'));
$categoryFilters = Tools::getValue('categoriesFromAjax');
$tagFilters = Tools::getValue('tagsFromAjax');
$minimalStockFilter = Tools::getValue('minimalStockFromAjax');

$optionsForProductMultiSelect = array();

Expand Down Expand Up @@ -135,7 +158,7 @@ public function generateByCron()

if (!$feedHelper->checkCache()) {
$feedHelper->generateFeed($this->getFilteredProductCollection());
}
}
}

/**
Expand All @@ -144,10 +167,10 @@ public function generateByCron()
*/
protected function getFilteredProductCollection()
{
$categoryFilters = UrbitInventoryfeedFeed::getCategoryFilters();
$tagFilters = UrbitInventoryfeedFeed::getTagsFilters();
$categoryFilters = UrbitInventoryfeedFeed::getCategoryFilters()[0] != 'none' ? UrbitInventoryfeedFeed::getCategoryFilters() : null;
$tagFilters = UrbitInventoryfeedFeed::getTagsFilters()[0] != 'none' ? UrbitInventoryfeedFeed::getTagsFilters() : null;
$minimalStockFilter = UrbitInventoryfeedFeed::getMinimalStockFilter();
$resultFilter = UrbitInventoryfeedFeed::getProductFilters();
$resultFilter = UrbitInventoryfeedFeed::getProductFilters()[0] != 'none' ? UrbitInventoryfeedFeed::getProductFilters() : null;

$products = ($resultFilter) ?
$this->getProductsFilteredByResultFilter($resultFilter) :
Expand Down Expand Up @@ -198,4 +221,73 @@ protected function getProductsFilteredByStandardFilters($categoryFilterValue, $t
$minimalStockFilterValue
);
}

/**
* Gets all token of a given shop
* @param int $id_shop
* @return array
*/
public function getAllTokensOfShop()
{
$id_shop = $this->context->shop->id;
$id_shop_group = (int) $this->context->shop->id_shop_group;
$res = array();
$tokenGeneral = $this->getTokenValue($id_shop);

if ($tokenGeneral) {
$res[] = array(
'id_shop' => $id_shop,
'id_shop_group' => null,
'token' => $tokenGeneral,
'id_lang' => Configuration::get('PS_LANG_DEFAULT'),
'id_currency' => false
);
}

$shopLanguages = Language::getLanguages(true, $id_shop);
$shopCurrencies = Currency::getCurrenciesByIdShop($id_shop);

foreach ($shopLanguages as $currentLang) {
$idLang = $currentLang['id_lang'];

foreach ($shopCurrencies as $currentCurrency) {
$idCurrency = $currentCurrency['id_currency'];
$token = $this->getTokenValue($id_shop, $id_shop_group, $idCurrency, $idLang);

if ($token) {
$res[] = array(
'id_shop' => $id_shop,
'id_shop_group' => $id_shop_group,
'token' => $token,
'id_lang' => $idLang,
'id_currency' => $idCurrency
);
}
}
}

return $res;
}

/**
* Get the configured token
* @param int $id_shop the shop context
* @param int $id_currency (optionnal) the currency
* @param int $id_lang (optionnal) the lang
* @return string
*/
public function getTokenValue($id_shop, $id_shop_group = null, $id_currency = false, $id_lang = false)
{
$key = 'URBITINVENTORYFEED_FEED_TOKEN';

if ($id_currency && $id_lang) {
$key .= '_'.$id_currency.'_'.$id_lang;
}

if ($id_shop) {
return Configuration::get($key, null, $id_shop_group, $id_shop);
} else {
return Configuration::get($key);
}
}
}
Loading