Current File : /var/www/vinorea/modules/ipexportimport/classes/import/order/EIAConfigurationImportOrders.php |
<?php
/**
*
* NOTICE OF LICENSE
*
* @author SmartPresta <tehran.alishov@gmail.com>
* @copyright 2024 SmartPresta
* @license Commercial License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once dirname(__FILE__) . '/EIAConfiguration.php';
require_once dirname(__FILE__) . '/EIAConfigurationFields.php';
class EIAConfigurationImportOrders
{
const MODULE_FOLDER_NAME = "ipexportimport/";
public function getRelatedModules($id_module)
{
$url = 'https://myprestamodules.com/modules/relatedmodules/send.php?get_related_modules=true&ajax=true&module=' . $id_module;
if ($url) {
return json_decode(Tools::file_get_contents($url), true);
}
return false;
}
public function getAllShops()
{
$shop_options = Shop::getShops();
if (count($shop_options) == 1) {
return (int)key($shop_options);
}
$export_from_all_shops_option = array('id_shop' => 'all', 'name' => 'All Shops');
array_unshift($shop_options, $export_from_all_shops_option);
return $shop_options;
}
public static function downloadImportSettings($id_settings)
{
$settings = EIAConfiguration::getModuleSettingsById($id_settings);
$settings['fields'] = EIAConfigurationFields::getModuleSettingsFieldsById($id_settings);
if (isset($settings['id_setting'])) {
unset($settings['id_setting']);
}
if (!empty($settings['fields'])) {
foreach ($settings['fields'] as &$field) {
unset($field['id_field']);
unset($field['id_setting']);
}
}
file_put_contents(_PS_MODULE_DIR_ . self::MODULE_FOLDER_NAME . 'upload/settings.txt', json_encode($settings));
return Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . basename(_PS_MODULE_DIR_) . '/'.self::MODULE_FOLDER_NAME.'download.php';
}
public static function deleteImportSettings($id_settings)
{
EIAConfiguration::delete($id_settings);
EIAConfigurationFields::removeBySettingsId($id_settings);
}
public static function uploadImportSettings()
{
if (!isset($_FILES['file']) || empty($_FILES['file']['tmp_name'])) {
throw new \Exception(EIATranslatorWrapper::l('Select configuration for upload!'));
}
$file_name = $_FILES['file']['name'];
$file_type = Tools::substr($file_name, strrpos($file_name, '.') + 1);
$file_type = Tools::strtolower($file_type);
if ($file_type != 'txt') {
throw new \Exception(EIATranslatorWrapper::l('Settings must have txt format!'));
}
$configuration = Tools::file_get_contents($_FILES['file']['tmp_name']);
if (EIATools::isStringSerialized($configuration)) {
$configuration = Tools::unSerialize($configuration);
} else {
$configuration = json_decode($configuration, true);
}
$configuration_fields = $configuration['fields'];
unset($configuration['fields']);
$id_settings = EIAConfiguration::add($configuration);
if (!empty($configuration_fields) && $id_settings) {
EIAConfigurationFields::import($id_settings, $configuration_fields);
}
return true;
}
public static function saveImportSettings($data)
{
$id_settings = $data['id_settings'];
$settings = self::prepareSettingsForSaving($data);
if ($id_settings) {
EIAConfiguration::update($id_settings, $settings);
EIAConfigurationFields::removeBySettingsId($id_settings);
} else {
$id_settings = EIAConfiguration::add($settings);
}
EIAConfigurationFields::save($id_settings, $data['fields']);
return $id_settings;
}
private static function prepareSettingsForSaving($settings)
{
if(!isset($settings['settings_name']) || !$settings['settings_name']){
$settings['settings_name'] = EIATranslatorWrapper::l('Import Template');
}
return [
'name' => pSQL($settings['settings_name']),
'format_file' => pSQL($settings['format_file']),
'import_shop' => (int)$settings['import_shop'],
'import_language' => (int)$settings['import_language'],
'import_delimiter' => pSQL($settings['import_delimiter']),
'import_method' => pSQL($settings['import_method']),
'user_notification' => pSQL($settings['user_notification']),
'type_upload_file' => pSQL($settings['type_upload_file']),
'ftp_protocol' => pSQL($settings['ftp_protocol']),
'ftp_server' => pSQL($settings['ftp_server']),
'ftp_username' => pSQL($settings['ftp_user']),
'ftp_password' => pSQL($settings['transfer_password']),
'ftp_folder_path' => pSQL($settings['transfer_path']),
'ftp_port' => pSQL($settings['transfer_port']),
'ftp_passive_mode' => isset($settings['passive_mode']) ? (int)$settings['passive_mode'] : (int)0,
'url_file_path' => pSQL($settings['path_to_file']),
'identify_order' => pSQL($settings['identify_order']),
'identify_product' => pSQL($settings['identify_product']),
'identify_product_combination' => pSQL($settings['identify_product_combination']),
'identify_customers' => pSQL($settings['identify_customers']),
'identify_addresses' => isset($settings['identify_addresses']) ? pSQL(serialize($settings['identify_addresses'])) : '',
'create_new_customers' => isset($settings['create_new_customers']) ? (int)$settings['create_new_customers'] : (int)0,
'create_new_addresses' => isset($settings['create_new_addresses']) ? (int)$settings['create_new_addresses'] : (int)0,
'date_add' => pSQL(time()),
];
}
public static function getFieldsFromFile()
{
return Tools::unserialize(Configuration::get('GOMAKOIL_IMPORT_ORDERS_FIELDS', null, (int)Context::getContext()->shop->id_shop_group, (int)Context::getContext()->shop->id));
}
public static function setFieldsFromFile($data)
{
Configuration::updateValue('GOMAKOIL_IMPORT_ORDERS_FIELDS', $data, false, (int)Tools::getValue('id_shop_group'), (int)Tools::getValue('id_shop'));
}
public function getOrderFieldsTab()
{
return array(
array(
'tab' => 'orders',
'name' => EIATranslatorWrapper::l('Orders data'),
),
array(
'tab' => 'products',
'name' => EIATranslatorWrapper::l('Products Data'),
),
array(
'tab' => 'customers',
'name' => EIATranslatorWrapper::l('Customers Data'),
),
array(
'tab' => 'shippingAddress',
'name' => EIATranslatorWrapper::l('Shipping Addresses'),
),
array(
'tab' => 'invoiceAddress',
'name' => EIATranslatorWrapper::l('Invoice Address'),
),
array(
'tab' => 'payment',
'name' => EIATranslatorWrapper::l('Payment'),
),
);
}
public function getOrderFields()
{
$data = array();
$data['orders'] = array(
array(
'field' => 'id_order',
'name' => EIATranslatorWrapper::l('Order ID'),
'required' => false,
),
array(
'field' => 'order_reference',
'name' => EIATranslatorWrapper::l('Order Reference'),
),
array(
'field' => 'id_status',
'name' => EIATranslatorWrapper::l('Order status ID'),
),
array(
'field' => 'status_name',
'name' => EIATranslatorWrapper::l('Order status name'),
),
array(
'field' => 'id_cart',
'name' => EIATranslatorWrapper::l('Cart ID'),
),
array(
'field' => 'shipping_weight',
'name' => EIATranslatorWrapper::l('Shipping weight'),
),
array(
'field' => 'secure_key',
'name' => EIATranslatorWrapper::l('Secure key'),
),
array(
'field' => 'id_currency',
'name' => EIATranslatorWrapper::l('Currency ID'),
'required' => true,
),
array(
'field' => 'message',
'name' => EIATranslatorWrapper::l('Order comment (message)'),
),
array(
'field' => 'id_carrier',
'name' => EIATranslatorWrapper::l('ID Carrier'),
'required' => true,
),
array(
'field' => 'conversion_rate',
'name' => EIATranslatorWrapper::l('Conversion rate'),
'required' => true
),
array(
'field' => 'payment',
'name' => EIATranslatorWrapper::l('Payment'),
'required' => true
),
array(
'field' => 'module',
'name' => EIATranslatorWrapper::l('Module'),
'required' => true
),
array(
'field' => 'recyclable',
'name' => EIATranslatorWrapper::l('Recyclable'),
),
array(
'field' => 'gift',
'name' => EIATranslatorWrapper::l('Gift'),
),
array(
'field' => 'gift_message',
'name' => EIATranslatorWrapper::l('Gift message'),
),
array(
'field' => 'mobile_theme',
'name' => EIATranslatorWrapper::l('Mobile theme'),
),
array(
'field' => 'tracking_number',
'name' => EIATranslatorWrapper::l('Tracking number'),
),
array(
'field' => 'shipping_number',
'name' => EIATranslatorWrapper::l('Shipping number'),
),
array(
'field' => 'total_products',
'name' => EIATranslatorWrapper::l('Total products'),
'required' => true
),
array(
'field' => 'total_products_wt',
'name' => EIATranslatorWrapper::l('Total products with tax'),
'required' => true
),
array(
'field' => 'total_discounts_with_tax',
'name' => EIATranslatorWrapper::l('Total discounts with tax'),
),
array(
'field' => 'total_discounts_tax_excl',
'name' => EIATranslatorWrapper::l('Total discounts (tax excl.)'),
),
array(
'field' => 'total_paid',
'name' => EIATranslatorWrapper::l('Total paid'),
'required' => true,
),
array(
'field' => 'total_paid_with_tax',
'name' => EIATranslatorWrapper::l('Total paid with tax'),
),
array(
'field' => 'total_paid_tax_excl',
'name' => EIATranslatorWrapper::l('Total paid (tax excl.)'),
),
array(
'field' => 'total_paid_real',
'name' => EIATranslatorWrapper::l('Total paid real'),
'required' => true
),
array(
'field' => 'total_shipping',
'name' => EIATranslatorWrapper::l('Total shipping'),
),
array(
'field' => 'total_shipping_with_tax',
'name' => EIATranslatorWrapper::l('Total shipping with tax'),
),
array(
'field' => 'total_shipping_tax_excl',
'name' => EIATranslatorWrapper::l('Total shipping (tax excl.)'),
),
array(
'field' => 'voucher_name',
'name' => EIATranslatorWrapper::l('Voucher name'),
),
array(
'field' => 'voucher_code',
'name' => EIATranslatorWrapper::l('Voucher code'),
),
array(
'field' => 'total_voucher_with_tax',
'name' => EIATranslatorWrapper::l('Total voucher with tax'),
),
array(
'field' => 'total_voucher_tax_excl',
'name' => EIATranslatorWrapper::l('Total voucher (tax excl.)'),
),
array(
'field' => 'carrier_tax_rate',
'name' => EIATranslatorWrapper::l('Carrier tax rate'),
),
array(
'field' => 'wrapping_cost_with_tax',
'name' => EIATranslatorWrapper::l('Wrapping Cost with tax'),
),
array(
'field' => 'wrapping_cost_tax_excl',
'name' => EIATranslatorWrapper::l('Wrapping Cost (tax excl.)'),
),
array(
'field' => 'valid',
'name' => EIATranslatorWrapper::l('Valid'),
),
array(
'field' => 'date_add',
'name' => EIATranslatorWrapper::l('Date add'),
),
array(
'field' => 'date_upd',
'name' => EIATranslatorWrapper::l('Date update'),
),
array(
'field' => 'delivery_number',
'name' => EIATranslatorWrapper::l('Delivery number'),
),
array(
'field' => 'delivery_date',
'name' => EIATranslatorWrapper::l('Delivery date'),
),
array(
'field' => 'credit_slip_shipping_cost',
'name' => EIATranslatorWrapper::l('Credit slip shipping cost'),
),
array(
'field' => 'credit_slip_amount',
'name' => EIATranslatorWrapper::l('Credit slip amount'),
),
array(
'field' => 'credit_slip_shipping_cost_amount',
'name' => EIATranslatorWrapper::l('Credit slip shipping cost amount'),
),
array(
'field' => 'credit_slip_date_add',
'name' => EIATranslatorWrapper::l('Credit slip date add'),
),
array(
'field' => 'credit_slip_total_products_tax_excl',
'name' => EIATranslatorWrapper::l('Credit slip total products (tax excl.)'),
),
array(
'field' => 'credit_slip_total_products_tax_incl',
'name' => EIATranslatorWrapper::l('Credit slip total products (tax incl.)'),
),
array(
'field' => 'credit_slip_total_shipping',
'name' => EIATranslatorWrapper::l('Credit slip total shipping'),
),
array(
'field' => 'credit_slip_total_shipping_tax_excl',
'name' => EIATranslatorWrapper::l('Credit slip total shipping (tax excl.)'),
),
array(
'field' => 'credit_slip_total_shipping_tax_incl',
'name' => EIATranslatorWrapper::l('Credit slip total shipping (tax incl.)'),
),
);
$data['products'] = array(
array(
'field' => 'id_product',
'name' => EIATranslatorWrapper::l('Product ID'),
),
array(
'field' => 'product_reference',
'name' => EIATranslatorWrapper::l('Product Reference'),
),
array(
'field' => 'product_ean_13',
'name' => EIATranslatorWrapper::l('Product EAN 13'),
),
array(
'field' => 'product_upc',
'name' => EIATranslatorWrapper::l('Product UPC barcode'),
),
array(
'field' => 'product_mpn',
'name' => EIATranslatorWrapper::l('Product MPN'),
),
array(
'field' => 'id_product_combination',
'name' => EIATranslatorWrapper::l('Product Combination ID'),
),
array(
'field' => 'product_combination_reference',
'name' => EIATranslatorWrapper::l('Product Combination Reference'),
),
array(
'field' => 'product_combination_ean',
'name' => EIATranslatorWrapper::l('Product Combination EAN 13'),
),
array(
'field' => 'product_combination_upc',
'name' => EIATranslatorWrapper::l('Product Combination UPC barcode'),
),
array(
'field' => 'product_combination_mpn',
'name' => EIATranslatorWrapper::l('Product Combination MPN'),
),
array(
'field' => 'product_name',
'name' => EIATranslatorWrapper::l('Product name'),
'required' => true,
),
array(
'field' => 'product_quantity',
'name' => EIATranslatorWrapper::l('Product quantity'),
'required' => true,
),
array(
'field' => 'product_quantity_in_stock',
'name' => EIATranslatorWrapper::l('Product quantity in stock'),
),
array(
'field' => 'product_quantity_refunded',
'name' => EIATranslatorWrapper::l('Product quantity refunded'),
),
array(
'field' => 'product_quantity_return',
'name' => EIATranslatorWrapper::l('Product quantity returned'),
),
array(
'field' => 'product_quantity_reinjected',
'name' => EIATranslatorWrapper::l('Product quantity reinjected'),
),
array(
'field' => 'unit_price_tax_excl',
'name' => EIATranslatorWrapper::l('Product Unit Price (tax excl.)'),
),
array(
'field' => 'unit_price_tax_incl',
'name' => EIATranslatorWrapper::l('Product Unit Price (tax incl.)'),
),
array(
'field' => 'total_price_tax_excl',
'name' => EIATranslatorWrapper::l('Product Total Price (tax excl.)'),
),
array(
'field' => 'total_price_tax_incl',
'name' => EIATranslatorWrapper::l('Product Total Price (tax incl.)'),
),
array(
'field' => 'product_weight',
'name' => EIATranslatorWrapper::l('Product weight'),
),
array(
'field' => 'product_supplier_reference',
'name' => EIATranslatorWrapper::l('Product supplier reference'),
),
array(
'field' => 'product_ecotax',
'name' => EIATranslatorWrapper::l('Product Ecotax '),
),
array(
'field' => 'product_ecotax_tax_rate',
'name' => EIATranslatorWrapper::l('Product Ecotax tax rate'),
),
array(
'field' => 'product_tax_rate',
'name' => EIATranslatorWrapper::l('Tax rate'),
),
array(
'field' => 'product_tax_name',
'name' => EIATranslatorWrapper::l('Tax name'),
),
array(
'field' => 'product_reduction_percent',
'name' => EIATranslatorWrapper::l('Product reduction percent'),
),
array(
'field' => 'product_reduction_amount_tax_incl',
'name' => EIATranslatorWrapper::l('Product reduction amount with tax'),
),
array(
'field' => 'product_reduction_amount_tax_excl',
'name' => EIATranslatorWrapper::l('Product reduction amount (tax excl.)'),
),
);
$data['customers'] = array(
array(
'field' => 'id_customer',
'name' => EIATranslatorWrapper::l('Customer ID'),
),
array(
'field' => 'customer_email',
'name' => EIATranslatorWrapper::l('Customer Email'),
'required' => true,
),
array(
'field' => 'customer_firstname',
'name' => EIATranslatorWrapper::l('Customer first name'),
'required' => true,
),
array(
'field' => 'customer_lastname',
'name' => EIATranslatorWrapper::l('Customer last name'),
'required' => true,
),
array(
'field' => 'customer_birthday',
'name' => EIATranslatorWrapper::l('Customer birthday'),
),
array(
'field' => 'customer_company',
'name' => EIATranslatorWrapper::l('Company'),
),
array(
'field' => 'customer_default_group',
'name' => EIATranslatorWrapper::l('Default customer group'),
),
array(
'field' => 'customer_groups',
'name' => EIATranslatorWrapper::l('Customer groups'),
),
array(
'field' => 'customer_private_note',
'name' => EIATranslatorWrapper::l('Private Note'),
),
array(
'field' => 'customer_is_guest',
'name' => EIATranslatorWrapper::l('Is guest'),
),
array(
'field' => 'customer_website',
'name' => EIATranslatorWrapper::l('Website'),
),
array(
'field' => 'customer_subscription',
'name' => EIATranslatorWrapper::l('Newsletter Subscription'),
),
);
$data['shippingAddress'] = array(
array(
'field' => 'shipping_address_id',
'name' => EIATranslatorWrapper::l('Shipping Address ID'),
),
array(
'field' => 'shipping_address_1',
'name' => EIATranslatorWrapper::l('Shipping Address 1'),
'required' => true,
),
array(
'field' => 'shipping_address_2',
'name' => EIATranslatorWrapper::l('Shipping Address 2'),
),
array(
'field' => 'shipping_customer_first_name',
'name' => EIATranslatorWrapper::l('Shipping customer first name'),
'required' => true,
),
array(
'field' => 'shipping_customer_last_name',
'name' => EIATranslatorWrapper::l('Shipping customer last name'),
'required' => true,
),
array(
'field' => 'shipping_dni_nif_nie',
'name' => EIATranslatorWrapper::l('Shipping DNI / NIF / NIE'),
),
array(
'field' => 'shipping_address_alias',
'name' => EIATranslatorWrapper::l('Shipping address alias'),
'required' => true,
),
array(
'field' => 'shipping_id_country',
'name' => EIATranslatorWrapper::l('Shipping ID Country'),
'required' => true,
),
array(
'field' => 'shipping_country_name',
'name' => EIATranslatorWrapper::l('Shipping Country name'),
),
array(
'field' => 'shipping_country_iso_code',
'name' => EIATranslatorWrapper::l('Shipping Country ISO code'),
),
array(
'field' => 'shipping_id_state',
'name' => EIATranslatorWrapper::l('Shipping ID State'),
),
array(
'field' => 'shipping_state_name',
'name' => EIATranslatorWrapper::l('Shipping State name'),
),
array(
'field' => 'shipping_state_iso_code',
'name' => EIATranslatorWrapper::l('Shipping State ISO code'),
),
array(
'field' => 'shipping_zip_code',
'name' => EIATranslatorWrapper::l('Shipping Zip/Postal Code'),
),
array(
'field' => 'shipping_city',
'name' => EIATranslatorWrapper::l('Shipping City'),
'required' => true,
),
array(
'field' => 'shipping_other',
'name' => EIATranslatorWrapper::l('Shipping Other'),
),
array(
'field' => 'shipping_phone',
'name' => EIATranslatorWrapper::l('Shipping Phone'),
),
array(
'field' => 'shipping_mobile_phone',
'name' => EIATranslatorWrapper::l('Shipping Mobile phone'),
),
array(
'field' => 'shipping_company',
'name' => EIATranslatorWrapper::l('Shipping Company'),
),
array(
'field' => 'shipping_vat_number',
'name' => EIATranslatorWrapper::l('Shipping Vat number'),
),
);
$data['invoiceAddress'] = array(
array(
'field' => 'invoice_address_id',
'name' => EIATranslatorWrapper::l('Invoice Address ID'),
),
array(
'field' => 'invoice_address_1',
'name' => EIATranslatorWrapper::l('Invoice Address 1'),
'required' => true,
),
array(
'field' => 'invoice_address_2',
'name' => EIATranslatorWrapper::l('Invoice Address 2'),
),
array(
'field' => 'invoice_number',
'name' => EIATranslatorWrapper::l('Invoice number'),
),
array(
'field' => 'invoice_customer_first_name',
'name' => EIATranslatorWrapper::l('Invoice customer first name'),
'required' => true,
),
array(
'field' => 'invoice_customer_last_name',
'name' => EIATranslatorWrapper::l('Invoice customer last name'),
'required' => true,
),
array(
'field' => 'invoice_dni_nif_nie',
'name' => EIATranslatorWrapper::l('Invoice DNI / NIF / NIE'),
),
array(
'field' => 'invoice_address_alias',
'name' => EIATranslatorWrapper::l('Invoice address alias'),
'required' => true,
),
array(
'field' => 'invoice_id_country',
'name' => EIATranslatorWrapper::l('Invoice ID Country'),
'required' => true,
),
array(
'field' => 'invoice_country_name',
'name' => EIATranslatorWrapper::l('Invoice Country name'),
),
array(
'field' => 'invoice_country_iso_code',
'name' => EIATranslatorWrapper::l('Invoice Country ISO code'),
),
array(
'field' => 'invoice_id_state',
'name' => EIATranslatorWrapper::l('Invoice ID State'),
),
array(
'field' => 'invoice_state_name',
'name' => EIATranslatorWrapper::l('Invoice State name'),
),
array(
'field' => 'invoice_state_iso_code',
'name' => EIATranslatorWrapper::l('Invoice State ISO code'),
),
array(
'field' => 'invoice_zip_code',
'name' => EIATranslatorWrapper::l('Invoice Zip/Postal Code'),
),
array(
'field' => 'invoice_city',
'name' => EIATranslatorWrapper::l('Invoice City'),
'required' => true,
),
array(
'field' => 'invoice_other',
'name' => EIATranslatorWrapper::l('Invoice Other'),
),
array(
'field' => 'invoice_phone',
'name' => EIATranslatorWrapper::l('Invoice Phone'),
),
array(
'field' => 'invoice_mobile_phone',
'name' => EIATranslatorWrapper::l('Invoice Mobile phone'),
),
array(
'field' => 'invoice_company',
'name' => EIATranslatorWrapper::l('Invoice Company'),
),
array(
'field' => 'invoice_vat_number',
'name' => EIATranslatorWrapper::l('Invoice Vat number'),
),
array(
'field' => 'invoice_note',
'name' => EIATranslatorWrapper::l('Invoice note'),
),
array(
'field' => 'invoice_date',
'name' => EIATranslatorWrapper::l('Invoice date'),
),
);
$data['payment'] = array(
array(
'field' => 'payment_method',
'name' => EIATranslatorWrapper::l('Payment Method'),
),
array(
'field' => 'payment_amount',
'name' => EIATranslatorWrapper::l('Payment amount'),
'required' => true,
),
array(
'field' => 'payment_currency',
'name' => EIATranslatorWrapper::l('Payment currency'),
'required' => true,
),
array(
'field' => 'payment_transaction_id',
'name' => EIATranslatorWrapper::l('Payment Transaction ID'),
),
array(
'field' => 'payment_date',
'name' => EIATranslatorWrapper::l('Payment date'),
),
);
return $data;
}
}