first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,583 @@
<?php
use x13import\Wholesaler\WholesalerConfiguration;
require_once (dirname(__FILE__) . '/../../x13import.php');
class AdminXImportCategoriesController extends XImportController
{
/** @var XImportCategory */
protected $object;
public function __construct()
{
$this->table = 'ximport_category';
$this->identifier = 'id_ximport_category';
$this->className = 'XImportCategory';
$this->list_no_link = true;
parent::__construct();
$this->tpl_folder = 'x_import_categories/';
$this->fields_list = array(
'id_ximport_category' => array(
'title' => $this->l('ID'),
'align' => 'center',
'class' => 'fixed-width-xs',
'width' => 50,
'orderby' => true
),
'path' => array(
'title' => $this->l('Kategoria hurtowni'),
'width' => 'auto',
'callback' => 'pathCallback'
),
'name' => array(
'title' => $this->l('Kategoria w sklepie'),
'width' => 200,
'class' => 'fixed-width-lg',
),
'wholesaler_name' => array(
'title' => $this->l('Nazwa hurtowni'),
'width' => 100,
'class' => 'fixed-width-md',
),
'import' => array(
'title' => $this->l('Import'),
'type' => 'bool',
'active' => 'import',
'class' => 'fixed-width-sm center x-import',
'align' => 'center',
'width' => 80,
'search' => true,
'orderby' => true
),
'markup' => array(
'title' => $this->l('Narzut'),
'width' => 80
)
);
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Usuń wybrane'),
'icon' => 'icon-trash'
),
'import' => array(
'text' => $this->l('Włącz import'),
'icon' => 'icon-power-off text-success'
),
'noimport' => array(
'text' => $this->l('Wyłącz import'),
'icon' => 'icon-power-off text-danger'
),
array(
'text' => (version_compare(_PS_VERSION_, '1.6', '<') ? null : 'divider')
),
'markup' => array(
'text' => $this->l('Ustaw narzut kategorii'),
'icon' => 'bulkMarkup'
),
'tittlePattern' => array(
'text' => $this->l('Ustaw wzorzec nazwy produktu'),
'icon' => 'bulkTittlePattern'
)
);
// @todo refactoring
$this->_conf[32] = $this->l('Kategorie zostały poprawne pobrane.');
$this->_conf[33] = $this->l('Kategorie zostały poprawne zaimportowane.');
$this->_conf[34] = $this->l('Produkty zostały poprawnie wyłączone.');
$this->_conf[35] = $this->l('Produkty zostały poprawnie usunięte.');
$this->_conf[36] = $this->l('Narzut został popranie zmieniony.');
$this->_conf[37] = $this->l('Aktualizacja zakończona.');
$this->_conf[38] = $this->l('Wzorzec nazwy produktu został popranie zmieniony.');
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function renderForm()
{
$root_category = Category::getRootCategory();
$root_category = array('id_category' => $root_category->id, 'name' => $root_category->name);
$selectedCategoriesIds =
$selectedCategories = [];
if (!Validate::isLoadedObject($this->object)) {
return '';
}
if ($this->object->id) {
$selectedCategoriesIds = XImportCategory::getAdditionalCategoriesById($this->object->id);
foreach ($selectedCategoriesIds as $selectedCategoryId) {
$selectedCategories[] = [
'id_category' => $selectedCategoryId,
'name' => (new Category($selectedCategoryId, $this->context->language->id))->name
];
}
}
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Podstawowe dane'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Kategoria hurtowni:'),
'name' => 'path',
'size' => 50,
'disabled' => true,
),
array(
'type' => 'text',
'label' => $this->l('Wzorzec nazwy produktu:'),
'desc' => $this->l('Wzorzec nazwy produktu może zawierać dowolne znaki alfanumeryczne oraz zmienne:').
'<br />'.
' - <b>{%name%}</b> - '.$this->l('która zostanie zastąpiona nazwą produktu').
'<br />'.
' - <b>{%reference%}</b> - '.$this->l('która zostanie zastąpiona kodem referencyjnym').
'<br />'.
' - <b>{%manufacturer%}</b> - '.$this->l('która zostanie zastąpiona nazwą producenta').
'<br />'.
' - <b>[%feature%]</b> - '.$this->l('która zostanie zastapiona wartością podanej cechy, np. [%Materiał%]'),
'name' => 'title_pattern',
'size' => 50
),
array(
'type' => $this->bootstrap ? 'switch' : 'radio',
'label' => $this->l('Import danych:'),
'name' => 'import',
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'on',
'value' => 1,
'label' => $this->l('Tak')
),
array(
'id' => 'off',
'value' => 0,
'label' => $this->l('Nie')
)
)
),
array(
'type' => 'select',
'label' => $this->l('Rodzaj narzutu:'),
'name' => 'markup_type',
'required' => true,
'class' => 'fixed-width-xxl',
'options' => array(
'query' => array(
array('id_markup' => XImportCategory::MARKUP_PERCENT, 'name' => $this->l('procent')),
array('id_markup' => XImportCategory::MARKUP_AMOUNT, 'name' => $this->l('kwota'))
),
'name' => 'name',
'id' => 'id_markup',
)
),
array(
'type' => 'text',
'label' => $this->l('Narzut:'),
'name' => 'markup',
'class' => 'fixed-width-md x-cast x-cast-float',
'desc' => $this->l('Narzut do ceny brutto')
),
array(
'type' => 'categories',
'label' => $this->l('Kategorie w sklepie:'),
'name' => 'id_additional_category',
'required' => true,
'tree' => array(
'id' => 'categories-tree',
'root_category' => $root_category['id_category'],
'use_search' => true,
'use_checkbox' => true,
'use_radio' => false,
'selected_categories' => $selectedCategoriesIds,
),
'values' => array(
'trads' => array(
'Root' => $root_category,
'selected' => $this->l('Selected'),
'Collapse All' => $this->l('Collapse All'),
'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All'),
'Expand All' => $this->l('Expand All'),
'search' => $this->l('search'),
),
'selected_cat' => $selectedCategoriesIds,
'disabled_categories' => array(),
'input_name' => 'id_additional_category[]',
'use_checkbox' => true,
'use_radio' => false,
'use_search' => true,
'top_category' => Category::getTopCategory(),
'use_context' => true,
)
),
array(
'type' => 'select',
'label' => $this->l('Kategoria główna:'),
'name' => 'id_category',
'required' => true,
'class' => 'fixed-width-xxl',
'options' => array(
'query' => $selectedCategories,
'name' => 'name',
'id' => 'id_category',
)
),
),
'submit' => array(
'name' => 'save',
'title' => $this->l('Zapisz'),
'class' => 'button btn btn-default pull-right'
)
);
return parent::renderForm();
}
public function initPageHeaderToolbar()
{
// hack toolbar
unset($this->toolbar_btn['new']);
$this->toolbar_btn['back'] = array(
'href' => '',
'desc' => ''
);
if (empty($this->display)) {
$this->toolbar_btn['categories_download'] =
$this->page_header_toolbar_btn['categories_download'] = array(
'href' => '#',
'desc' => $this->l('Pobierz kategorie z hurtowni'),
'icon' => 'process-icon-download',
'class' => 'x-categories-download'
);
$this->toolbar_btn['categories_import'] =
$this->page_header_toolbar_btn['categories_import'] = array(
'href' => '#',
'desc' => $this->l('Importuj kategorie do sklepu'),
'icon' => 'process-icon-download',
'class' => 'x-categories-import'
);
}
if (version_compare(_PS_VERSION_, '1.6.0.0', '>')) {
unset(
$this->toolbar_btn['categories_download'],
$this->toolbar_btn['categories_import']
);
}
else {
unset($this->toolbar_btn['back']);
}
if (method_exists(get_parent_class($this), 'initPageHeaderToolbar')) {
parent::initPageHeaderToolbar();
}
}
public function initToolbar()
{
parent::initToolbar();
$this->initPageHeaderToolbar();
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
if (version_compare(_PS_VERSION_, '1.6', '<') && !$this->display) {
$this->addJS(_PS_JS_DIR_ . 'admin-categories-tree.js');
$this->addJS(_PS_JS_DIR_ . 'jquery/plugins/treeview-categories/jquery.treeview-categories.js');
$this->addJS(_PS_JS_DIR_ . 'jquery/plugins/treeview-categories/jquery.treeview-categories.async.js');
$this->addJS(_PS_JS_DIR_ . 'jquery/plugins/treeview-categories/jquery.treeview-categories.edit.js');
$this->addjQueryPlugin('autocomplete');
$this->addCSS(_PS_JS_DIR_ . 'jquery/plugins/treeview-categories/jquery.treeview-categories.css');
}
else if (version_compare(_PS_VERSION_, '1.7', '<')) {
$this->addJS(PS_ADMIN_DIR . '/themes/default/js/tree.js');
$this->addJS(PS_ADMIN_DIR . '/themes/default/js/vendor/typeahead.min.js');
}
$this->addJS($this->module->getPathUri() . 'views/js/x13importCategories.js');
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
$this->_select .= 'l.`name` AS `name`, a.`markup_type`';
$this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` AS `l` ON (l.`id_category` = a.`id_category` AND l.`id_lang` = ' . (int)$this->context->language->id . ')';
$this->_orderBy = 'path';
$this->_group .= 'GROUP BY a.`id_ximport_category`';
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
}
public function pathCallback($path)
{
return str_replace('###', ' / ', $path);
}
public function processUpdate()
{
/** @var XImportCategory $object */
$object = parent::processUpdate();
if (Tools::isSubmit('submitAdd' . $this->table) && Validate::isLoadedObject($object)) {
$object->addAdditionalCategory(Tools::getValue('id_additional_category', []));
$object->id_category = (int)Tools::getValue('id_category');
return $object->save();
}
return $object;
}
protected function processBulkImport()
{
if (is_array($this->boxes) && !empty($this->boxes))
{
$result = true;
foreach ($this->boxes as $id)
{
$class = new $this->className($id);
$class->import = 1;
$class->save();
}
$this->redirect_after = self::$currentIndex.'&conf=29&token='.$this->token;
}
else
$this->errors[] = Tools::displayError('Musisz wybrać przynajmniej jeden element do zmiany.');
if (isset($result))
return $result;
else
return false;
}
protected function processBulkNoimport()
{
if (is_array($this->boxes) && !empty($this->boxes))
{
$result = true;
foreach ($this->boxes as $id)
{
$class = new $this->className($id);
$class->import = 0;
$class->save();
}
$this->redirect_after = self::$currentIndex.'&conf=29&token='.$this->token;
}
else
$this->errors[] = Tools::displayError('Musisz wybrać przynajmniej jeden element do zmiany.');
if (isset($result))
return $result;
else
return false;
}
protected function processBulkMarkup()
{
if (is_array($this->boxes) && !empty($this->boxes)) {
$result = true;
foreach ($this->boxes as $id) {
$class = new $this->className((int)$id);
$class->markup = (float)Tools::getValue('bulk_markup', 0);
$class->markup_type = Tools::getValue('bulk_markup_type', XImportCategory::MARKUP_PERCENT);
$class->save();
}
$this->redirect_after = self::$currentIndex.'&conf=36&token='.$this->token;
}
else
$this->errors[] = Tools::displayError('Musisz wybrać przynajmniej jeden element do zmiany.');
if (isset($result)) {
return $result;
}
else {
return false;
}
}
protected function processBulkTittlePattern()
{
if (is_array($this->boxes) && !empty($this->boxes)) {
$result = true;
foreach ($this->boxes as $id) {
$class = new $this->className((int)$id);
$class->title_pattern = Tools::getValue('bulk_title_pattern', '');
$class->save();
}
$this->redirect_after = self::$currentIndex.'&conf=38&token='.$this->token;
}
else
$this->errors[] = Tools::displayError('Musisz wybrać przynajmniej jeden element do zmiany.');
if (isset($result)) {
return $result;
}
else {
return false;
}
}
public function ajaxProcessCategoriesDownload()
{
$wholesalerName = Tools::getValue('wholesaler');
$wholesalerClassName = XImportWholesalers::getWholesalerClassName($wholesalerName);
require_once (X13_IMPORT_WHOLESALERS_DIR . $wholesalerName . '.php');
try {
/** @var XImportWholesalers $wholesaler */
$wholesaler = new $wholesalerClassName();
$wholesaler->importCategories();
}
catch (Exception $exception) {
die(json_encode([
'status' => false,
'message' => $exception->getMessage()
]));
}
die(json_encode([
'status' => true
]));
}
public function ajaxProcessCategoriesImportForm()
{
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$categoryTree = (new Helper())->renderCategoryTree(null, [], 'categoriesAssigned', true, true, false, true);
}
else {
$categoryTree = (new HelperTreeCategories('categoriesAssigned', $this->l('Wybierz kategorie sklepu do przypisania')))
->setInputName('categoriesAssigned')
->setRootCategory(Category::getRootCategory()->id)
->setUseSearch(true)
->setUseCheckBox(false)
->render();
}
$tpl = $this->context->smarty->createTemplate($this->module->getLocalPath() . 'views/templates/admin/' . $this->tpl_folder . 'categories_import_form.tpl');
$tpl->assign('categoryTree', $categoryTree);
die(json_encode([
'form' => $tpl->fetch()
]));
}
public function ajaxProcessCategoriesImportCount()
{
die(json_encode([
'count' => XImportCategory::countCategoriesToImport()
]));
}
public function ajaxProcessCategoriesImport()
{
$categories = XImportCategory::getCategoriesToImport((int)Tools::getValue('limit'));
if (empty($categories)) {
die(json_encode([
'status' => true,
'finish' => true
]));
}
XImportCategory::importCategories($categories, Category::getRootCategory());
die(json_encode([
'status' => true,
'finish' => false
]));
}
public function ajaxProcessCategoriesImportSelected()
{
switch ((int)Tools::getValue('categoriesImportMode')) {
case XImportCategory::MODE_IMPORT_TREE:
case XImportCategory::MODE_IMPORT_LAST_CHILD:
XImportCategory::importCategories(
Tools::getValue('categoriesToAssign'),
new Category((int)Tools::getValue('categoriesAssigned')[0]),
(int)Tools::getValue('categoriesImportMode'),
(int)Tools::getValue('categoriesOverwrite')
);
break;
case XImportCategory::MODE_ASSIGN:
foreach (Tools::getValue('categoriesToAssign') as $categoryId) {
$xCategory = new XImportCategory($categoryId);
// do not overwrite assigned categories
if (!Tools::getValue('categoriesOverwrite') && $xCategory->id_category) {
continue;
}
$xCategory->addAdditionalCategory(Tools::getValue('categoriesAssigned'));
$xCategory->id_category = (int)Tools::getValue('categoriesImportDefault');
$xCategory->save();
}
break;
}
die(json_encode([
'status' => true
]));
}
public function ajaxProcessCategoriesRegenerateTree()
{
Category::regenerateEntireNtree();
die(json_encode([
'status' => true
]));
}
public function ajaxProcessUpdateMarkup()
{
$category = new XImportCategory(Tools::getValue('id'));
$category->markup = Tools::getValue('markup');
$category->markup_type = Tools::getValue('markupType');
$category->save();
die(json_encode(array(
'confirmations' => 'Narzut został pomyślnie zapisany.',
'markup' => $category->markup,
'markupType' => $category->markup_type
)));
}
public function ajaxProcessUpdateImport()
{
$category = new XImportCategory(Tools::getValue('id'));
$category->import = !$category->import;
$category->save();
die(json_encode(array(
'confirmations' => 'Zmiany zostały pomyślnie zapisane.'
)));
}
}

View File

@@ -0,0 +1,563 @@
<?php
require_once (dirname(__FILE__) . '/../../x13import.php');
use x13import\Component\ProcessLock;
class AdminXImportConfigurationController extends XImportController
{
public function __construct()
{
$this->table = 'ximport_configuration';
$this->identifier = 'id_ximport_configuration';
$this->className = 'XImportConfiguration';
parent::__construct();
$this->tpl_folder = 'x_import_configuration/';
$this->tpl_option_vars['has_color_field'] = false;
$use_token = XImportConfiguration::get('USE_TOKEN');
if ($use_token && !XImportConfiguration::get('TOKEN')) {
XImportConfiguration::updateValue('TOKEN', Tools::passwdGen());
}
$token = '?token=' . XImportConfiguration::get('TOKEN');
$cronLastUnLock = ProcessLock::getLastUnlock('cron');
$updateLastUnLock = ProcessLock::getLastUnlock('update');
$this->fields_options = array(
'urls' => array(
'title' => $this->l('Adresy skryptów'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'URL_CRON' => array(
'title' => $this->l('Adres pliku CRON'),
'type' => 'readonly',
'size' => 75,
'readonly' => trim((new Shop((int)Configuration::get('PS_SHOP_DEFAULT')))->getBaseURL(Configuration::get('PS_SSL_ENABLED'), false), '/') . $this->module->getPathUri() . 'cron.php' . ($use_token ? $token : ''),
'hint' => $this->l('Pobiera najnowsze pliki z importowanych hurtowni i aktualizuje produkty.'),
'desc' => $this->l('Wywołuj co 2 godziny w każdej 23 minucie') . '<br>' .
($cronLastUnLock ? $this->l('Ostatnie uruchomienie') . ': ' . $cronLastUnLock->format('Y-m-d H:i') : '')
),
'URL_UPDATE' => array(
'title' => $this->l('Adres pliku UPDATE'),
'type' => 'readonly',
'size' => 75,
'readonly' => trim((new Shop((int)Configuration::get('PS_SHOP_DEFAULT')))->getBaseURL(Configuration::get('PS_SSL_ENABLED'), false), '/') . $this->module->getPathUri() . 'update.php' . ($use_token ? $token : ''),
'hint' => $this->l('Dodaje nowe produkty i zdjęcia.'),
'desc' => $this->l('Wywołuj co 15 minut') . '<br>' .
($updateLastUnLock ? $this->l('Ostatnie uruchomienie') . ': ' . $updateLastUnLock->format('Y-m-d H:i') : '')
),
'USE_TOKEN' => array(
'title' => $this->l('Używaj tokenu bezpieczeństwa'),
'type' => 'bool'
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
),
'general' => array(
'title' => $this->l('Ustawienia podstawowe'),
'image' => '../img/t/AdminPreferences.gif',
'description' => ' <strong>'.$this->l('Nowe produkty').'</strong> '.
$this->l('zawsze mają uzupełnione wszystkie dostępne parametry, bez względu na ustawienie opcji').' <strong>'.$this->l('Aktualizuj ...').'</strong><br/><br/> '.$this->l('Wszystkie poniższe opcje które zaczynają się od').' <strong>'.$this->l('Aktualizuj ...').'</strong> '. $this->l('zadziałają') .' <strong>'.$this->l('tylko').'</strong> '.$this->l('na już').' <strong>'.$this->l('zaimportowane').'</strong> '.$this->l('produkty.').'<br/>'.
$this->l('Np. zmieniając opcję ').' <strong>'.$this->l('Aktualizuj nazwy ').'</strong> '. $this->l('na').' <strong>'.$this->l('TAK').'</strong> '. $this->l(', spowoduje zaktualizowanie nazwy już dodanych produktów (zostaną zmienione na takie jakie znajdują się w').' <strong>'.$this->l('XMLu').'</strong> '. $this->l(' - wraz z').' <strong>'.$this->l('wzorcem nazwy produktów').'</strong> '. $this->l('jeśli jest uzupełniony).').'<br/>'
,
'fields' => array(
'UPDATE_NAME' => array(
'title' => $this->l('Aktualizuj nazwy'),
'type' => 'bool'
),
'UPDATE_DESC' => array(
'title' => $this->l('Aktualizuj długie opisy'),
'type' => 'bool'
),
'UPDATE_DESC_SHORT' => array(
'title' => $this->l('Aktualizuj krótkie opisy'),
'type' => 'bool'
),
'UPDATE_LINK_REWRITE' => array(
'title' => $this->l('Aktualizuj przyjazny adres URL'),
'type' => 'bool',
'desc' => $this->l('Zalecamy nie używać tej opcji w większości przypadków') . '<br />' .
$this->l('Przy włączonej tej opcji po ręcznej zmianie przyjaznego adresu, moduł ustawi nowego adresu URL')
),
'UPDATE_META' => array(
'title' => $this->l('Aktualizuj sekcję meta'),
'type' => 'bool'
),
'UPDATE_TAGS' => array(
'title' => $this->l('Aktualizuj tagi'),
'type' => 'bool'
),
'UPDATE_IS_VIRTUAL' => array(
'title' => $this->l('Aktualizuj typ produktu'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje typ produktu (standardowy / wirtualny)')
),
'UPDATE_REFERENCE' => array(
'title' => $this->l('Aktualizuj kod referencyjny'),
'type' => 'bool'
),
'UPDATE_EAN13' => array(
'title' => $this->l('Aktualizuj EAN'),
'type' => 'bool'
),
'UPDATE_MPN' => array(
'title' => $this->l('Aktualizuj MPN'),
'type' => 'bool',
'desc' => (version_compare(_PS_VERSION_, '1.7.7', '<') ? $this->l('Opcja dostępna od PrestaShop 1.7.7') : ''),
'disabled' => version_compare(_PS_VERSION_, '1.7.7', '<')
),
'UPDATE_ISBN' => array(
'title' => $this->l('Aktualizuj ISBN'),
'type' => 'bool',
'desc' => (version_compare(_PS_VERSION_, '1.7.0', '<') ? $this->l('Opcja dostępna od PrestaShop 1.7') : ''),
'disabled' => version_compare(_PS_VERSION_, '1.7', '<')
),
'UPDATE_CONDITION' => array(
'title' => $this->l('Aktualizuj pole "stan"'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje stan produktu (nowy, uzywany, odświeżony)')
),
'UPDATE_ONLINE_ONLY' => array(
'title' => $this->l('Aktualizuj dostępność online'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje informacje o dostępności wyłącznie w sklepie internetowym')
),
'UPDATE_FEATURES' => array(
'title' => $this->l('Aktualizuj cechy'),
'type' => 'bool'
),
'UPDATE_ATTACHMENTS' => array(
'title' => $this->l('Aktualizuj załączniki'),
'type' => 'bool'
),
'UPDATE_MANUFACTURER' => array(
'title' => $this->l('Aktualizuj producentów'),
'type' => 'bool'
),
'UPDATE_SUPPLIER' => array(
'title' => $this->l('Aktualizuj dostawców'),
'type' => 'bool'
),
'UPDATE_CARRIERS' => array(
'title' => $this->l('Aktualizuj przewoźników'),
'type' => 'bool',
),
'UPDATE_WEIGHT' => array(
'title' => $this->l('Aktualizuj wagi'),
'type' => 'bool'
),
'UPDATE_DIMENSIONS' => array(
'title' => $this->l('Aktualizuj wymiary'),
'type' => 'bool',
),
'UPDATE_CATEGORY' => array(
'title' => $this->l('Aktualizuj powiązania w kategoriach'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje produkty w kategoriach, zalecamy wyłączenie tej opcji po jendorazowej zmianie kategorii')
),
'UPDATE_ATTRIBUTE_DEFAULT' => array(
'title' => $this->l('Domyślna kombinacja'),
'type' => 'select',
'identifier' => 'id_default_attribute',
'list' => array(
array('id_default_attribute' => '0', 'name' => $this->l('bez wpływu na cenę (najtańszy)')),
array('id_default_attribute' => '1', 'name' => $this->l('domyślnie wg. PrestaShop'))
)
),
'hr_general' => array(
'name' => 'hr',
'type' => 'hr'
),
'SAVE_DELETED_ATTRIBUTES' => array(
'title' => $this->l('Zachowaj nieistniejące kombinacje'),
'type' => 'bool',
'desc' => $this->l('Przy włączonej opcji wszystkie kombinacje, ktore nie istnieją już w hurtowni lub mają zerowy stan magazynowy zostaną zachowane') . '<br />' .
sprintf($this->l('Wyłaczenie tej opcji spowoduje usunięcie tych kombinacji %s(zalecane)%s'), '<b>', '</b>')
),
'ONLINE_ONLY' => array(
'title' => $this->l('Ustaw produkty jako dostępne tylko online'),
'type' => 'bool',
'desc' => $this->l('Ustawia dla wszystkich produktów dostępność tylko w sklepie internetowym (nie sprzedawany w sklepie stacjonarnym)')
),
'CATEGORY_PARENTS' => array(
'title' => $this->l('Dodawaj produkty do kategorii nadrzędnych'),
'type' => 'bool',
'desc' => $this->l('Dodaje produkty do wszystkich kategorii nadrzędnych od kategorii domyślnej')
),
'SKIP_EMPTY_DESCRIPTIONS' => array(
'title' => $this->l('Pomijaj produkty bez opisu'),
'type' => 'bool'
),
'TRIM_SUPPLIER_DOMAIN_EXTENSION' => array(
'title' => $this->l('Usuń rozszerzenie domeny z nazwy dostawcy'),
'desc' => $this->l('Usuwa z nazwy rozszerzenia: .pl, .com, .info, .shop, itp...') . '<br />' .
$this->l('Nie dotyczy własnej nazwy dostawcy (opcja zaawansowana)'),
'type' => 'bool'
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
),
'stock' => array(
'title' => $this->l('Ustawienia ilości i dostępności'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'UPDATE_QUANTITY' => array(
'title' => $this->l('Aktualizuj stany magazynowe'),
'type' => 'bool'
),
'UPDATE_MINIMAL_QUANTITY' => array(
'title' => $this->l('Aktualizuj minimalną ilość sprzedaży'),
'type' => 'bool'
),
'UPDATE_AVAILABLE_DATE' => array(
'title' => $this->l('Aktualizuj datę dostępności'),
'type' => 'bool'
),
'UPDATE_AVAILABLE_TEXT' => array(
'title' => $this->l('Aktualizuj etykiety dostępności'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje etykiety dostepności (Etykieta, gdy w magazynie / Etykieta, gdy niedostępny (a ponowne zamówienie dozwolone))')
),
'UPDATE_DELIVERY_LABEL_TEXT' => array(
'title' => $this->l('Aktualizuj czas dostawy'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje czas dostawy (produktów dostępnych w magazynie / wyprzedanych produktów z możliwością rezerwacji)') .
(version_compare(_PS_VERSION_, '1.7.3', '<') ? '<br />' . $this->l('Opcja dostępna od PrestaShop 1.7.3') : ''),
'disabled' => version_compare(_PS_VERSION_, '1.7.3', '<'),
),
'UPDATE_REDIRECT_NOT_AVAILABLE' => array(
'title' => $this->l('Aktualizuj przekierowania niedostępnych produktów'),
'type' => 'bool',
'disabled' => version_compare(_PS_VERSION_, '1.7.1', '<')
),
'hr_stock1' => array(
'name' => 'hr_stock1',
'type' => 'hr'
),
'IMPORT_REDIRECT_NOT_AVAILABLE' => array(
'title' => $this->l('Przekieruj niedostępne produkty'),
'type' => 'select',
'identifier' => 'redirect_type',
'list' => array(
array('redirect_type' => '404', 'name' => $this->l('brak przekierowania (404)')),
array('redirect_type' => '301-category', 'name' => $this->l('do kategorii głównej, przekierowanie permanentne (301)')),
array('redirect_type' => '302-category', 'name' => $this->l('do kategorii głównej, przekierowanie tymczasowe (302)'))
),
'disabled' => version_compare(_PS_VERSION_, '1.7.1', '<')
),
'IMPORT_UNAVAILABLE' => array(
'title' => $this->l('Importuj produkty niedostępne'),
'type' => 'bool'
),
'MOD_ADVANCED_STOCK_NEW' => array(
'title' => $this->l('Zaawansowane ustawienia dostępności podczas importu'),
'desc' => '<b>' . $this->l('Dotyczy nowo dodawanych produktów niedostępnych') . '</b><br />' .
$this->l('Poniższe opcje mogą być nadpisane przez "Ustawienina zaawansowane hurtowni"') . '<br />' .
$this->l('Domyślnie wyłącza wszystko'),
'type' => 'bool',
'disabled' => !(bool)XImportConfiguration::get('IMPORT_UNAVAILABLE')
),
'MOD_ADVANCED_STOCK_NEW_ACTIVE' => array(
'title' => $this->l('Aktywność'),
'type' => 'select',
'identifier' => 'id_new_active',
'list' => array(
array('id_new_active' => 0, 'name' => $this->l('wyłącz')),
array('id_new_active' => 1, 'name' => $this->l('włącz'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_NEW')
),
'MOD_ADVANCED_STOCK_NEW_VIS' => array(
'title' => $this->l('Widoczność'),
'type' => 'select',
'identifier' => 'id_new_vis',
'list' => array(
array('id_new_vis' => 'none', 'name' => $this->l('ukryj')),
array('id_new_vis' => 'catalog', 'name' => $this->l('tylko katalog')),
array('id_new_vis' => 'search', 'name' => $this->l('tylko wyszukiwanie')),
array('id_new_vis' => 'both', 'name' => $this->l('wszędzie'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_NEW')
),
'MOD_ADVANCED_STOCK_NEW_OOS' => array(
'title' => $this->l('Preferencje dostępności'),
'type' => 'select',
'identifier' => 'id_new_oos',
'list' => array(
array('id_new_oos' => 0, 'name' => $this->l('nie pozwól zamówić')),
array('id_new_oos' => 1, 'name' => $this->l('pozwól zamówić')),
array('id_new_oos' => 2, 'name' => $this->l('użyj domyślnego zachowania'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_NEW')
),
'MOD_ADVANCED_STOCK_NEW_AFO' => array(
'title' => $this->l('Sprzedaż'),
'type' => 'select',
'identifier' => 'id_new_afo',
'list' => array(
array('id_new_afo' => 0, 'name' => $this->l('wyłącz (tryb katalogu)')),
array('id_new_afo' => 1, 'name' => $this->l('włącz'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_NEW')
),
'hr_stock2' => array(
'name' => 'hr_stock2',
'type' => 'hr'
),
'MOD_ADVANCED_STOCK_UPD' => array(
'title' => $this->l('Zaawansowane ustawienia dostępności podczas aktualizacji'),
'desc' => '<b>' . $this->l('Dotyczy aktualizacji produktów niedostępnych, oraz obsługi produktów usuniętych z hurtowni') . '</b><br />' .
'<u>' . $this->l('Dotyczy tylko głównego produktu, dla kombinacji sprawdź opcję: "Zachowaj nieistniejące atrybuty"') . '</u><br />' .
$this->l('Poniższe opcje mogą być nadpisane przez "Ustawienina zaawansowane hurtowni"') . '<br />' .
$this->l('Domyślnie wyłącza wszystko i zeruje ilości'),
'type' => 'bool'
),
'MOD_ADVANCED_STOCK_UPD_ACTIVE' => array(
'title' => $this->l('Aktywność'),
'type' => 'select',
'identifier' => 'id_upd_active',
'list' => array(
array('id_upd_active' => 0, 'name' => $this->l('wyłącz')),
array('id_upd_active' => 1, 'name' => $this->l('włącz')),
array('id_upd_active' => 2, 'name' => $this->l('nic nie rób'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_UPD')
),
'MOD_ADVANCED_STOCK_UPD_VIS' => array(
'title' => $this->l('Widoczność'),
'type' => 'select',
'identifier' => 'id_upd_vis',
'list' => array(
array('id_upd_vis' => 'none', 'name' => $this->l('ukryj')),
array('id_upd_vis' => 'catalog', 'name' => $this->l('tylko katalog')),
array('id_upd_vis' => 'search', 'name' => $this->l('tylko wyszukiwanie')),
array('id_upd_vis' => 'both', 'name' => $this->l('wszędzie')),
array('id_upd_vis' => 'nothing', 'name' => $this->l('nic nie rób'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_UPD')
),
'MOD_ADVANCED_STOCK_UPD_OOS' => array(
'title' => $this->l('Preferencje dostępności'),
'type' => 'select',
'identifier' => 'id_upd_oos',
'list' => array(
array('id_upd_oos' => 0, 'name' => $this->l('nie pozwól zamówić')),
array('id_upd_oos' => 1, 'name' => $this->l('pozwól zamówić')),
array('id_upd_oos' => 2, 'name' => $this->l('użyj domyślnego zachowania')),
array('id_upd_oos' => 4, 'name' => $this->l('nic nie rób'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_UPD')
),
'MOD_ADVANCED_STOCK_UPD_AFO' => array(
'title' => $this->l('Sprzedaż'),
'type' => 'select',
'identifier' => 'id_upd_afo',
'list' => array(
array('id_upd_afo' => 0, 'name' => $this->l('wyłącz (tryb katalogu)')),
array('id_upd_afo' => 1, 'name' => $this->l('włącz')),
array('id_upd_afo' => 2, 'name' => $this->l('nic nie rób'))
),
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_UPD')
),
'MOD_ADVANCED_STOCK_UPD_QTY_ZERO' => array(
'title' => $this->l('Zeruj ilość'),
'desc' => $this->l('Dotyczy wyłącznie produktów usuniętych z hurtowni'),
'type' => 'bool',
'disabled' => !(bool)XImportConfiguration::get('MOD_ADVANCED_STOCK_UPD')
),
),
'submit' => array(
'title' => $this->l('Zapisz')
)
),
'price' => array(
'title' => $this->l('Ustawienia cen'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'UPDATE_PRICE' => array(
'title' => $this->l('Aktualizuj ceny'),
'type' => 'bool'
),
'UPDATE_UNIT_PRICE' => array(
'title' => $this->l('Aktualizuj ceny jednostkowe'),
'type' => 'bool',
'desc' => $this->l('np. cena za kg')
),
'UPDATE_UNITY' => array(
'title' => $this->l('Aktualizuj jednostki ceny'),
'type' => 'bool',
),
'UPDATE_WHOLESALE_PRICE' => array(
'title' => $this->l('Aktualizuj ceny hurtowe'),
'type' => 'bool'
),
'UPDATE_TAX' => array(
'title' => $this->l('Aktualizuj podatek'),
'type' => 'bool'
),
'FORCE_TAX_ZERO' => array(
'title' => $this->l('Wymuszaj podatek 0%'),
'desc' => $this->l('Ustawia zawsze regułę podatkową 0%, cena produktu zostanie przeliczona').'<br/>'.
$this->l('Jeśli sprzedajesz produkty z VATem opcja powinna być wyłączona'),
'type' => 'bool'
),
'UPDATE_ADDITIONAL_SHIPPING_COST' => array(
'title' => $this->l('Aktualizuj dodatkowe koszty wysyłki'),
'type' => 'bool'
),
'UPDATE_ON_SALE' => array(
'title' => $this->l('Aktualizuj pole "wyprzedaż"'),
'type' => 'bool'
),
'UPDATE_SHOW_PRICE' => array(
'title' => $this->l('Aktualizuj widoczność ceny'),
'type' => 'bool',
'desc' => $this->l('Aktualizuje informacje, czy cena produktu ma być wyświetlana. Jeśli nie, produkt będzie wyświetlany w formie katalogu i nie będzie możliwy jego zakup')
),
'CLEAR_SPECIFIC_PRICE' => array(
'title' => $this->l('Czyść ceny specyficzne'),
'type' => 'bool',
'desc' => $this->l('Włączenie tej opcji usunie wszystkie ceny specyficzne (promocje) dodane do produktu')
),
'SKIP_PRICE_ZERO' => array(
'title' => $this->l('Pomijaj produkty z zerową ceną'),
'type' => 'bool',
'desc' => $this->l('Porównuje cenę brutto przed narzutem')
),
'UNACTIVE_PRICE_ZERO' => array(
'title' => $this->l('Wyłączaj produkty z zerową ceną'),
'type' => 'bool'
),
'PRICE_ROUND' => array(
'title' => $this->l('Zaokrąglanie cen z narzutem'),
'type' => 'select',
'identifier' => 'id_round',
'list' => array(
array('id_round' => '0', 'name' => $this->l('nie zaokrąglaj')),
array('id_round' => '1', 'name' => $this->l('zaokrąglaj w górę do 00gr')),
array('id_round' => '2', 'name' => $this->l('zaokrąglaj w górę do 99gr')),
array('id_round' => '7', 'name' => $this->l('zaokrąglaj w górę do 9zł i 00gr')),
array('id_round' => '10', 'name' => $this->l('zaokrąglaj w górę do pełnych dziesiątek')),
array('id_round' => '3', 'name' => $this->l('zaokrąglaj standardowo do 00gr')),
array('id_round' => '4', 'name' => $this->l('zaokrąglaj standardowo do 99gr')),
array('id_round' => '8', 'name' => $this->l('zaokrąglaj standardowo do 9zł i 00gr')),
array('id_round' => '11', 'name' => $this->l('zaokrąglaj standardowo do pełnych dziesiątek')),
array('id_round' => '5', 'name' => $this->l('zaokrąglaj w dół do 00gr')),
array('id_round' => '6', 'name' => $this->l('zaokrąglaj w dół do 99gr')),
array('id_round' => '9', 'name' => $this->l('zaokrąglaj w dół do 9zł i 00gr')),
array('id_round' => '12', 'name' => $this->l('zaokrąglaj w dół do pełnych dziesiątek'))
),
'desc' => $this->l('Przy zaokrąglaniu i równaniu do pełnych złotówek najniższa możliwa cena produktu to 1 PLN') . '<br>' .
$this->l('Przy zaokrąglaniu i równaniu do pełnych dziesiątek najniższa możliwa cena produktu to 10 PLN'),
),
'PRICE_MODIFY' => array(
'title' => $this->l('Modyfikuj cenę po zaokrągleniu'),
'desc' => $this->l('Dodaje/odejmuje podaną wartość od ceny wyliczonej po jej zaokrągleniu'),
'type' => 'text',
'class' => 'fixed-width-xxl x-cast x-cast-float',
'defaultValue' => '0.00'
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
),
'images' => array(
'title' => $this->l('Ustawienia zdjęć'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'UPDATE_IMAGES' => array(
'title' => $this->l('Aktualizuj zdjęcia'),
'type' => 'bool',
'desc' => $this->l('Dodaje nowe zdjęcia jeśli pojawią się w hurtorni dla już zaimportowanych produktów') . '<br />' .
$this->l('Nigdy nie usuwa wcześniej pobranych zdjęć, jak i nie aktualizuje zdjęc z tego samego adresu - linku')
),
'ALLOW_NO_IMAGES' => array(
'title' => $this->l('Importuj produkty bez zdjęć'),
'type' => 'bool'
),
'DISABLE_NO_IMAGES' => array(
'title' => $this->l('Wyłączaj produkty bez zdjęć'),
'type' => 'bool'
),
'MAX_IMAGE_SIZE' => array(
'title' => $this->l('Maksymalny rozmiar zdjęcia'),
'type' => 'text',
'class' => 'fixed-width-sm x-cast x-cast-int',
'size' => 10,
'defaultValue' => '0',
'suffix' => 'MB'
),
'MAX_IMAGE_PIXEL' => array(
'title' => $this->l('Maksymalny dłuższy bok zdjęcia'),
'type' => 'text',
'class' => 'fixed-width-sm x-cast x-cast-int',
'size' => 10,
'defaultValue' => '0',
'suffix' => 'px'
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
),
'adv_settings' => array(
'title' => $this->l('Ustawienia zaawansowane'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'CLEAR_CACHE' => array(
'title' => $this->l('Włącz czyszczenie cache po pomyślnym imporcie'),
'type' => 'bool',
'desc' => $this->l('Opcja spróbuje wyczyścić cache wszystkich modułów przypiętych do hookUpdateProduct'),
),
),
'submit' => array(
'title' => $this->l('Zapisz')
)
)
);
$this->tpl_option_vars['ionCubeLicenseInfo'] = $this->displayIonLicenseInfo();
}
public function renderOptions()
{
unset($this->toolbar_btn);
$this->display = 'options';
$this->initToolbar();
$helper = new HelperXImportOptions();
$this->setHelperDisplay($helper);
$helper->id = $this->id;
$helper->tpl_vars = $this->tpl_option_vars;
$options = $helper->generateOptions($this->fields_options);
return $options;
}
protected function processUpdateOptions()
{
$this->beforeUpdateOptions();
foreach ($this->fields_options as $category_data) {
if (!isset($category_data['fields'])) {
continue;
}
foreach ($category_data['fields'] as $key => $options) {
if ($options['type'] != 'hr') {
XImportConfiguration::updateValue($key, trim(Tools::getValue($key, '')));
}
}
}
Tools::redirectAdmin($this->context->link->getAdminLink('AdminXImportConfiguration') . '&conf=6');
}
}

View File

@@ -0,0 +1,336 @@
<?php
require_once (dirname(__FILE__) . '/../../x13import.php');
class AdminXImportExcludesController extends XImportController
{
public function __construct()
{
$this->table = 'ximport_product';
$this->identifier = 'id_ximport_product';
$this->className = 'XImportProduct';
$this->list_no_link = true;
parent::__construct();
$this->fields_options = array(
'general' => array(
'title' => $this->l('Wykluczenia import produktów'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'EXCLUDES_BY_REFERENCE' => array(
'title' => $this->l('Wyklucz po kodzie referencyjnym'),
'desc' => $this->l('Kody referencyjne podawaj w nowej linii'),
'type' => 'textarea',
'cols' => 10,
'rows' => 8,
'auto_value' => false,
'value' => $this->formatExcludesString('EXCLUDES_BY_REFERENCE')
),
'EXCLUDES_BY_EAN' => array(
'title' => $this->l('Wyklucz po kodzie EAN'),
'desc' => $this->l('Kody EAN podawaj w nowej linii'),
'type' => 'textarea',
'cols' => 10,
'rows' => 8,
'auto_value' => false,
'value' => $this->formatExcludesString('EXCLUDES_BY_EAN')
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
)
);
$this->fields_list = array(
'id_product' => array(
'title' => $this->l('ID'),
'align' => 'center',
'class' => 'fixed-width-xs',
'width' => 50,
'filter_key' => 'a!id_product',
'orderby' => true
),
'image' => array(
'title' => $this->l('Zdjęcie'),
'align' => 'center',
'image' => 'p',
'class' => 'fixed-width-sm',
'orderby' => false,
'filter' => false,
'search' => false
),
'name' => array(
'title' => $this->l('Nazwa produktu'),
'filter_key' => 'pl!name',
'orderby' => true
),
'reference' => array(
'title' => $this->l('Nr ref.'),
'class' => 'fixed-width-md',
'filter_key' => 'p!reference',
'orderby' => true
),
'category_name' => array(
'title' => $this->l('Kategoria'),
'class' => 'fixed-width-lg',
'filter_key' => 'cl!name',
'orderby' => true
),
'supplier_name' => array(
'title' => $this->l('Dostawca'),
'class' => 'fixed-width-lg',
'filter_key' => 's!name',
'orderby' => true
),
'price_netto' => array(
'title' => $this->l('Cena netto'),
'class' => 'fixed-width-md',
'search' => false,
'orderby' => false
),
'quantity' => array(
'title' => $this->l('Ilość'),
'type' => 'int',
'class' => 'fixed-width-sm',
'align' => 'center',
'width' => 80,
'filter_key' => 'sav!quantity',
'search' => true,
'orderby' => true
),
/*'active_shop' => array(
'title' => $this->l('Akt.'),
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'filter_key' => 'p!active',
'icon' => array(
'0' => array('class' => 'icon-remove', 'src' => 'disabled.gif', 'alt' => $this->l('Wyłączony w sklepie')),
'1' => array('class' => 'icon-check', 'src' => 'enabled.gif', 'alt' => $this->l('Włączony w sklepie'))
),
'search' => true,
'orderby' => true
),*/
'exclude' => array(
'title' => $this->l('Wyklucz aktualizację'),
'type' => 'bool',
'active' => 'exclude',
'class' => 'fixed-width-sm center word-break x-exclude',
'align' => 'center',
'width' => 80,
'search' => true,
'orderby' => false
),
'exclude_price' => array(
'title' => $this->l('Wyklucz aktualizację ceny'),
'type' => 'bool',
'active' => 'exclude_price',
'class' => 'fixed-width-md center word-break x-exclude-price',
'align' => 'center',
'width' => 100,
'search' => true,
'orderby' => false
)
);
$this->tpl_folder = 'x_import_excludes/';
}
public function initToolbar()
{
parent::initToolbar();
unset($this->toolbar_btn['new']);
// hack toolbar
$this->toolbar_btn['back'] = array(
'href' => '',
'desc' => ''
);
}
public function initProcess()
{
if (Tools::getIsset('submitBulkenableExcludeProductsximport_product')
|| Tools::getIsset('submitBulkdisableExcludeProductsximport_product')
|| Tools::getIsset('submitBulkenableExcludeProductsPricesximport_product')
|| Tools::getIsset('submitBulkdisableExcludeProductsPricesximport_product')
) {
if (!Tools::getIsset('ximport_productBox')) {
$this->errors[] = $this->l('Nie wybrano żadnego produktu.');
}
else {
$price = (Tools::getIsset('submitBulkenableExcludeProductsPricesximport_product')
|| Tools::getIsset('submitBulkdisableExcludeProductsPricesximport_product'));
$type = (Tools::getIsset('submitBulkenableExcludeProductsximport_product')
|| Tools::getIsset('submitBulkenableExcludeProductsPricesximport_product') ? XImportProduct::EXCLUDE_ENABLE : XImportProduct::EXCLUDE_DISABLE);
foreach (Tools::getValue('ximport_productBox') as $ids_box) {
XImportProduct::setExclude((int)$ids_box, $price, $type);
}
// redirect to avoid conflicts
Tools::redirectAdmin($this->context->link->getAdminLink('AdminXImportExcludes') . '&conf=4');
}
}
parent::initProcess();
}
public function renderList()
{
$this->addRowAction('xSpan');
$this->bulk_actions = array(
'enableExcludeProducts' => array(
'text' => $this->l('Wł. wykluczenie aktualizacji')
),
'enableExcludeProductsPrices' => array(
'text' => $this->l('Wł. wykluczenie aktualizacji ceny')
),
'divider1' => array(
'text' => 'divider'
),
'disableExcludeProducts' => array(
'text' => $this->l('Wył. wykluczenie aktualizacji')
),
'disableExcludeProductsPrices' => array(
'text' => $this->l('Wył. wykluczenie aktualizacji ceny')
)
);
return parent::renderList();
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
$id_shop = (Shop::isFeatureActive() ? (int)$this->context->shop->id : 'p.id_shop_default');
$id_lang = $this->context->language->id;
$id_lang_shop = $this->context->language->id;
if (version_compare(_PS_VERSION_, '1.6.1.0', '<'))
{
$select_image = 'MAX(image_shop.`id_image`) AS id_image';
$join_image = '
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = ' . $id_shop . ')';
}
else {
$select_image = 'image_shop.`id_image` AS `id_image`';
$join_image = '
LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = ' . $id_shop . ')
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`)';
}
$this->_select = 'pl.`name`, p.`reference`, cl.`name` as `category_name`, sav.`quantity`, p.`active` as `active_shop`,
s.`name` as `supplier_name`, ' . $select_image;
$this->_join .= '
JOIN `'._DB_PREFIX_.'product` p ON (a.`id_product` = p.`id_product`)
JOIN `'._DB_PREFIX_.'product_shop` ps ON (a.`id_product` = ps.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (a.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int)$id_lang . ')
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND pl.`id_lang` = cl.`id_lang`)
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (p.`id_supplier` = s.`id_supplier`)
LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0' . StockAvailable::addSqlShopRestriction(null, null, 'sav') . ')'.
$join_image;
$this->_group .= 'GROUP BY p.`id_product`';
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
foreach ($this->_list as &$product)
{
// override box & input ID
$product['id'] = $product['id_ximport_product'] = $product['id_product'];
$product['price_netto'] = Tools::displayPrice($this->formatPrice((int)$product['id_product'], (int)$product['id_product_attribute'], false, false));
}
}
protected function processUpdateOptions()
{
$this->beforeUpdateOptions();
foreach (array_keys($this->fields_options['general']['fields']) as $field) {
$value = explode(';', str_replace(["\n", "\r", "\n\r", "\r\n", ","], ';', Tools::getValue($field, '')));
$value = array_values(array_filter(array_map('trim', $value)));
XImportConfiguration::updateValue($field, json_encode($value));
}
Tools::redirectAdmin($this->context->link->getAdminLink('AdminXImportExcludes') . '&conf=6');
}
public function displayXSpanLink($token = null, $id, $name = null)
{
$tpl = $this->context->smarty->createTemplate($this->module->getLocalPath() . 'views/templates/admin/' . $this->tpl_folder . 'helpers/list/action_xspan.tpl');
return $tpl->fetch();
}
public function ajaxProcessExcludeProducts()
{
XImportProduct::setExclude((int)Tools::getValue('id'));
die(json_encode(array(
'confirmations' => 'Zmiany zostały pomyślnie zapisane.'
)));
}
public function ajaxProcessExcludeProductsPrices()
{
XImportProduct::setExclude((int)Tools::getValue('id'), true);
die(json_encode(array(
'confirmations' => 'Zmiany zostały pomyślnie zapisane.'
)));
}
/**
* @param int $id_product
* @param int $id_product_attribute
* @param bool $use_tax
* @param bool $use_reduction
* @return float
*/
private function formatPrice($id_product, $id_product_attribute, $use_tax, $use_reduction = true)
{
$specific_price_output = null;
return Product::getPriceStatic(
$id_product,
$use_tax,
$id_product_attribute,
2, // decimals
null, // divisor
false, // only reduction
$use_reduction,
1, // quantity
false, // force associated tax - deprecated
null, // customer id
null, // cart id
null, // address id
$specific_price_output,
true, // eco tax
$use_reduction
);
}
/**
* @param string $field
* @return string
*/
private function formatExcludesString($field)
{
if ($value = XImportConfiguration::get($field)) {
$value = json_decode($value, true);
if (is_array($value)) {
return implode("\r", $value);
}
}
return '';
}
}

