first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
drwxr-xr-x 2 30094 users 11 Oct 6 10:16 .
drwxr-xr-x 15 30094 users 16 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 2737 Oct 14 2021 CarrierDataProvider.php
-rw-r--r-- 1 30094 users 4589 Oct 14 2021 CartDataProvider.php
-rw-r--r-- 1 30094 users 2691 Oct 14 2021 CategoryDataProvider.php
-rw-r--r-- 1 30094 users 1550 Oct 14 2021 GoogleTaxonomyDataProvider.php
-rw-r--r-- 1 30094 users 1582 Oct 14 2021 ModuleDataProvider.php
-rw-r--r-- 1 30094 users 6422 Oct 14 2021 OrderDataProvider.php
-rw-r--r-- 1 30094 users 853 Oct 14 2021 PaginatedApiDataProviderInterface.php
-rw-r--r-- 1 30094 users 3139 Oct 14 2021 ProductDataProvider.php
-rw-r--r-- 1 30094 users 1273 Oct 14 2021 index.php

View File

@@ -0,0 +1,120 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use Currency;
use Language;
use PrestaShop\Module\PsEventbus\Builder\CarrierBuilder;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\DTO\Carrier as EventBusCarrier;
use PrestaShop\Module\PsEventbus\Repository\CarrierRepository;
use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository;
use PrestaShop\Module\PsEventbus\Repository\LanguageRepository;
class CarrierDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var ConfigurationRepository
*/
private $configurationRepository;
/**
* @var CarrierBuilder
*/
private $carrierBuilder;
/**
* @var CarrierRepository
*/
private $carrierRepository;
/**
* @var LanguageRepository
*/
private $languageRepository;
public function __construct(
ConfigurationRepository $configurationRepository,
CarrierBuilder $carrierBuilder,
CarrierRepository $carrierRepository,
LanguageRepository $languageRepository
) {
$this->configurationRepository = $configurationRepository;
$this->carrierBuilder = $carrierBuilder;
$this->carrierRepository = $carrierRepository;
$this->languageRepository = $languageRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso)
{
$language = new Language();
$currency = new Currency();
/** @var array $carriers */
$carriers = $this->carrierRepository->getAllCarrierProperties($offset, $limit, $language->id);
/** @var string $configurationPsWeightUnit */
$configurationPsWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT');
/** @var EventBusCarrier[] $eventBusCarriers */
$eventBusCarriers = $this->carrierBuilder->buildCarriers(
$carriers,
$language,
$currency,
$configurationPsWeightUnit
);
return $eventBusCarriers;
}
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
/** @var array $shippingIncremental */
$shippingIncremental = $this->carrierRepository->getShippingIncremental(Config::COLLECTION_CARRIERS, $langIso);
if (!$shippingIncremental) {
return [];
}
$language = new Language();
$currency = new Currency();
$carrierIds = array_column($shippingIncremental, 'id_object');
/** @var array $carriers */
$carriers = $this->carrierRepository->getCarrierProperties($carrierIds, $language->id);
/** @var string $configurationPsWeightUnit */
$configurationPsWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT');
/** @var EventBusCarrier[] $eventBusCarriers */
$eventBusCarriers = $this->carrierBuilder->buildCarriers(
$carriers,
$language,
$currency,
$configurationPsWeightUnit
);
return $eventBusCarriers;
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopDatabaseException
*/
public function getRemainingObjectsCount($offset, $langIso)
{
$langId = $this->languageRepository->getLanguageIdByIsoCode($langIso);
return (int) $this->carrierRepository->getRemainingCarriersCount($offset, $langId);
}
}

View File

