Current File : /var/www/vinorea/modules/ipexportimport/classes/import/order/EIAOrderDetail.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__) . '/EIAProduct.php');
class EIAOrderDetail
{
public $row;
public $id_shop;
public $id_lang;
public $id_order;
public $orderDetail;
public $identify_product;
public $identify_combination;
public $id_process;
public $validateOnly;
const IDENTIFY_PRODUCT_ID = 1;
const IDENTIFY_PRODUCT_REFERENCE = 2;
const IDENTIFY_PRODUCT_EAN = 3;
const IDENTIFY_PRODUCT_UPC = 4;
const IDENTIFY_PRODUCT_MPN = 5;
const IDENTIFY_PRODUCT_ISBN = 6;
public function __construct($id_shop = null, $id_lang = null, $id_order = null, $identify_product = null, $identify_combination = null, $orderDetail = null, $row = null, $id_process = null, $validateOnly = false)
{
$this->row = $row;
$this->id_process = $id_process;
$this->orderDetail = $orderDetail;
$this->id_shop = (int) $id_shop;
$this->id_lang = (int) $id_lang;
$this->id_order = (int) $id_order;
$this->identify_product = $identify_product;
$this->identify_combination = $identify_combination;
$this->validateOnly = $validateOnly;
}
public function save()
{
// $fields = $this->getIdentifyField();
$obj = new EIAProduct($this->id_shop, $this->id_lang, $this->id_order, $this->identify_product, $this->identify_combination, $this->row, $this->id_process, $this->validateOnly);
if (isset($this->orderDetail['product_id'])) {
$obj->id_product = $this->orderDetail['product_id'];
}
if (isset($this->orderDetail['id_order_invoice'])) {
$obj->id_order_invoice = $this->orderDetail['id_order_invoice'];
}
if (isset($this->orderDetail['product_reference'])) {
$obj->reference = $this->orderDetail['product_reference'];
}
if (isset($this->orderDetail['product_ean13'])) {
$obj->ean13 = $this->orderDetail['product_ean13'];
}
if (isset($this->orderDetail['product_upc'])) {
$obj->upc = $this->orderDetail['product_upc'];
}
if (isset($this->orderDetail['product_mpn'])) {
$obj->mpn = $this->orderDetail['product_mpn'];
}
if (isset($this->orderDetail['product_isbn'])) {
$obj->isbn = $this->orderDetail['product_isbn'];
}
if (isset($this->orderDetail['product_attribute_id'])) {
$obj->id_product_combination = $this->orderDetail['product_attribute_id'];
}
if (isset($this->orderDetail['product_attribute_reference'])) {
$obj->combination_reference = $this->orderDetail['product_attribute_reference'];
}
if (isset($this->orderDetail['product_attribute_ean13'])) {
$obj->combination_ean = $this->orderDetail['product_attribute_ean13'];
}
if (isset($this->orderDetail['product_attribute_upc'])) {
$obj->combination_upc = $this->orderDetail['product_attribute_upc'];
}
if (isset($this->orderDetail['product_attribute_mpn'])) {
$obj->combination_mpn = $this->orderDetail['product_attribute_mpn'];
}
if (isset($this->orderDetail['product_attribute_isbn'])) {
$obj->combination_isbn = $this->orderDetail['product_attribute_isbn'];
}
if (isset($this->orderDetail['product_name'])) {
$obj->name = $this->orderDetail['product_name'];
}
if (isset($this->orderDetail['product_quantity'])) {
$obj->quantity = $this->orderDetail['product_quantity'];
}
if (isset($this->orderDetail['product_quantity_in_stock'])) {
$obj->quantity_in_stock = $this->orderDetail['product_quantity_in_stock'];
}
if (isset($this->orderDetail['product_quantity_refunded'])) {
$obj->quantity_refunded = $this->orderDetail['product_quantity_refunded'];
}
if (isset($this->orderDetail['product_quantity_return'])) {
$obj->quantity_return = $this->orderDetail['product_quantity_return'];
}
if (isset($this->orderDetail['product_quantity_reinjected'])) {
$obj->quantity_reinjected = $this->orderDetail['product_quantity_reinjected'];
}
if (isset($this->orderDetail['unit_price_tax_excl'])) {
$obj->unit_price_tax_excl = $this->orderDetail['unit_price_tax_excl'];
}
if (isset($this->orderDetail['unit_price_tax_incl'])) {
$obj->unit_price_tax_incl = $this->orderDetail['unit_price_tax_incl'];
}
if (isset($this->orderDetail['total_price_tax_excl'])) {
$obj->total_price_tax_excl = $this->orderDetail['total_price_tax_excl'];
}
if (isset($this->orderDetail['total_price_tax_incl'])) {
$obj->total_price_tax_incl = $this->orderDetail['total_price_tax_incl'];
}
if (isset($this->orderDetail['product_weight'])) {
$obj->weight = $this->orderDetail['product_weight'];
}
if (isset($this->orderDetail['product_supplier_reference'])) {
$obj->supplier_reference = $this->orderDetail['product_supplier_reference'];
}
if (isset($this->orderDetail['ecotax'])) {
$obj->ecotax = $this->orderDetail['ecotax'];
}
if (isset($this->orderDetail['ecotax_tax_rate'])) {
$obj->ecotax_tax_rate = $this->orderDetail['ecotax_tax_rate'];
}
if (isset($this->orderDetail['tax_rate'])) {
$obj->tax_rate = $this->orderDetail['tax_rate'];
}
if (isset($this->orderDetail['reduction_percent'])) {
$obj->reduction_percent = $this->orderDetail['reduction_percent'];
}
if (isset($this->orderDetail['reduction_amount_tax_incl'])) {
$obj->reduction_amount_tax_incl = $this->orderDetail['reduction_amount_tax_incl'];
}
if (isset($this->orderDetail['reduction_amount_tax_excl'])) {
$obj->reduction_amount_tax_excl = $this->orderDetail['reduction_amount_tax_excl'];
}
if (isset($this->orderDetail['id_tax'])) {
$obj->id_tax = $this->orderDetail['id_tax'];
}
if (isset($this->orderDetail['tax_name_new'])) {
$obj->tax_name_new = $this->orderDetail['tax_name_new'];
}
if (isset($this->orderDetail['unit_amount_tax'])) {
$obj->unit_amount_tax = $this->orderDetail['unit_amount_tax'];
}
if (isset($this->orderDetail['total_amount_tax'])) {
$obj->total_amount_tax = $this->orderDetail['total_amount_tax'];
}
$obj->run();
}
private function getIdentifyField()
{
$val = array();
$field_in_file = false;
if ($this->identify_product && $this->identify_product == self::IDENTIFY_PRODUCT_ID) {
$field_in_file = 'product_id';
}
if ($this->identify_product && $this->identify_product == self::IDENTIFY_PRODUCT_REFERENCE) {
$field_in_file = 'product_reference';
}
if ($this->identify_product && $this->identify_product == self::IDENTIFY_PRODUCT_EAN) {
$field_in_file = 'product_ean';
}
if ($this->identify_product && $this->identify_product == self::IDENTIFY_PRODUCT_UPC) {
$field_in_file = 'product_upc';
}
if ($this->identify_product && $this->identify_product == self::IDENTIFY_PRODUCT_MPN) {
$field_in_file = 'product_mpn';
}
if ($this->identify_product && $this->identify_product == self::IDENTIFY_PRODUCT_ISBN) {
$field_in_file = 'product_isbn';
}
if ($this->identify_combination && $this->identify_combination == self::IDENTIFY_PRODUCT_ID) {
$field_in_file = 'product_attribute_id';
}
if ($this->identify_combination && $this->identify_combination == self::IDENTIFY_PRODUCT_REFERENCE) {
$field_in_file = 'product_attribute_reference';
}
if ($this->identify_combination && $this->identify_combination == self::IDENTIFY_PRODUCT_EAN) {
$field_in_file = 'product_attribute_ean13';
}
if ($this->identify_combination && $this->identify_combination == self::IDENTIFY_PRODUCT_UPC) {
$field_in_file = 'product_attribute_upc';
}
if ($this->identify_combination && $this->identify_combination == self::IDENTIFY_PRODUCT_MPN) {
$field_in_file = 'product_attribute_mpn';
}
if ($this->identify_combination && $this->identify_combination == self::IDENTIFY_PRODUCT_ISBN) {
$field_in_file = 'product_attribute_isbn';
}
if ($field_in_file && isset($this->orderDetail[$field_in_file])) {
$val = array($field_in_file => $this->orderDetail[$field_in_file]);
}
if (!$field_in_file && isset($this->orderDetail['product_name'])) {
$val = array('product_name' => $this->orderDetail['product_name']);
}
return $val;
}
}