View File

@@ -0,0 +1,256 @@
<?php
require_once (dirname(__FILE__) . '/../../x13import.php');
class AdminXImportPricesController extends XImportController
{
private $wholesales = array();
public function __construct()
{
$this->table = 'ximport_price';
$this->identifier = 'id_ximport_price';
$this->className = 'XImportPrice';
parent::__construct();
$this->tpl_folder = 'x_import_prices/';
$this->tpl_option_vars['has_color_field'] = false;
foreach (XImportWholesalers::getWholesalers() as $wholesale) {
$this->wholesales[] = array(
'name' => $wholesale['name']
);
}
$wholesales = array();
foreach ($this->wholesales as $wholesale) {
$wholesales[$wholesale['name']] = $wholesale['name'];
}
$this->fields_options = array(
'general' => array(
'title' => $this->l('Ustawienia zakresów cenowych'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'MARKUP_SUM' => array(
'title' => $this->l('Sumuj narzut z zakresów cenowych'),
'type' => 'bool',
'desc' => $this->l('Przy włączonej opcji sumuje narzut ze wszystkich pasujących zakresów cenowych.') . '<br>' .
$this->l('Wyłączenie tej opcji spowoduje wybranie narzutu z najwęższego pasującego zakresu cenowego.')
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
)
);
$this->fields_list = array(
'wholesaler' => array(
'title' => $this->l('Hurtownia'),
'type' => 'select',
'list' => $wholesales,
'filter_key' => 'wholesaler'
),
'range_from' => array(
'title' => $this->l('Cena od'),
'class' => 'fixed-width-md'
),
'range_to' => array(
'title' => $this->l('Cena do'),
'class' => 'fixed-width-md'
),
'markup' => array(
'title' => $this->l('Wartość'),
'class' => 'fixed-width-md'
),
'override_category' => array(
'title' => $this->l('Nadpisuje narzut kategorii'),
'width' => 100,
'align' => 'center',
'type' => 'bool',
'icon' => array(
'0' => array('class' => 'icon-remove', 'src' => 'disabled.gif', 'alt' => $this->l('Nie')),
'1' => array('class' => 'icon-check', 'src' => 'enabled.gif', 'alt' => $this->l('Tak'))
),
'class' => 'fixed-width-sm'
)
);
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Usuń zaznaczone'),
'confirm' => $this->l('Czy chcesz usunąć zaznaczone zakresy?'),
'icon' => 'icon-trash'
)
);
}
public function viewAccess($disable = false)
{
if (empty($this->wholesales)) {
$this->errors[] = $this->l('Brak dodanych hurtowni');
}
if (!parent::viewAccess($disable) || empty($this->wholesales)) {
return false;
}
return true;
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function renderForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Zastosuj narzut dla wybranej hurtowni'),
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Hurtownia'),
'name' => 'wholesaler',
'class' => 'fixed-width-xxl',
'required' => true,
'options' => array(
'query' => $this->wholesales,
'id' => 'name',
'name' => 'name'
)
),
array(
'type' => 'text',
'label' => $this->l('Cena od'),
'suffix' => $this->context->currency->sign . ' ' . $this->l('brutto'),
'name' => 'range_from',
'size' => 12,
'class' => 'fixed-width-md x-cast x-cast-float',
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Cena do'),
'suffix' => $this->context->currency->sign . ' ' . $this->l('brutto'),
'name' => 'range_to',
'size' => 12,
'class' => 'fixed-width-md x-cast x-cast-float',
'required' => true,
),
array(
'type' => 'select',
'label' => $this->l('Rodzaj narzutu'),
'name' => 'type',
'class' => 'fixed-width-xxl',
'required' => true,
'options' => array(
'query' => array(
array('id' => XImportPrice::MARKUP_VALUE, 'name' => $this->l('Kwota')),
array('id' => XImportPrice::MARKUP_PERCENT, 'name' => $this->l('Procent'))
),
'id' => 'id',
'name' => 'name'
)
),
array(
'type' => 'text',
'label' => $this->l('Wartość'),
'desc' => $this->l('Wartość narzutu zostanie zastosowana od ceny brutto'),
'name' => 'markup',
'size' => 12,
'class' => 'fixed-width-md x-cast x-cast-float',
'required' => true,
),
array(
'type' => $this->bootstrap ? 'switch' : 'radio',
'label' => $this->l('Nadpisuje narzut kategorii'),
'desc' => $this->l('Wyłączenie tej opcji spowoduje zsumowanie narzutu hutrowni oraz kategorii'),
'name' => 'override_category',
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'override_category_on',
'value' => 1,
'label' => $this->l('Tak')
),
array(
'id' => 'override_category_off',
'value' => 0,
'label' => $this->l('Nie')
)
)
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
);
return parent::renderForm();
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
foreach ($this->_list as &$list)
{
$list['markup'] = $list['markup'] . ' ' . ($list['type'] == XImportPrice::MARKUP_VALUE ? $this->context->currency->sign : '%');
}
}
public function getFieldsValue($obj)
{
$this->fields_value = parent::getFieldsValue($obj);
if (!Validate::isLoadedObject($obj)) {
$this->fields_value['range_from'] =
$this->fields_value['range_to'] =
$this->fields_value['markup'] = '0.00';
}
return $this->fields_value;
}
public function renderOptions()
{
unset($this->toolbar_btn);
$this->display = 'options';
$this->initToolbar();
$helper = new HelperXImportOptions();
$this->setHelperDisplay($helper);
$helper->id = $this->id;
$helper->tpl_vars = $this->tpl_option_vars;
$options = $helper->generateOptions($this->fields_options);
return $options;
}
protected function processUpdateOptions()
{
$this->beforeUpdateOptions();
foreach ($this->fields_options as $category_data)
{
if (!isset($category_data['fields'])) {
continue;
}
foreach ($category_data['fields'] as $key => $options) {
XImportConfiguration::updateValue($key, Tools::getValue($key, ''));
}
}
$this->confirmations[] = $this->_conf[6];
}
}

