Files
interblue.pl/modules/pshowimporter/classes/PShow_Prestashop_Fields.php
2024-10-25 14:16:28 +02:00

126 lines
3.5 KiB
PHP

<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShow_Prestashop_Fields
{
/**
* Get lang iso
*
* @return string
*/
public static function getLangIso()
{
$lang_iso = Tools::strtolower(Context::getContext()->language->iso_code);
if (count(glob(_IMPORT_FIELDS_PATH_ . $lang_iso . '_product.ini')) == 0) {
return 'en';
}
return $lang_iso;
}
/**
* Get fields available to import
*
* @param array $primary_config
* @return array
*/
public static function getFields($primary_config)
{
$whatToGet = str_replace('data_', '', $primary_config['file_contains']);
$lang_iso = self::getLangIso();
$ini_file = _IMPORT_FIELDS_PATH_ . $lang_iso . '_' . $whatToGet . '.ini';
$fields = PShow_Ini::read($ini_file);
if ($whatToGet == 'combination' && (bool) Configuration::getGlobalValue('mod_combination_description')) {
$fields['description'] = 'Description';
}
if ($whatToGet == 'combination' && (bool) Configuration::getGlobalValue('pshowimporter_mod_combination_dimensions')) {
$fields['width'] = 'Dimension - width';
$fields['height'] = 'Dimension - height';
$fields['depth'] = 'Dimension - depth';
}
// advanced stack management
if (($whatToGet == 'combination' || $whatToGet == 'product') &&
PShow_Addon::getInstance('ASM') && PShow_Addon::getInstance('ASM')->isEnabled()) {
$fields['asm_warehouse_name'] = 'Warehouse - name';
}
if ($primary_config['file_contains'] == 'data_combination') {
$fields = array_merge($fields, self::getProductAttributes());
}
if ($primary_config['file_contains'] == 'data_product') {
$fields = array_merge($fields, self::getProductFeatures());
}
self::sortFields($fields);
return array($whatToGet => $fields);
}
/**
* Sort assoc array
*
* @param array $array
*/
public static function sortFields(&$array)
{
asort($array);
}
/**
* Get product features
*
* @return array
*/
public static function getProductFeatures()
{
$features = Feature::getFeatures(Context::getContext()->language->id);
$result = array();
foreach ($features as $f) {
$result['feature:' . $f['id_feature']] = 'Feature - pre-definied value &lt;' . $f['name'] . '|id:' . $f['id_feature'] . '&gt;';
}
foreach ($features as $f) {
$result['feature_custom:' . $f['id_feature']] = 'Feature - customized value &lt;' . $f['name'] . '|id:' . $f['id_feature'] . '&gt; [string]';
}
return $result;
}
/**
* Get product attributes
*
* @return array
*/
public static function getProductAttributes()
{
$attrs = AttributeGroup::getAttributesGroups(Context::getContext()->language->id);
$result = array();
foreach ($attrs as $a) {
$result['attribute:' . $a['id_attribute_group']] = 'Attribute: ' . $a['name'] . '|id:' . $a['id_attribute_group'] . ' &lt;' . $a['group_type'] . '&gt;';
}
return $result;
}
}