@@ -0,0 +1,159 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CartProductRepository;
use PrestaShop\Module\PsEventbus\Repository\CartRepository;
class CartDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var CartRepository
*/
private $cartRepository;
/**
* @var CartProductRepository
*/
private $cartProductRepository;
/**
* @param CartRepository $cartRepository
* @param CartProductRepository $cartProductRepository
*/
public function __construct(
CartRepository $cartRepository,
CartProductRepository $cartProductRepository
) {
$this->cartRepository = $cartRepository;
$this->cartProductRepository = $cartProductRepository;
}
public function getFormattedData($offset, $limit, $langIso)
{
$carts = $this->cartRepository->getCarts($offset, $limit);
if (!is_array($carts)) {
return [];
}
$cartProducts = $this->getCartProducts($carts);
$this->castCartValues($carts);
$carts = array_map(function ($cart) {
return [
'id' => $cart['id_cart'],
'collection' => Config::COLLECTION_CARTS,
'properties' => $cart,
];
}, $carts);
return array_merge($carts, $cartProducts);
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*/
public function getRemainingObjectsCount($offset, $langIso)
{
return (int) $this->cartRepository->getRemainingCartsCount($offset);
}
/**
* @param array $carts
*
* @return void
*/
private function castCartValues(array &$carts)
{
foreach ($carts as &$cart) {
$cart['id_cart'] = (string) $cart['id_cart'];
}
}
/**
* @param array $cartProducts
*
* @return void
*/
private function castCartProductValues(array &$cartProducts)
{
foreach ($cartProducts as &$cartProduct) {
$cartProduct['id_cart_product'] = (string) "{$cartProduct['id_cart']}-{$cartProduct['id_product']}-{$cartProduct['id_product_attribute']}";
$cartProduct['id_cart'] = (string) $cartProduct['id_cart'];
$cartProduct['id_product'] = (string) $cartProduct['id_product'];
$cartProduct['id_product_attribute'] = (string) $cartProduct['id_product_attribute'];
$cartProduct['quantity'] = (int) $cartProduct['quantity'];
}
}
/**
* @param int $limit
* @param string $langIso
* @param array $objectIds
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
$carts = $this->cartRepository->getCartsIncremental($limit, $objectIds);
if (!is_array($carts) || empty($carts)) {
return [];
}
$cartProducts = $this->getCartProducts($carts);
$this->castCartValues($carts);
$carts = array_map(function ($cart) {
return [
'id' => $cart['id_cart'],
'collection' => Config::COLLECTION_CARTS,
'properties' => $cart,
];
}, $carts);
return array_merge($carts, $cartProducts);
}
/**
* @param array $carts
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
private function getCartProducts(array $carts)
{
$cartIds = array_map(function ($cart) {
return (string) $cart['id_cart'];
}, $carts);
$cartProducts = $this->cartProductRepository->getCartProducts($cartIds);
if (!is_array($cartProducts) || empty($cartProducts)) {
return [];
}
$this->castCartProductValues($cartProducts);
if (is_array($cartProducts)) {
return array_map(function ($cartProduct) {
return [
'id' => "{$cartProduct['id_cart']}-{$cartProduct['id_product']}-{$cartProduct['id_product_attribute']}",
'collection' => Config::COLLECTION_CART_PRODUCTS,
'properties' => $cartProduct,
];
}, $cartProducts);
}
return [];
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Decorator\CategoryDecorator;
use PrestaShop\Module\PsEventbus\Repository\CategoryRepository;
class CategoryDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var CategoryRepository
*/
private $categoryRepository;
/**
* @var CategoryDecorator
*/
private $categoryDecorator;
public function __construct(CategoryRepository $categoryRepository, CategoryDecorator $categoryDecorator)
{
$this->categoryRepository = $categoryRepository;
$this->categoryDecorator = $categoryDecorator;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso)
{
$categories = $this->categoryRepository->getCategories($offset, $limit, $langIso);
if (!is_array($categories)) {
return [];
}
$this->categoryDecorator->decorateCategories($categories);
return array_map(function ($category) {
return [
'id' => "{$category['id_category']}-{$category['iso_code']}",
'collection' => Config::COLLECTION_CATEGORIES,
'properties' => $category,
];
}, $categories);
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*/
public function getRemainingObjectsCount($offset, $langIso)
{
return (int) $this->categoryRepository->getRemainingCategoriesCount($offset, $langIso);
}
/**
* @param int $limit
* @param string $langIso
* @param array $objectIds
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
$categories = $this->categoryRepository->getCategoriesIncremental($limit, $langIso, $objectIds);
if (!is_array($categories)) {
return [];
}
$this->categoryDecorator->decorateCategories($categories);
return array_map(function ($category) {
return [
'id' => "{$category['id_category']}-{$category['iso_code']}",
'collection' => Config::COLLECTION_CATEGORIES,
'properties' => $category,
];
}, $categories);
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Decorator\CustomPriceDecorator;
use PrestaShop\Module\PsEventbus\Repository\CustomPriceRepository;
class CustomPriceDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var CustomPriceRepository
*/
private $customPriceRepository;
/**
* @var CustomPriceDecorator
*/
private $customPriceDecorator;
public function __construct(
CustomPriceRepository $customPriceRepository,
CustomPriceDecorator $customPriceDecorator
) {
$this->customPriceRepository = $customPriceRepository;
$this->customPriceDecorator = $customPriceDecorator;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso)
{
$specificPrices = $this->customPriceRepository->getSpecificPrices($offset, $limit);
$this->customPriceDecorator->decorateSpecificPrices($specificPrices);
return array_map(function ($specificPrice) {
return [
'id' => $specificPrice['id_specific_price'],
'collection' => Config::COLLECTION_SPECIFIC_PRICES,
'properties' => $specificPrice,
];
}, $specificPrices);
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopDatabaseException
*/
public function getRemainingObjectsCount($offset, $langIso)
{
return (int) $this->customPriceRepository->getRemainingSpecificPricesCount($offset);
}
/**
* @param int $limit
* @param string $langIso
* @param array $objectIds
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
$specificPrices = $this->customPriceRepository->getSpecificPricesIncremental($limit, $objectIds);
if (!empty($specificPrices)) {
$this->customPriceDecorator->decorateSpecificPrices($specificPrices);
} else {
return [];
}
return array_map(function ($specificPrice) {
return [
'id' => $specificPrice['id_specific_price'],
'collection' => Config::COLLECTION_SPECIFIC_PRICES,
'properties' => $specificPrice,
];
}, $specificPrices);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\ProductCarrierRepository;
class CustomProductCarrierDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var ProductCarrierRepository
*/
private $productCarrierRepository;
public function __construct(
ProductCarrierRepository $productCarrierRepository
) {
$this->productCarrierRepository = $productCarrierRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso)
{
$productCarriers = $this->productCarrierRepository->getProductCarriers($offset, $limit);
$productCarriers = array_map(function ($productCarrier) {
return [
'id' => $productCarrier['id_product'] . '-' . $productCarrier['id_carrier_reference'],
'collection' => Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS,
'properties' => $productCarrier,
];
}, $productCarriers);
return $productCarriers;
}
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
/** @var array $productCarrierIncremental */
$productCarrierIncremental = $this->productCarrierRepository->getProductCarrierIncremental(Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, $langIso);
if (!$productCarrierIncremental) {
return [];
}
$productIds = array_column($productCarrierIncremental, 'id_object');
/** @var array $productCarriers */
$productCarriers = $this->productCarrierRepository->getProductCarriersProperties($productIds);
return array_map(function ($productCarrier) {
return [
'id' => "{$productCarrier['id_product']}-{$productCarrier['id_carrier_reference']}",
'collection' => Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS,
'properties' => $productCarrier,
];
}, $productCarriers);
}
public function getRemainingObjectsCount($offset, $langIso)
{
return (int) $this->productCarrierRepository->getRemainingProductCarriersCount($offset);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use Context;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\GoogleTaxonomyRepository;
class GoogleTaxonomyDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var GoogleTaxonomyRepository
*/
private $googleTaxonomyRepository;
/**
* @var Context
*/
private $context;
public function __construct(GoogleTaxonomyRepository $googleTaxonomyRepository, Context $context)
{
$this->googleTaxonomyRepository = $googleTaxonomyRepository;
$this->context = $context;
}
public function getFormattedData($offset, $limit, $langIso)
{
/** @var int $shopId */
$shopId = $this->context->shop->id;
$data = $this->googleTaxonomyRepository->getTaxonomyCategories($offset, $limit, $shopId);
if (!is_array($data)) {
return [];
}
return array_map(function ($googleTaxonomy) {
$uniqueId = "{$googleTaxonomy['id_category']}-{$googleTaxonomy['id_category']}";
$googleTaxonomy['taxonomy_id'] = $uniqueId;
return [
'id' => $uniqueId,
'collection' => Config::COLLECTION_TAXONOMIES,
'properties' => $googleTaxonomy,
];
}, $data);
}
public function getRemainingObjectsCount($offset, $langIso)
{
/** @var int $shopId */
$shopId = $this->context->shop->id;
return (int) $this->googleTaxonomyRepository->getRemainingTaxonomyRepositories($offset, $shopId);
}
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
return [];
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\ModuleRepository;
use PrestaShop\Module\PsEventbus\Repository\ShopRepository;
class ModuleDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var ModuleRepository
*/
private $moduleRepository;
/**
* @var string
*/
private $createdAt;
public function __construct(ModuleRepository $moduleRepository, ShopRepository $shopRepository)
{
$this->moduleRepository = $moduleRepository;
$this->createdAt = $shopRepository->getCreatedAt();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*/
public function getFormattedData($offset, $limit, $langIso)
{
$modules = $this->moduleRepository->getModules($offset, $limit);
if (!is_array($modules)) {
return [];
}
return array_map(function ($module) {
$moduleId = (string) $module['module_id'];
$module['active'] = $module['active'] == '1';
$module['created_at'] = $module['created_at'] ?: $this->createdAt;
$module['updated_at'] = $module['updated_at'] ?: $this->createdAt;
return [
'id' => $moduleId,
'collection' => Config::COLLECTION_MODULES,
'properties' => $module,
];
}, $modules);
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*/
public function getRemainingObjectsCount($offset, $langIso)
{
return (int) $this->moduleRepository->getRemainingModules($offset);
}
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
return [];
}
}

View File

@@ -0,0 +1,327 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use Context;
use Language;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Formatter\ArrayFormatter;
use PrestaShop\Module\PsEventbus\Repository\OrderDetailsRepository;
use PrestaShop\Module\PsEventbus\Repository\OrderHistoryRepository;
use PrestaShop\Module\PsEventbus\Repository\OrderRepository;
use PrestaShopDatabaseException;
class OrderDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var OrderRepository
*/
private $orderRepository;
/**
* @var Context
*/
private $context;
/**
* @var ArrayFormatter
*/
private $arrayFormatter;
/**
* @var OrderDetailsRepository
*/
private $orderDetailsRepository;
/**
* @var OrderHistoryRepository
*/
private $orderHistoryRepository;
public function __construct(
Context $context,
OrderRepository $orderRepository,
OrderDetailsRepository $orderDetailsRepository,
ArrayFormatter $arrayFormatter,
OrderHistoryRepository $orderHistoryRepository
) {
$this->orderRepository = $orderRepository;
$this->context = $context;
$this->arrayFormatter = $arrayFormatter;
$this->orderDetailsRepository = $orderDetailsRepository;
$this->orderHistoryRepository = $orderHistoryRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso)
{
/** @var int $shopId */
$shopId = $this->context->shop->id;
$orders = $this->orderRepository->getOrders($offset, $limit, $shopId);
if (empty($orders)) {
return [];
}
$langId = (int) Language::getIdByIso($langIso);
$this->castOrderValues($orders, $langId);
$orderDetails = $this->getOrderDetails($orders, $shopId);
$orderStatuses = $this->getOrderStatuses($orders, $langId);
$orders = array_map(function ($order) {
return [
'id' => $order['id_order'],
'collection' => Config::COLLECTION_ORDERS,
'properties' => $order,
];
}, $orders);
return array_merge($orders, $orderDetails, $orderStatuses);
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*/
public function getRemainingObjectsCount($offset, $langIso)
{
/** @var int $shopId */
$shopId = $this->context->shop->id;
return (int) $this->orderRepository->getRemainingOrderCount($offset, $shopId);
}
/**
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
/** @var int $shopId */
$shopId = $this->context->shop->id;
$orders = $this->orderRepository->getOrdersIncremental($limit, $shopId, $objectIds);
if (!is_array($orders) || empty($orders)) {
return [];
}
$orderDetails = $this->getOrderDetails($orders, $shopId);
$this->castOrderValues($orders, (int) Language::getIdByIso($langIso));
$orders = array_map(function ($order) {
return [
'id' => $order['id_order'],
'collection' => Config::COLLECTION_ORDERS,
'properties' => $order,
];
}, $orders);
return array_merge($orders, $orderDetails);
}
/**
* @param array $orders
* @param int $shopId
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
private function getOrderDetails(array $orders, $shopId)
{
if (empty($orders)) {
return [];
}
$orderIds = $this->arrayFormatter->formatValueArray($orders, 'id_order');
$orderDetails = $this->orderDetailsRepository->getOrderDetails($orderIds, $shopId);
if (!is_array($orderDetails) || empty($orderDetails)) {
return [];
}
$this->castOrderDetailValues($orderDetails);
$orderDetails = array_map(function ($orderDetail) {
return [
'id' => $orderDetail['id_order_detail'],
'collection' => Config::COLLECTION_ORDER_DETAILS,
'properties' => $orderDetail,
];
}, $orderDetails);
return $orderDetails;
}
/**
* @param array $orders
* @param int $langId
*
* @return array|array[]
*
* @throws PrestaShopDatabaseException
*/
private function getOrderStatuses(array $orders, $langId)
{
if (empty($orders)) {
return [];
}
$orderIds = $this->arrayFormatter->formatValueArray($orders, 'id_order');
$orderHistoryStatuses = $this->orderHistoryRepository->getOrderHistoryStatuses($orderIds, $langId);
$orderHistoryStatuses = $this->castOrderStatuses($orderHistoryStatuses);
return array_map(function ($orderHistoryStatus) {
return [
'id' => $orderHistoryStatus['id_order_history'],
'collection' => Config::COLLECTION_ORDER_STATUS_HISTORY,
'properties' => $orderHistoryStatus,
];
}, $orderHistoryStatuses);
}
/**
* @param array $orders
* @param int $langId
*
* @return void
*
* @throws PrestaShopDatabaseException
*/
private function castOrderValues(array &$orders, int $langId)
{
foreach ($orders as &$order) {
$order['id_order'] = (int) $order['id_order'];
$order['id_customer'] = (int) $order['id_customer'];
$order['current_state'] = (int) $order['current_state'];
$order['conversion_rate'] = (float) $order['conversion_rate'];
$order['total_paid_tax_incl'] = (float) $order['total_paid_tax_incl'];
$order['total_paid_tax_excl'] = (float) $order['total_paid_tax_excl'];
$order['refund'] = (float) $order['refund'];
$order['refund_tax_excl'] = (float) $order['refund_tax_excl'];
$order['new_customer'] = $order['new_customer'] == 1;
$order['is_paid'] = $this->castIsPaidValue($orders, $order, $langId);
$order['shipping_cost'] = (float) $order['shipping_cost'];
$order['total_paid_tax'] = $order['total_paid_tax_incl'] - $order['total_paid_tax_excl'];
$order['id_carrier'] = (int) $order['id_carrier'];
$this->castAddressIsoCodes($order);
unset($order['address_iso']);
}
}
/**
* @param array $orders
* @param array $order
* @param int $langId
*
* @return bool
*
* @throws PrestaShopDatabaseException
*/
private function castIsPaidValue(array $orders, array $order, int $langId)
{
$isPaid = $dateAdd = 0;
$orderIds = $this->arrayFormatter->formatValueArray($orders, 'id_order');
/** @var array $orderHistoryStatuses */
$orderHistoryStatuses = $this->orderHistoryRepository->getOrderHistoryStatuses($orderIds, $langId);
foreach ($orderHistoryStatuses as &$orderHistoryStatus) {
if ($order['id_order'] == $orderHistoryStatus['id_order'] && $dateAdd < $orderHistoryStatus['date_add']) {
$isPaid = (bool) $orderHistoryStatus['paid'];
$dateAdd = $orderHistoryStatus['date_add'];
}
}
return (bool) $isPaid;
}
/**
* @param array $orderDetails
*
* @return void
*/
private function castOrderDetailValues(array &$orderDetails)
{
foreach ($orderDetails as &$orderDetail) {
$orderDetail['id_order_detail'] = (int) $orderDetail['id_order_detail'];
$orderDetail['id_order'] = (int) $orderDetail['id_order'];
$orderDetail['product_id'] = (int) $orderDetail['product_id'];
$orderDetail['product_attribute_id'] = (int) $orderDetail['product_attribute_id'];
$orderDetail['product_quantity'] = (int) $orderDetail['product_quantity'];
$orderDetail['unit_price_tax_incl'] = (float) $orderDetail['unit_price_tax_incl'];
$orderDetail['unit_price_tax_excl'] = (float) $orderDetail['unit_price_tax_excl'];
$orderDetail['refund'] = (float) $orderDetail['refund'] > 0 ? -1 * (float) $orderDetail['refund'] : 0;
$orderDetail['refund_tax_excl'] = (float) $orderDetail['refund_tax_excl'] > 0 ? -1 * (float) $orderDetail['refund_tax_excl'] : 0;
$orderDetail['category'] = (int) $orderDetail['category'];
$orderDetail['unique_product_id'] = "{$orderDetail['product_id']}-{$orderDetail['product_attribute_id']}-{$orderDetail['iso_code']}";
$orderDetail['conversion_rate'] = (float) $orderDetail['conversion_rate'];
}
}
private function castOrderStatuses(array &$orderStatuses): array
{
$castedOrderStatuses = [];
foreach ($orderStatuses as $orderStatus) {
$castedOrderStatus = [];
$castedOrderStatus['id_order_state'] = (int) $orderStatus['id_order_state'];
$castedOrderStatus['id_order'] = (int) $orderStatus['id_order'];
$castedOrderStatus['id_order_history'] = (int) $orderStatus['id_order_history'];
$castedOrderStatus['name'] = (string) $orderStatus['name'];
$castedOrderStatus['template'] = (string) $orderStatus['template'];
$castedOrderStatus['date_add'] = (string) $orderStatus['date_add'];
$castedOrderStatus['is_validated'] = (bool) $orderStatus['logable'];
$castedOrderStatus['is_delivered'] = (bool) $orderStatus['delivery'];
$castedOrderStatus['is_shipped'] = (bool) $orderStatus['shipped'];
$castedOrderStatus['is_paid'] = (bool) $orderStatus['paid'];
$castedOrderStatus['is_deleted'] = (bool) $orderStatus['deleted'];
$castedOrderStatuses[] = $castedOrderStatus;
}
return $castedOrderStatuses;
}
/**
* @param array $orderDetail
*
* @return void
*/
private function castAddressIsoCodes(&$orderDetail)
{
if (!$orderDetail['address_iso']) {
$orderDetail['invoice_country_code'] = null;
$orderDetail['delivery_country_code'] = null;
return;
}
$addressAndIsoCodes = explode(',', $orderDetail['address_iso']);
if (count($addressAndIsoCodes) === 1) {
$addressAndIsoCode = explode(':', $addressAndIsoCodes[0]);
$orderDetail['invoice_country_code'] = $addressAndIsoCode[1];
$orderDetail['delivery_country_code'] = $addressAndIsoCode[1];
return;
}
foreach ($addressAndIsoCodes as $addressAndIsoCodeString) {
$addressAndIsoCode = explode(':', $addressAndIsoCodeString);
if ($addressAndIsoCode[0] === 'delivery') {
$orderDetail['delivery_country_code'] = $addressAndIsoCode[1];
} elseif ($addressAndIsoCode[0] === 'invoice') {
$orderDetail['invoice_country_code'] = $addressAndIsoCode[1];
}
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShopDatabaseException;
interface PaginatedApiDataProviderInterface
{
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso);
/**
* @param int $offset
* @param string $langIso
*
* @return int
*
* @throws PrestaShopDatabaseException
*/
public function getRemainingObjectsCount($offset, $langIso);
/**
* @param int $limit
* @param string $langIso
* @param array $objectIds
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public function getFormattedDataIncremental($limit, $langIso, $objectIds);
}

View File

@@ -0,0 +1,117 @@
<?php
namespace PrestaShop\Module\PsEventbus\Provider;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Decorator\ProductDecorator;
use PrestaShop\Module\PsEventbus\Repository\LanguageRepository;
use PrestaShop\Module\PsEventbus\Repository\ProductRepository;
class ProductDataProvider implements PaginatedApiDataProviderInterface
{
/**
* @var ProductRepository
*/
private $productRepository;
/**
* @var ProductDecorator
*/
private $productDecorator;
/**
* @var LanguageRepository
*/
private $languageRepository;
public function __construct(
ProductRepository $productRepository,
ProductDecorator $productDecorator,
LanguageRepository $languageRepository
) {
$this->productRepository = $productRepository;
$this->productDecorator = $productDecorator;
$this->languageRepository = $languageRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedData($offset, $limit, $langIso)
{
$langId = $this->languageRepository->getLanguageIdByIsoCode($langIso);
$products = $this->productRepository->getProducts($offset, $limit, $langId);
if (!$products) {
return [];
}
$this->productDecorator->decorateProducts($products, $langIso, $langId);
$bundles = $this->productDecorator->getBundles($products);
$products = array_map(function ($product) {
return [
'id' => $product['unique_product_id'],
'collection' => Config::COLLECTION_PRODUCTS,
'properties' => $product,
];
}, $products);
return array_merge($products, $bundles);
}
/**
* @param int $offset
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopDatabaseException
*/
public function getRemainingObjectsCount($offset, $langIso)
{
$langId = $this->languageRepository->getLanguageIdByIsoCode($langIso);
return (int) $this->productRepository->getRemainingProductsCount($offset, $langId);
}
/**
* @param int $limit
* @param string $langIso
* @param array $objectIds
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getFormattedDataIncremental($limit, $langIso, $objectIds)
{
$langId = $this->languageRepository->getLanguageIdByIsoCode($langIso);
$products = $this->productRepository->getProductsIncremental($limit, $langId, $objectIds);
if (!empty($products)) {
$this->productDecorator->decorateProducts($products, $langIso, $langId);
} else {
return [];
}
$orderDetails = $this->productDecorator->getBundles($products);
$products = array_map(function ($product) {
return [
'id' => $product['unique_product_id'],
'collection' => Config::COLLECTION_PRODUCTS,
'properties' => $product,
];
}, $products);
return array_merge($products, $orderDetails);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2020 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;