This commit is contained in:
2025-03-21 20:24:43 +01:00
parent 224398df90
commit f34c9162d4
12427 changed files with 5329941 additions and 373384 deletions

View File

@@ -264,6 +264,7 @@ class EmpikClient
$filterParams = array_merge([
'sort' => 'dateCreated',
'order' => 'desc',
'max' => '20',
], $filterParams);
$query = http_build_query($filterParams);

View File

@@ -0,0 +1,110 @@
<?php
namespace Empik\Marketplace\Adapter;
use Context;
use Exception;
use Module;
use Tools;
use Translate;
class TranslateAdapter
{
/**
* Adapter for getting module translation for a specific locale on PS 1.6
*
* @param Module|string $module Module instance or name
* @param string $originalString string to translate
* @param string $source source of the original string
* @param string|null $iso locale or language ISO code
*
* @return string
*
* @throws Exception
*/
public function getModuleTranslation(
$module,
$originalString,
$source,
$iso = null
) {
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
return Translate::getModuleTranslation($module, $originalString, $source, null, false, $iso);
} elseif ($iso === null) {
return Translate::getModuleTranslation($module, $originalString, $source);
}
static $translations;
static $langCache = [];
static $translationsMerged = [];
$name = $module instanceof Module ? $module->name : $module;
if (empty($iso)) {
$iso = Context::getContext()->language->iso_code;
}
if (!isset($translationsMerged[$name][$iso])) {
$filesByPriority = [
// PrestaShop 1.5 translations
_PS_MODULE_DIR_ . $name . '/translations/' . $iso . '.php',
// PrestaShop 1.4 translations
_PS_MODULE_DIR_ . $name . '/' . $iso . '.php',
// Translations in theme
_PS_THEME_DIR_ . 'modules/' . $name . '/translations/' . $iso . '.php',
_PS_THEME_DIR_ . 'modules/' . $name . '/' . $iso . '.php',
];
foreach ($filesByPriority as $file) {
if (file_exists($file)) {
$_MODULE = null;
include $file;
if (isset($_MODULE)) {
$translations[$iso] = isset($translations[$iso])
? array_merge($translations[$iso], $_MODULE)
: $_MODULE;
}
}
}
$translationsMerged[$name][$iso] = true;
}
$string = preg_replace("/\\\*'/", "\'", $originalString);
$key = md5($string);
$cacheKey = $name . '|' . $string . '|' . $source . '|' . $iso;
if (!isset($langCache[$cacheKey])) {
if (!isset($translations[$iso])) {
return str_replace('"', '&quot;', $string);
}
$currentKey = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $source) . '_' . $key;
$defaultKey = Tools::strtolower('<{' . $name . '}prestashop>' . $source) . '_' . $key;
if ('controller' == Tools::substr($source, -10, 10)) {
$file = Tools::substr($source, 0, -10);
$currentKeyFile = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $file) . '_' . $key;
$defaultKeyFile = Tools::strtolower('<{' . $name . '}prestashop>' . $file) . '_' . $key;
}
if (isset($currentKeyFile) && !empty($translations[$iso][$currentKeyFile])) {
$ret = Tools::stripslashes($translations[$iso][$currentKeyFile]);
} elseif (isset($defaultKeyFile) && !empty($translations[$iso][$defaultKeyFile])) {
$ret = Tools::stripslashes($translations[$iso][$defaultKeyFile]);
} elseif (!empty($translations[$iso][$currentKey])) {
$ret = Tools::stripslashes($translations[$iso][$currentKey]);
} elseif (!empty($translations[$iso][$defaultKey])) {
$ret = Tools::stripslashes($translations[$iso][$defaultKey]);
} else {
$ret = Tools::stripslashes($string);
}
$langCache[$cacheKey] = htmlspecialchars($ret, ENT_COMPAT, 'UTF-8');
}
return $langCache[$cacheKey];
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Empik\Marketplace\Configuration;
use Empik\Marketplace\Adapter\ConfigurationAdapter;
class ExportProductConfiguration
{
const EXPORT_PRODUCT_FILENAME = 'PrestaShop_products.csv';
const EXPORT_OFFER_FILENAME = 'PrestaShop_offers.csv';
const EXPORT_PATH = __DIR__ . '/../../data/';
const CSV_FIELD_SEPARATOR = ';';
const CSV_VALUE_SEPARATOR = '|';
protected $configurationAdapter;
public function __construct(ConfigurationAdapter $configurationAdapter)
{
$this->configurationAdapter = $configurationAdapter;
}
public function getExportPath()
{
return self::EXPORT_PATH . self::EXPORT_PRODUCT_FILENAME;
}
public function getProductExportPath()
{
return self::EXPORT_PATH . self::EXPORT_PRODUCT_FILENAME;
}
public function getOfferExportPath()
{
return self::EXPORT_PATH . self::EXPORT_OFFER_FILENAME;
}
public function getCsvDelimiter()
{
return self::CSV_FIELD_SEPARATOR;
}
public function getProductIdType()
{
return $this->configurationAdapter->get('EMPIK_OFFER_IDENTIFIER');
}
public function getPriceRatio()
{
return (float)$this->configurationAdapter->get('EMPIK_PRICE_RATIO');
}
public function getAddToPrice()
{
return (float)$this->configurationAdapter->get('EMPIK_ADD_TO_PRICE');
}
public function getStockReduce()
{
return (float)$this->configurationAdapter->get('EMPIK_REDUCE_STOCK');
}
}