View File

@@ -0,0 +1,282 @@
<?php
require_once (dirname(__FILE__) . '/../../x13import.php');
use x13import\Component\Logger;
use x13import\Component\MaintenanceMode;
use x13import\Wholesaler\WholesalerConfiguration;
use x13import\Wholesaler\WholesalerOptions;
use x13import\Wholesaler\WholesalerUploader;
class AdminXImportWholesalersController extends XImportController
{
public function __construct()
{
$this->table = 'ximport_configuration';
$this->identifier = 'id_ximport_configuration';
$this->className = 'XImportConfiguration';
parent::__construct();
$this->tpl_folder = 'x_import_wholesalers/';
$this->fields_options = array(
'general' => array(
'title' => $this->l('Hurtownie'),
'image' => '../img/t/AdminPreferences.gif',
'fields' => array(
'empty' => array(
'type' => 'empty'
)
),
'submit' => array(
'title' => $this->l('Zapisz')
)
)
);
$wholesalers = [];
foreach (XImportWholesalers::getWholesalers() as $wholesaler) {
$wholesalerOptions = new WholesalerOptions(new WholesalerConfiguration($wholesaler['name']));
$wholesalers[] = array_merge($wholesaler, [
'baseOptions' => $wholesalerOptions->getBaseOptions(),
'availabilityOptions' => $wholesalerOptions->getAvailabilityOptions(),
'descriptionOptions' => $wholesalerOptions->getDescriptionOptions(),
'additionalOptions' => $wholesalerOptions->getAdditionalOptions(),
'importRestrictionOptions' => $wholesalerOptions->getImportRestrictionOptions()
]);
}
$iso = $this->context->language->iso_code;
$this->tpl_option_vars['iso'] = file_exists(_PS_CORE_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en';
$this->tpl_option_vars['path_css'] = _THEME_CSS_DIR_;
$this->tpl_option_vars['ad'] = __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_);
$this->tpl_option_vars['tinymce'] = true;
$this->tpl_option_vars['wholesalers'] = $wholesalers;
$this->tpl_option_vars['wholesalers_link'] = $this->context->link->getAdminLink('AdminXImportWholesalers');
$this->tpl_option_vars['tab_wholesaler'] = Tools::getValue('tabWholesaler', '');
$this->tpl_option_vars['tab_wholesaler_option'] = Tools::getValue('tabWholesalerOption', '');
$this->tpl_option_vars['has_color_field'] = false;
$this->tpl_option_vars['maintenance_mode'] = (MaintenanceMode::isShopDev()
|| MaintenanceMode::isModuleDev()
|| MaintenanceMode::isModuleDevEmployee($this->context->employee));
}
public function renderOptions()
{
if (Tools::getIsset('wholesalerUploadSuccess')) {
if (count(explode(',', Tools::getValue('wholesalerUploadName'))) == 1) {
$uploadWholesalersMessage = 'Dodano hurtownię %s, przejdź do jej konfiguracji';
} else {
$uploadWholesalersMessage = 'Dodano hurtownie %s, przejdź do ich konfiguracji';
}
$this->confirmations[] = sprintf($this->l($uploadWholesalersMessage), '<strong>' . str_replace(',', ', ', Tools::getValue('wholesalerUploadName')) . '</strong>');
}
unset($this->toolbar_btn);
$this->display = 'options';
$this->initToolbar();
$helper = new HelperXImportOptions();
$this->setHelperDisplay($helper);
$helper->id = $this->id;
$helper->tpl_vars = $this->tpl_option_vars;
return $helper->generateOptions($this->fields_options);
}
public function initPageHeaderToolbar()
{
$this->toolbar_btn['products_off'] =
$this->page_header_toolbar_btn['products_off'] = array(
'href' => self::$currentIndex.'&products_off&token='.$this->token,
'desc' => $this->l('Wyłącz produkty ze wszystkich hurtowni'),
'icon' => 'process-icon-off',
'class' => 'x-products-off'
);
$this->toolbar_btn['products_delete'] =
$this->page_header_toolbar_btn['products_delete'] = array(
'href' => self::$currentIndex.'&products_delete&token='.$this->token,
'desc' => $this->l('Usuń produkty ze wszystkich hurtowni'),
'icon' => 'process-icon-delete',
'class' => 'x-products-delete'
);
if (version_compare(_PS_VERSION_, '1.6.0.0', '>')) {
unset(
$this->toolbar_btn['products_delete'],
$this->toolbar_btn['products_off']
);
}
else {
unset($this->toolbar_btn['back']);
}
if (method_exists(get_parent_class($this), 'initPageHeaderToolbar')) {
parent::initPageHeaderToolbar();
}
}
public function initToolbar()
{
parent::initToolbar();
$this->initPageHeaderToolbar();
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJS(_PS_JS_DIR_ . 'tiny_mce/tiny_mce.js');
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$this->addJqueryUI('ui.tabs');
}
if (version_compare(_PS_VERSION_, '1.6.0.11', '<')) {
$this->addJS(_PS_JS_DIR_ . 'tinymce.inc.js');
} else {
$this->addJS(_PS_JS_DIR_ . 'admin/tinymce.inc.js');
}
$this->addJS($this->module->getPathUri() . 'views/js/x13importWholesalers.js');
}
public function postProcess()
{
if (Tools::isSubmit('submitAddNewWholesaler')) {
if (isset($_FILES['wholesaler_file']) && !empty($_FILES['wholesaler_file']['tmp_name'])) {
$uploader = new WholesalerUploader($_FILES['wholesaler_file']);
if ((int)$_FILES['wholesaler_file']['error'] !== UPLOAD_ERR_OK) {
$this->errors[] = $this->l('Wystąpił błąd podczas przesyłania pliku.');
return false;
}
if (!$uploader->validateUploadedFile()) {
$this->errors[] = $this->l('Przesłano nieprawidłowy typ pliku.');
return false;
}
try {
$wholesalers = $uploader->moveUploadedFile();
if (!empty($wholesalers)) {
Tools::redirectAdmin($this->context->link->getAdminLink('AdminXImportWholesalers')
. '&wholesalerUploadSuccess&wholesalerUploadName=' . implode(',', $wholesalers)
. (count($wholesalers) == 1 ? '&tabWholesaler=' . $wholesalers[0] : ''));
}
$this->errors[] = $this->l('Przesłany plik lub archiwum hurtowni jest nieprawidłowe.');
}
catch (Exception $exception) {
$this->errors[] = $exception->getMessage();
}
}
else {
$this->errors[] = $this->l('Nie wybrano pliku do przesłania.');
}
}
return parent::postProcess();
}
protected function processUpdateOptions()
{
$this->beforeUpdateOptions();
foreach ($this->fields_options as $category_data) {
if (!isset($category_data['fields'])) {
continue;
}
foreach ($category_data['fields'] as $key => $options) {
if ($options['type'] != 'hr' || $options['type'] != 'empty') {
XImportConfiguration::updateValue($key, trim(Tools::getValue($key, '')));
}
}
}
$configurationValues = Tools::getValue('wholesaler', []);
foreach (XImportWholesalers::getWholesalers() as $wholesaler) {
$wholesalerOptions = new WholesalerConfiguration($wholesaler['name']);
if (isset($configurationValues[$wholesaler['name']])) {
foreach ($configurationValues[$wholesaler['name']] as $key => $value) {
$wholesalerOptions->{$key} = (!is_array($value) ? trim($value) : array_filter($value));
}
$wholesalerOptions->saveConfiguration();
}
}
Tools::redirectAdmin($this->context->link->getAdminLink('AdminXImportWholesalers') .
'&conf=6&tabWholesaler=' . Tools::getValue('tabWholesaler', '') . '&tabWholesalerOption=' . Tools::getValue('tabWholesalerOption', ''));
}
public function ajaxProcessCountProducts()
{
die(json_encode([
'status' => true,
'count' => XImportProduct::countProducts(Tools::getValue('wholesalerCode', null))
]));
}
public function ajaxProcessProductsDelete()
{
$products = XImportProduct::getProductsIds(Tools::getValue('wholesalerCode', null), (int)Tools::getValue('limit'));
if (empty($products)) {
if (XImportConfiguration::get('CLEAR_CACHE')) {
try {
Hook::exec('actionProductUpdate');
} catch (Exception $ex) {
Logger::instance()->exception($ex);
}
}
die(json_encode([
'status' => true,
'finish' => true
]));
}
foreach ($products as $productId) {
$product = new Product($productId);
if (Validate::isLoadedObject($product)) {
$product->delete();
}
}
die(json_encode([
'status' => true,
'finish' => false
]));
}
public function ajaxProcessProductsOff()
{
$wholesalerCode = Tools::getValue('wholesalerCode', null);
$countActive = XImportProduct::countProducts($wholesalerCode, true);
XImportProduct::unActiveAllProducts($wholesalerCode);
if (XImportConfiguration::get('CLEAR_CACHE')) {
try {
Hook::exec('actionProductUpdate');
} catch (Exception $ex) {
Logger::instance()->exception($ex);
}
}
die(json_encode([
'status' => true,
'count' => $countActive
]));
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;