View File

@@ -0,0 +1,60 @@
<?php
class EmpikAction extends ObjectModel
{
const ACTION_OTHER = 'OTHER';
const ACTION_PRODUCT_EXPORT = 'PRODUCT_EXPORT';
const ACTION_OFFER_EXPORT = 'OFFER_EXPORT';
const ACTION_PRODUCT_EXPORT_INCLUDE = 'PRODUCT_EXPORT_INCLUDE';
const ACTION_PRODUCT_EXPORT_EXCLUDE = 'PRODUCT_EXPORT_EXCLUDE';
const STATUS_NEW = 'NEW';
const STATUS_COMPLETED = 'COMPLETE';
public $id_shop;
public $action = self::ACTION_OTHER;
public $status = self::STATUS_NEW;
public $id_import;
public $import_count;
public $date_start;
public $date_end;
public static $definition = [
'table' => 'empik_action',
'primary' => 'id_empik_action',
'fields' => [
'id_shop' => [
'type' => self::TYPE_INT,
'validate' => 'isUnsignedInt',
'required' => true,
],
'action' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'status' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'id_import' => [
'type' => self::TYPE_INT,
'validate' => 'isCleanHtml',
],
'import_count' => [
'type' => self::TYPE_INT,
'validate' => 'isCleanHtml',
],
'date_start' => [
'type' => self::TYPE_DATE,
'validate' => 'isDate',
'required' => true,
],
'date_end' => [
'type' => self::TYPE_DATE,
'validate' => 'isDate',
'required' => true,
],
],
];
}

View File

@@ -0,0 +1,30 @@
<?php
class EmpikActionLog extends ObjectModel
{
public $id_empik_action;
public $message;
public $date_add;
public static $definition = [
'table' => 'empik_action',
'primary' => 'id_empik_action_log',
'fields' => [
'id_empik_action' => [
'type' => self::TYPE_INT,
'validate' => 'isUnsignedInt',
'required' => true,
],
'message' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'date_add' => [
'type' => self::TYPE_DATE,
'validate' => 'isDate',
'required' => true,
],
],
];
}

View File

@@ -0,0 +1,87 @@
<?php
class EmpikOrder extends ObjectModel
{
public $id_order;
public $empik_order_reference;
public $empik_order_carrier;
public $empik_payment;
public $empik_carrier;
public $empik_pickup_point;
public $empik_vat_number;
public $date_add;
public static $definition = [
'table' => 'empik_orders',
'primary' => 'id_empik_order',
'fields' => [
'id_order' => [
'type' => self::TYPE_INT,
'validate' => 'isUnsignedInt',
'required' => true,
],
'empik_order_reference' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'empik_order_carrier' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'empik_payment' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
'required' => true,
],
'empik_carrier' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
'required' => true,
],
'empik_pickup_point' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'empik_vat_number' => [
'type' => self::TYPE_STRING,
'validate' => 'isCleanHtml',
],
'date_add' => [
'type' => self::TYPE_DATE,
'validate' => 'isDate',
'required' => false,
],
],
];
public static function getEmpikOrderByOrderId($orderId)
{
$query = (new DbQuery())
->select('eo.*')
->from('empik_orders', 'eo')
->where('eo.id_order = "'.pSQL($orderId).'"');
return Db::getInstance()->getRow($query);
}
public static function getEmpikOrderReferenceByOrderId($orderId)
{
$query = (new DbQuery())
->select('eo.empik_order_reference')
->from('empik_orders', 'eo')
->where('eo.id_order = "'.pSQL($orderId).'"');
return Db::getInstance()->getValue($query);
}
public static function getOrderIdByEmpikOrderReference($empikOrderReference)
{
$query = (new DbQuery())
->select('eo.id_order')
->from('empik_orders', 'eo')
->where('eo.empik_order_reference = "'.pSQL($empikOrderReference).'"');
return Db::getInstance()->getValue($query);
}
}

View File

@@ -67,7 +67,6 @@ class CronJobsHandler
break;
case self::ACTION_EXPORT_OFFERS:
$this->exportOfferProcessor->process();
file_put_contents('logs/empik.log', date( 'Y-m-d H:i:s' ) . ' - export offers' . PHP_EOL, FILE_APPEND );
break;
case self::ACTION_IMPORT_ORDERS:
$this->orderProcessor->process();

View File

@@ -143,13 +143,11 @@ class ExportOfferHandler
$quantity = \StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']);
$calculatedQuantity = $this->offerQuantityCalculator->calculate($quantity);
if ( $calculatedQuantity < 1 )
$calculatedQuantity = 1;
$offer['product-id-type'] = $this->identifierExtractor->getIdentifierType();
$offer['product-id'] = $this->identifierExtractor->extract($product);
$offer['sku'] = $this->skuExtractor->extract($product);
$offer['state'] = $product['condition'] === 'new' ? self::STATE_CODE_USED : self::STATE_CODE_NEW;
$offer['state'] = !empty($product['empik_condition']) ? $product['empik_condition'] : self::STATE_CODE_NEW;
if ($product['offer_price'] > 0) {
$offer['price'] = $product['offer_price'];
@@ -164,8 +162,6 @@ class ExportOfferHandler
}
$offer['quantity'] = $calculatedQuantity;
if ( $offer['quantity'] < 1 )
$offer['quantity'] = 1;
if ($leadTimeToShip && $leadTimeToShip >= 0) {
$offer['leadtime-to-ship'] = $leadTimeToShip;

View File

@@ -0,0 +1,8 @@
<?php
namespace Empik\Marketplace\Manager;
class OrderManager
{
}

View File

@@ -0,0 +1,383 @@
<?php
namespace Empik\Marketplace\OrderFulfiller;
use Empik\Marketplace\Adapter\ToolsAdapter;
use Empik\Marketplace\DataProvider\ProductDataProvider;
use Order;
use OrderDetail;
use Address;
use Customer;
use OrderCarrier;
use OrderHistory;
use Cart;
class EmpikOrder
{
/** @var ProductDataProvider */
protected $productDataProvider;
/** @var array */
protected $data;
/** @var Order */
protected $order;
/** @var OrderDetail[] */
protected $orderDetails;
/** @var Customer */
protected $customer;
/** @var Address */
protected $shippingAddress;
/** @var Address */
protected $billingAddress;
/** @var OrderCarrier */
protected $carrier;
/** @var Cart */
protected $cart;
/** @var OrderHistory[] */
protected $orderHistory;
/** @var array */
protected $notes;
public function __construct($data)
{
$id = \EmpikOrder::getOrderIdByEmpikOrderReference($data['order_id']);
$order = new Order($id);
$this->setData($data);
$this->setOrder($order);
$this->productDataProvider = new ProductDataProvider();
}
/**
* @return bool
*/
public function exist()
{
$data = $this->getData();
return (bool)\EmpikOrder::getOrderIdByEmpikOrderReference($data['order_id']);
}
/**
* @return bool
*/
public function isAcceptable()
{
foreach ($this->getAcceptanceLines() as $orderLine) {
if (!$orderLine['accepted']) {
return false;
}
}
return true;
}
/**
* @return array
*/
public function getAcceptanceLines()
{
$return = [];
foreach ($this->getData()['order_lines'] as $orderLine) {
$pr = $this->productDataProvider->getOneBy([
'p.reference' => $orderLine['offer_sku'] // @todo
]);
$return[] = [
'id' => (string)$orderLine['order_line_id'],
'accepted' => $pr && $pr['active'] && $pr['quantity'] >= $orderLine['quantity'],
];
}
return $return;
}
public function add()
{
$context = \Context::getContext();
if ($this->customer && !$this->customer->id) {
$this->customer->id_shop = $context->shop->id;
$this->customer->id_shop_group = $context->shop->id_shop_group;
$this->customer->add();
}
if ($this->shippingAddress && !$this->shippingAddress->id) {
$this->shippingAddress->id_customer = $this->customer->id;
$this->shippingAddress->add();
}
if ($this->billingAddress && !$this->billingAddress->id) {
$this->shippingAddress->id_customer = $this->customer->id;
$this->billingAddress->add();
}
$this->cart->id_customer = $this->customer->id;
// $this->cart->add();
$this->order->id_address_delivery = $this->shippingAddress->id;
$this->order->id_address_invoice = $this->billingAddress->id;
$this->order->id_cart = $this->cart->id;
$this->order->id_currency = $context->currency->id;
$this->order->id_lang = $context->language->id;
$this->order->id_shop = $context->shop->id;
$this->order->id_shop_group = $context->shop->id_shop_group;
$this->order->id_customer = $this->customer->id;
$this->order->id_carrier = $this->carrier->id_carrier;
$this->order->payment = $this->data['payment_type'];
$this->order->module = 'empikmarketplace';
$this->order->total_paid = (float)$this->data['total_price'];
$this->order->total_paid_tax_incl = (float)$this->data['total_price'];
$this->order->total_paid_tax_excl = (float)$this->data['total_price'];
$this->order->total_paid_real = (float)$this->data['total_price'];
$this->order->total_products = (float)$this->data['price'];
$this->order->total_products_wt = (float)$this->data['price'];
$this->order->total_shipping = (float)$this->data['shipping_price'];
$this->order->total_shipping_tax_incl = (float)$this->data['shipping_price'];
$this->order->total_shipping_tax_excl = (float)$this->data['shipping_price'];
$this->order->conversion_rate = 1;
$this->order->secure_key = $this->customer->secure_key;
do {
$this->order->reference = Order::generateReference();
} while (Order::getByReference($this->order->reference)->count());
if ($this->orderHistory) {
$this->order->current_state = end($this->orderHistory)->id_order_state;
}
// foreach ($this->notes as $note) {
// $this->order->note .= !$this->order->note ? $note : "\r\n\r\n" . $note;
// }
// create order
$this->order->add();
// add message (ps 1.6)
// if ($this->order->note && !ToolsAdapter::is17static()) {
// $msg = new \Message();
// $msg->message = $this->order->note;
// $msg->id_cart = $this->cart->id;
// $msg->id_customer = $this->customer->id;
// $msg->id_order = $this->order->id;
// $msg->private = 1;
// $msg->add();
// }
// add order carrier
$this->carrier->id_order = $this->order->id;
$this->carrier->shipping_cost_tax_excl = $this->order->total_shipping_tax_excl;
$this->carrier->shipping_cost_tax_incl = $this->order->total_shipping_tax_incl;
$this->carrier->add();
foreach ($this->orderDetails as $orderDetail) {
$orderDetail->id_order = $this->order->id;
$orderDetail->add();
}
foreach ($this->orderHistory as $history) {
$history->id_order = $this->order->id;
$history->add();
}
// @todo
$empikOrder = new \EmpikOrder();
$empikOrder->id_order = $this->order->id;
$empikOrder->empik_order_reference = $this->data['order_id'];
$empikOrder->empik_order_carrier = $this->data['shipping_type_code'];
$empikOrder->empik_payment = $this->data['payment_type'];
$empikOrder->empik_carrier = $this->data['shipping_type_label'];
foreach ($this->data['order_additional_fields'] as $additionalField) {
if ($additionalField['code'] === 'delivery-point-name') {
$empikOrder->empik_pickup_point = $additionalField['value'];
}
if ($additionalField['code'] === 'nip') {
$empikOrder->empik_vat_number = $additionalField['value'];
}
}
$empikOrder->add();
}
/**
* @return Cart
*/
public function getCart()
{
return $this->cart;
}
/**
* @param Cart $cart
*/
public function setCart($cart)
{
$this->cart = $cart;
}
/**
* @return OrderHistory[]
*/
public function getOrderHistory()
{
return $this->orderHistory;
}
/**
* @param OrderHistory[] $orderHistory
*/
public function setOrderHistory($orderHistory)
{
$this->orderHistory = $orderHistory;
}
/**
* @return OrderCarrier
*/
public function getCarrier()
{
return $this->carrier;
}
/**
* @param OrderCarrier $carrier
*/
public function setCarrier($carrier)
{
$this->carrier = $carrier;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* @param array $data
*/
public function setData($data)
{
$this->data = $data;
}
/**
* @return Order
*/
public function getOrder()
{
return $this->order;
}
/**
* @param Order $order
*/
public function setOrder($order)
{
$this->order = $order;
}
/**
* @return OrderDetail[]
*/
public function getOrderDetails()
{
return $this->orderDetails;
}
/**
* @param OrderDetail[] $orderDetails
*/
public function setOrderDetails($orderDetails)
{
$this->orderDetails = $orderDetails;
}
/**
* @return Customer
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param Customer $customer
*/
public function setCustomer($customer)
{
$this->customer = $customer;
}
/**
* @return Address
*/
public function getShippingAddress()
{
return $this->shippingAddress;
}
/**
* @param Address $shippingAddress
*/
public function setShippingAddress($shippingAddress)
{
$this->shippingAddress = $shippingAddress;
}
/**
* @return Address
*/
public function getBillingAddress()
{
return $this->billingAddress;
}
/**
* @param Address $billingAddress
*/
public function setBillingAddress($billingAddress)
{
$this->billingAddress = $billingAddress;
}
/**
* @return array
*/
public function getNotes(): array
{
return $this->notes;
}
/**
* @param array $notes
*/
public function setNotes(array $notes): void
{
$this->notes = $notes;
}
}

View File

@@ -66,6 +66,7 @@ class OrderFulfiller
// add addresses
$billingAddress = isset($data['customer']['billing_address']) ? $data['customer']['billing_address'] : null;
$shippingAddress = isset($data['customer']['shipping_address']) ? $data['customer']['shipping_address'] : null;
$additionalFields = isset($data['order_additional_fields']) ? $data['order_additional_fields'] : [];
$prestaShopShippingAddress = $this->addressProvider->provide(
$shippingAddress,
@@ -75,7 +76,8 @@ class OrderFulfiller
$prestaShopBillingAddress = $this->addressProvider->provide(
$billingAddress,
$order->getCustomer()
$order->getCustomer(),
$additionalFields
);
$order->setBillingAddress($prestaShopBillingAddress);

View File

@@ -0,0 +1,42 @@
<?php
namespace Empik\Marketplace\Processor;
use Empik\Marketplace\Manager\OrderManager;
use Empik\Marketplace\OrderFulfiller\OrderFulfiller;
use Empik\Marketplace\Repository\OrderRepository;
class OrdersProcessor
{
/** @var OrderRepository */
private $orderRepository;
/** @var OrderManager */
private $orderManager;
/** @var OrderFulfiller */
private $orderFulfiller;
public function __construct(
OrderRepository $orderRepository,
OrderManager $orderManager,
OrderFulfiller $orderFulfiller
)
{
$this->orderRepository = $orderRepository;
$this->orderManager = $orderManager;
$this->orderFulfiller = $orderFulfiller;
}
public function process($limit = 0, $step = 0)
{
$orders = $this->orderRepository->find($limit, $step);
foreach ($orders as $order) {
try {
$this->orderFulfiller->fulfill($order);
} catch (\Exception $e) {
}
}
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Empik\Marketplace\Provider;
class BillingAddressProvider
{
public function provide($address)
{
return [];
}
}

View File

@@ -27,7 +27,7 @@ class AddressProvider
* @param Customer $customer
* @return Address
*/
public function provide(array $addressData, Customer $customer)
public function provide(array $addressData, Customer $customer, array $additionalFields = [])
{
$address = $this->getAddress($addressData, $customer);
if ($address) {
@@ -58,6 +58,14 @@ class AddressProvider
$obj->address2 = $addressData['street_2'];
}
if ($additionalFields) {
foreach ($additionalFields as $additionalField) {
if ($additionalField['code'] === 'nip' && $additionalField['value']) {
$obj->vat_number = $additionalField['value'];
}
}
}
$obj->id_country = $this->getCountryId($addressData);
$obj->address1 = $addressData['street_1'];
$obj->city = $addressData['city'];
@@ -67,7 +75,7 @@ class AddressProvider
$obj->phone = !empty($addressData['phone']) ? $addressData['phone'] : null;
$obj->other = !empty($addressData['additional_info']) ? $addressData['additional_info'] : null;
$obj->alias = substr(
$obj->alias = mb_substr(
sprintf('%s - %s', $obj->city, $obj->address1),
0,
32

View File

@@ -0,0 +1,47 @@
<?php
namespace Empik\Marketplace\Provider\Order;
use Module;
use EmpikMarketplace;
class NotesProvider
{
/** @var EmpikMarketplace */
protected $module;
public function __construct()
{
$this->module = Module::getInstanceByName('empikmarketplace');
}
/**
* @param array $data
* @return array
*/
function provide($data)
{
$notes = [];
$notes[] = $this->module->l('Empik order reference:') . ' ' . $data['order_id'];
$notes[] = $this->module->l('Payment type:') . ' ' . $data['payment_type'];
$notes[] = $this->module->l('Shipping option name:') . ' ' . $data['shipping_type_label'];
foreach ($data['order_additional_fields'] as $additionalField) {
if ($additionalField['code'] === 'nip') {
$notes[] = $this->module->l('VAT number:') . ' ' . $additionalField['value'];
break;
}
}
foreach ($data['order_additional_fields'] as $additionalField) {
if ($additionalField['code'] === 'delivery-point-name') {
$notes[] = $this->module->l('Pickup point:') . ' ' . $additionalField['value'];
break;
}
}
return $notes;
}
}

View File

@@ -9,6 +9,10 @@ use Empik\Marketplace\Utils\IdentifierExtractor;
use OrderDetail;
use Context;
use Configuration;
use Product;
use ProductSupplier;
use TaxRulesGroup;
use TaxCalculator;
class OrderLinesProvider
{
@@ -70,10 +74,38 @@ class OrderLinesProvider
$obj->product_price = $orderLine['price_unit'];
$obj->unit_price_tax_incl = $orderLine['price_unit'];
$obj->unit_price_tax_excl = $orderLine['price_unit'];
$obj->total_price_tax_incl = $obj->unit_price_tax_incl * $obj->product_quantity;
$obj->total_price_tax_excl = $obj->total_price_tax_excl * $obj->product_quantity;
$taxRate = $this->getProductTaxRateByDefaultCountry($productData);
$taxRateMultiplier = (100 + $taxRate) / 100;
$obj->total_price_tax_excl = round($obj->total_price_tax_incl / $taxRateMultiplier, 6);
$obj->unit_price_tax_excl = round($obj->unit_price_tax_incl / $taxRateMultiplier, 6);
$obj->original_product_price = Product::getPriceStatic(
$obj->product_id,
false,
(int) $obj->product_attribute_id,
6,
null,
false,
false,
1,
false,
null,
null,
null,
$null,
true,
true,
$this->context
);
$obj->tax_computation_method = TaxCalculator::COMBINE_METHOD;
$obj->purchase_supplier_price = (float) $productData['wholesale_price'];
if ($productData['id_supplier'] > 0 && ($supplierPrice = ProductSupplier::getProductPrice((int) $productData['id_supplier'], $productData['id_product'], $productData['id_product_attribute'], true)) > 0) {
$obj->purchase_supplier_price = (float) $supplierPrice;
}
$obj->tax_rate = $taxRate;
$obj->id_tax_rules_group = $productData['id_tax_rules_group'];
$lines[] = $obj;
}
@@ -99,4 +131,21 @@ class OrderLinesProvider
return !empty($product) ? $product : false;
}
/**
* @param $productData
* @return float
*/
protected function getProductTaxRateByDefaultCountry($productData)
{
$taxRate = 0.00;
$defaultCountryId = Configuration::get('PS_COUNTRY_DEFAULT');
$taxRates = TaxRulesGroup::getAssociatedTaxRatesByIdCountry($defaultCountryId);
if (!empty($taxRates)) {
$taxRate = reset($taxRates);
}
return $taxRate;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Empik\Marketplace\Repository;
class OrderRepository
{
public function find($limit, $step)
{
}
}

View File

@@ -39,10 +39,11 @@ class ProductRepository
{
$sql = new DbQuery();
$sql->select('SQL_CALC_FOUND_ROWS ps.id_product, ps.price, p.active');
$sql->select('SQL_CALC_FOUND_ROWS ps.id_product, ps.price, ps.id_tax_rules_group, ps.wholesale_price, p.id_supplier, p.active');
$sql->select('p.upc, p.unity, p.width, p.height, p.depth, p.condition, p.additional_shipping_cost');
$sql->select('
IFNULL(epb.logistic_class, 0) AS logistic_class,
IFNULL(epb.condition, 0) AS empik_condition,
IFNULL(epb.product_export, 0) AS product_export,
IFNULL(epb.offer_export, 0) AS offer_export,
IFNULL(ep.offer_price, 0) AS offer_price,

View File

@@ -0,0 +1,46 @@
<?php
namespace Empik\Marketplace\Repository;
use Db;
use DbQuery;
use Empik\Marketplace\Utils\Utils;
class AttributeRepository
{
/** @var Db */
protected $db;
/** @var int */
protected $langId;
public function __construct()
{
$this->db = Db::getInstance();
$this->langId = Utils::getLangId();
}
public function getAttributes($productId, $productAttributeId)
{
$sql = new DbQuery();
$sql->select('al.name AS value, agl.public_name AS name');
$sql->from('attribute_group', 'ag');
$sql->leftJoin('attribute_group_lang', 'agl', 'agl.id_attribute_group = ag.id_attribute_group AND agl.id_lang = ' . (int)$this->langId);
$sql->leftJoin('product_attribute', 'pa', 'pa.id_product = ' . (int)$productId . ' AND pa.id_product_attribute = ' . (int)$productAttributeId);
$sql->leftJoin('product_attribute_combination', 'pac', 'pac.id_product_attribute = pa.id_product_attribute');
$sql->leftJoin('attribute', 'a', 'a.id_attribute = pac.id_attribute AND ag.id_attribute_group = a.id_attribute_group');
$sql->leftJoin('attribute_lang', 'al', 'al.id_attribute = a.id_attribute AND al.id_lang = ' . (int)$this->langId);
$sql->orderBy('ag.id_attribute_group');
$result = $this->db->executeS($sql);
$resultGrouped = [];
foreach ($result as $item) {
if (!isset($resultGrouped[$item['name']]) || $item['value']) {
$resultGrouped[$item['name']] = $item;
}
}
return (array)$resultGrouped;
}
}

View File

@@ -59,7 +59,9 @@ class IdentifierExtractor
$identifier = isset($product['ean13']) ? $product['ean13'] : '';
break;
case self::IDENTIFIER_SKU:
$identifier = isset($product['reference']) ? $product['reference'] : '';
// $identifier = isset($product['reference']) ? $product['reference'] : '';
$skuExtractor = new SkuExtractor();
$identifier = $skuExtractor->extract($product);
break;
default:
throw new LogicException(sprintf('Unknown identifier type: "%s"', $this->identifierType));

View File

@@ -39,6 +39,6 @@ class OfferPriceCalculator
$price += $this->addToPrice;
}
return Tools::ps_round(floor($price), self::ROUND_PRECISION);
return Tools::ps_round($price, self::ROUND_PRECISION);
}
}

View File

@@ -26,10 +26,6 @@ class OfferQuantityCalculator
$quantity = max($quantity - $this->stockReduce, 0);
if ( $quantity < 1 ) {
$quantity = 1;
}
return $quantity;
}
}