ver. 0.292: ShopProduct + ShopPaymentMethod + ShopPromotion + ShopStatuses + ShopTransport frontend migration to Domain

Full migration of front\factory\ — entire directory removed (all 20 classes migrated).
ProductRepository +20 frontend methods, PromotionRepository +5 applyType methods,
TransportRepository +4 cached methods, PaymentMethodRepository +cached frontend methods.
Fix: broken transports_list() in ajax.php replaced with forPaymentMethod().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 21:55:16 +01:00
parent 6181ef958d
commit d14018a5f3
48 changed files with 1780 additions and 975 deletions

View File

@@ -132,7 +132,7 @@ class OrderAdminService
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'id' => (int)$order['apilo_order_id'],
'status' => (int)\front\factory\ShopStatuses::get_apilo_status_id($newStatus),
'status' => (int)( new \Domain\ShopStatus\ShopStatusRepository($this->db) )->getApiloStatusId( (int)$newStatus ),
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken,

View File

@@ -558,8 +558,8 @@ class OrderRepository
return false;
}
$transport = \front\factory\ShopTransport::transport($transport_id);
$payment_method = \front\factory\ShopPaymentMethod::payment_method($payment_id);
$transport = ( new \Domain\Transport\TransportRepository( $this->db ) )->findActiveByIdCached( $transport_id );
$payment_method = ( new \Domain\PaymentMethod\PaymentMethodRepository( $this->db ) )->findActiveById( (int)$payment_id );
$basket_summary = \Domain\Basket\BasketCalculator::summaryPrice($basket, $coupon);
$order_number = $this->generateOrderNumber();
$order_date = date('Y-m-d H:i:s');

View File

@@ -257,6 +257,67 @@ class PaymentMethodRepository
return $result;
}
/**
* Metody platnosci dla danego transportu — z Redis cache (frontend).
*
* @return array<int, array<string, mixed>>
*/
public function paymentMethodsByTransport(int $transportMethodId): array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_methods_by_transport' . $transportMethodId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$result = $this->forTransport($transportMethodId);
$cacheHandler->set($cacheKey, $result);
return $result;
}
/**
* Pojedyncza aktywna metoda platnosci — z Redis cache (frontend).
*/
public function paymentMethodCached(int $paymentMethodId): ?array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_method' . $paymentMethodId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$result = $this->findActiveById($paymentMethodId);
$cacheHandler->set($cacheKey, $result);
return $result;
}
/**
* Wszystkie aktywne metody platnosci — z Redis cache (frontend).
*
* @return array<int, array<string, mixed>>
*/
public function paymentMethodsCached(): array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_methods';
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$result = $this->allActive();
$cacheHandler->set($cacheKey, $result);
return $result;
}
private function normalizePaymentMethod(array $row): array
{
$row['id'] = (int)($row['id'] ?? 0);

View File

@@ -1848,4 +1848,399 @@ class ProductRepository
], [ 'id' => $row['id'] ] );
}
}
// =========================================================================
// Frontend methods (migrated from front\factory\ShopProduct)
// =========================================================================
/**
* @return string|null
*/
public function getSkuWithFallback(int $productId, bool $withParentFallback = false)
{
if ($productId <= 0) {
return null;
}
$sku = $this->db->get('pp_shop_products', 'sku', ['id' => $productId]);
if (!$sku && $withParentFallback) {
$parentId = $this->db->get('pp_shop_products', 'parent_id', ['id' => $productId]);
if ($parentId) {
return $this->getSkuWithFallback((int)$parentId, true);
}
return null;
}
return $sku ? (string)$sku : null;
}
/**
* @return string|null
*/
public function getEanWithFallback(int $productId, bool $withParentFallback = false)
{
if ($productId <= 0) {
return null;
}
$ean = $this->db->get('pp_shop_products', 'ean', ['id' => $productId]);
if (!$ean && $withParentFallback) {
$parentId = $this->db->get('pp_shop_products', 'parent_id', ['id' => $productId]);
if ($parentId) {
return $this->getEanWithFallback((int)$parentId, true);
}
return null;
}
return $ean ? (string)$ean : null;
}
public function isProductActiveCached(int $productId): int
{
if ($productId <= 0) {
return 0;
}
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'is_product_active:' . $productId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return (int)unserialize($cached) === 1 ? 1 : 0;
}
$status = $this->db->get('pp_shop_products', 'status', ['id' => $productId]);
$cacheHandler->set($cacheKey, $status);
return (int)$status === 1 ? 1 : 0;
}
/**
* @return string|null
*/
public function getMinimalPriceCached(int $productId, $priceBruttoPromo = null)
{
if ($productId <= 0) {
return null;
}
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'get_minimal_price:' . $productId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$price = $this->db->min('pp_shop_product_price_history', 'price', [
'AND' => [
'id_product' => $productId,
'price[!]' => str_replace(',', '.', $priceBruttoPromo),
],
]);
$cacheHandler->set($cacheKey, $price);
return $price;
}
/**
* @return array<int, array<string, mixed>>
*/
public function productCategoriesFront(int $productId): array
{
if ($productId <= 0) {
return [];
}
$parentId = $this->db->get('pp_shop_products', 'parent_id', ['id' => $productId]);
$targetId = $parentId ? (int)$parentId : $productId;
$stmt = $this->db->query(
'SELECT category_id FROM pp_shop_products_categories WHERE product_id = :pid',
[':pid' => $targetId]
);
return $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
}
/**
* @return string|null
*/
public function getProductNameCached(int $productId, string $langId)
{
if ($productId <= 0) {
return null;
}
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_name' . $langId . '_' . $productId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$name = $this->db->get('pp_shop_products_langs', 'name', [
'AND' => ['product_id' => $productId, 'lang_id' => $langId],
]);
$cacheHandler->set($cacheKey, $name);
return $name;
}
/**
* @return string|null
*/
public function getFirstImageCached(int $productId)
{
if ($productId <= 0) {
return null;
}
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_image:' . $productId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$stmt = $this->db->query(
'SELECT src FROM pp_shop_products_images WHERE product_id = :pid ORDER BY o ASC LIMIT 1',
[':pid' => $productId]
);
$rows = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
$image = isset($rows[0]['src']) ? $rows[0]['src'] : null;
$cacheHandler->set($cacheKey, $image);
return $image;
}
public function getWeightCached(int $productId)
{
if ($productId <= 0) {
return null;
}
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_wp:' . $productId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$wp = $this->db->get('pp_shop_products', 'wp', ['id' => $productId]);
$cacheHandler->set($cacheKey, $wp);
return $wp;
}
/**
* @return array<int, int>
*/
public function promotedProductIdsCached(int $limit = 6): array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'promoted_products-' . $limit;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$stmt = $this->db->query(
'SELECT id FROM pp_shop_products WHERE status = 1 AND promoted = 1 ORDER BY RAND() LIMIT ' . (int)$limit
);
$rows = $stmt ? $stmt->fetchAll() : [];
$products = [];
if (is_array($rows)) {
foreach ($rows as $row) {
$products[] = (int)$row['id'];
}
}
$cacheHandler->set($cacheKey, $products);
return $products;
}
/**
* @return array<int, int>
*/
public function topProductIds(int $limit = 6): array
{
$date30 = date('Y-m-d', strtotime('-30 days'));
$stmt = $this->db->query(
"SELECT COUNT(0) AS sell_count, psop.parent_product_id
FROM pp_shop_order_products AS psop
INNER JOIN pp_shop_orders AS pso ON pso.id = psop.order_id
WHERE pso.date_order >= :d
GROUP BY parent_product_id
ORDER BY sell_count DESC",
[':d' => $date30]
);
$rows = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
$ids = [];
foreach ($rows as $row) {
if ($this->isProductActiveCached((int)$row['parent_product_id'])) {
$ids[] = (int)$row['parent_product_id'];
}
}
return $ids;
}
/**
* @return array<int, int>
*/
public function newProductIds(int $limit = 10): array
{
$stmt = $this->db->query(
'SELECT id FROM pp_shop_products WHERE status = 1 ORDER BY date_add DESC LIMIT ' . (int)$limit
);
$rows = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
return array_column($rows, 'id');
}
/**
* @return array|null
*/
public function productDetailsFrontCached(int $productId, string $langId)
{
if ($productId <= 0) {
return null;
}
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_details_front:' . $productId . ':' . $langId;
$cached = $cacheHandler->get($cacheKey);
if ($cached) {
return unserialize($cached);
}
$product = $this->db->get('pp_shop_products', '*', ['id' => $productId]);
if (!is_array($product)) {
return null;
}
// language
$langRows = $this->db->select('pp_shop_products_langs', '*', [
'AND' => ['product_id' => $productId, 'lang_id' => $langId],
]);
if (is_array($langRows)) {
foreach ($langRows as $row) {
if ($row['copy_from']) {
$copyRows = $this->db->select('pp_shop_products_langs', '*', [
'AND' => ['product_id' => $productId, 'lang_id' => $row['copy_from']],
]);
if (is_array($copyRows)) {
foreach ($copyRows as $row2) {
$product['language'] = $row2;
}
}
} else {
$product['language'] = $row;
}
}
}
// attributes
$attrStmt = $this->db->query(
'SELECT DISTINCT(attribute_id) FROM pp_shop_products_attributes AS pspa '
. 'INNER JOIN pp_shop_attributes AS psa ON psa.id = pspa.attribute_id '
. 'WHERE product_id = ' . $productId . ' ORDER BY o ASC'
);
$attrRows = $attrStmt ? $attrStmt->fetchAll() : [];
if (is_array($attrRows)) {
foreach ($attrRows as $row) {
$row['type'] = $this->db->get('pp_shop_attributes', 'type', ['id' => $row['attribute_id']]);
$row['language'] = $this->db->get('pp_shop_attributes_langs', ['name'], [
'AND' => ['attribute_id' => $row['attribute_id'], 'lang_id' => $langId],
]);
$valStmt = $this->db->query(
'SELECT value_id, is_default FROM pp_shop_products_attributes AS pspa '
. 'INNER JOIN pp_shop_attributes_values AS psav ON psav.id = pspa.value_id '
. 'WHERE product_id = :pid AND pspa.attribute_id = :aid',
[':pid' => $productId, ':aid' => $row['attribute_id']]
);
$valRows = $valStmt ? $valStmt->fetchAll(\PDO::FETCH_ASSOC) : [];
if (is_array($valRows)) {
foreach ($valRows as $row2) {
$row2['language'] = $this->db->get('pp_shop_attributes_values_langs', ['name', 'value'], [
'AND' => ['value_id' => $row2['value_id'], 'lang_id' => $langId],
]);
$row['values'][] = $row2;
}
}
$product['attributes'][] = $row;
}
}
$product['images'] = $this->db->select('pp_shop_products_images', '*', [
'product_id' => $productId,
'ORDER' => ['o' => 'ASC', 'id' => 'ASC'],
]);
$product['files'] = $this->db->select('pp_shop_products_files', '*', ['product_id' => $productId]);
$product['categories'] = $this->db->select('pp_shop_products_categories', 'category_id', ['product_id' => $productId]);
$product['products_related'] = $this->db->select('pp_shop_products_related', 'product_related_id', ['product_id' => $productId]);
$setId = $this->db->select('pp_shop_product_sets_products', 'set_id', ['product_id' => $productId]);
$productsSets = $this->db->select('pp_shop_product_sets_products', 'product_id', ['set_id' => (int)$setId]);
$product['products_sets'] = is_array($productsSets) ? array_unique($productsSets) : [];
$attributes = $this->db->select('pp_shop_products_attributes', ['attribute_id', 'value_id'], ['product_id' => $productId]);
$attributesTmp = [];
if (is_array($attributes)) {
foreach ($attributes as $attr) {
$attributesTmp[$attr['attribute_id']][] = $attr['value_id'];
}
}
if (!empty($attributesTmp)) {
$product['permutations'] = \Shared\Helpers\Helpers::array_cartesian_product($attributesTmp);
}
$cacheHandler->set($cacheKey, $product);
return $product;
}
/**
* @return string|null
*/
public function getWarehouseMessageZero(int $productId, string $langId)
{
if ($productId <= 0) {
return null;
}
return $this->db->get('pp_shop_products_langs', 'warehouse_message_zero', [
'AND' => ['product_id' => $productId, 'lang_id' => $langId],
]);
}
/**
* @return string|null
*/
public function getWarehouseMessageNonzero(int $productId, string $langId)
{
if ($productId <= 0) {
return null;
}
return $this->db->get('pp_shop_products_langs', 'warehouse_message_nonzero', [
'AND' => ['product_id' => $productId, 'lang_id' => $langId],
]);
}
}

View File

@@ -419,4 +419,217 @@ class PromotionRepository
// Cache invalidation should not block save/delete.
}
}
// =========================================================================
// Frontend: basket promotion logic (migrated from front\factory\ShopPromotion)
// =========================================================================
/**
* Promocja na cały koszyk (condition_type=4)
*/
public function applyTypeWholeBasket(array $basket, $promotion): array
{
$productRepo = new \Domain\Product\ProductRepository( $this->db );
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion->include_product_promo )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
$basket[$key]['discount_type'] = $promotion->discount_type;
$basket[$key]['discount_amount'] = $promotion->amount;
$basket[$key]['discount_include_coupon'] = $promotion->include_coupon;
$basket[$key]['include_product_promo'] = $promotion->include_product_promo;
}
}
}
return $basket;
}
/**
* Promocja na najtańszy produkt z kategorii 1 lub 2 (condition_type=3)
*/
public function applyTypeCheapestProduct(array $basket, $promotion): array
{
$productRepo = new \Domain\Product\ProductRepository( $this->db );
$condition_1 = false;
$categories = json_decode( $promotion->categories );
if ( is_array( $categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion->include_product_promo )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( !$condition_1[$key] and in_array( $category_tmp['category_id'], $categories ) )
$condition_1[$key] = true;
}
}
}
}
if ( count( $condition_1 ) >= $promotion->min_product_count )
{
$cheapest_position = false;
foreach ( $basket as $key => $val )
{
$price = \shop\Product::get_product_price( $val['product-id'] );
if ( !$cheapest_position or $cheapest_position['price'] > $price )
{
$cheapest_position['price'] = $price;
$cheapest_position['key'] = $key;
}
}
$basket[$cheapest_position['key']]['quantity'] = 1;
$basket[$cheapest_position['key']]['discount_type'] = 3;
$basket[$cheapest_position['key']]['discount_amount'] = $promotion->price_cheapest_product;
$basket[$cheapest_position['key']]['discount_include_coupon'] = $promotion->include_coupon;
$basket[$cheapest_position['key']]['include_product_promo'] = $promotion->include_product_promo;
}
return $basket;
}
/**
* Promocja na wszystkie produkty z kategorii 1 lub 2 (condition_type=5)
*/
public function applyTypeCategoriesOr(array $basket, $promotion): array
{
$productRepo = new \Domain\Product\ProductRepository( $this->db );
$categories = json_decode( $promotion->categories );
$condition_categories = json_decode( $promotion->condition_categories );
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion->include_product_promo )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp['category_id'], $condition_categories ) or in_array( $category_tmp['category_id'], $categories ) )
{
$basket[$key]['discount_type'] = $promotion->discount_type;
$basket[$key]['discount_amount'] = $promotion->amount;
$basket[$key]['discount_include_coupon'] = $promotion->include_coupon;
$basket[$key]['include_product_promo'] = $promotion->include_product_promo;
}
}
}
}
return $basket;
}
/**
* Promocja na produkty z kategorii 1 i 2 (condition_type=2)
*/
public function applyTypeCategoriesAnd(array $basket, $promotion): array
{
$productRepo = new \Domain\Product\ProductRepository( $this->db );
$condition_1 = false;
$condition_2 = false;
$categories = json_decode( $promotion->categories );
$condition_categories = json_decode( $promotion->condition_categories );
if ( is_array( $condition_categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( !$condition_1 and in_array( $category_tmp['category_id'], $condition_categories ) )
{
$condition_1 = true;
}
}
}
foreach ( $basket as $key => $val )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( !$condition_2 and in_array( $category_tmp['category_id'], $categories ) )
$condition_2 = true;
}
}
}
if ( $condition_1 and $condition_2 )
{
foreach ( $basket as $key => $val )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp['category_id'], $categories ) or in_array( $category_tmp['category_id'], $condition_categories ) )
{
$basket[$key]['discount_type'] = $promotion->discount_type;
$basket[$key]['discount_amount'] = $promotion->amount;
$basket[$key]['discount_include_coupon'] = $promotion->include_coupon;
$basket[$key]['include_product_promo'] = $promotion->include_product_promo;
}
}
}
}
return $basket;
}
/**
* Rabat procentowy na produkty z kategorii I jeżeli w koszyku jest produkt z kategorii II (condition_type=1)
*/
public function applyTypeCategoryCondition(array $basket, $promotion): array
{
$productRepo = new \Domain\Product\ProductRepository( $this->db );
$condition = false;
$categories = json_decode( $promotion->categories );
$condition_categories = json_decode( $promotion->condition_categories );
if ( is_array( $condition_categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp['category_id'], $condition_categories ) )
{
$condition = true;
}
}
}
}
if ( $condition )
{
foreach ( $basket as $key => $val )
{
$product_categories = $productRepo->productCategoriesFront( (int) $val['product-id'] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp['category_id'], $categories ) )
{
$basket[$key]['discount_type'] = $promotion->discount_type;
$basket[$key]['discount_amount'] = $promotion->amount;
$basket[$key]['discount_include_coupon'] = $promotion->include_coupon;
$basket[$key]['include_product_promo'] = $promotion->include_product_promo;
}
}
}
}
return $basket;
}
}

View File

@@ -287,6 +287,135 @@ class TransportRepository
return $transports;
}
// =========================================================================
// Frontend methods (migrated from front\factory\ShopTransport)
// =========================================================================
/**
* Lista metod transportu dla koszyka (z filtrowaniem wagi + darmowa dostawa)
*/
public function transportMethodsFront( $basket, $coupon ): array
{
global $settings;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport_methods_front';
$cached = $cacheHandler->get( $cacheKey );
if ( $cached )
{
$transports_tmp = unserialize( $cached );
}
else
{
$transports_tmp = $this->allActive();
$cacheHandler->set( $cacheKey, $transports_tmp );
}
$wp_summary = \Domain\Basket\BasketCalculator::summaryWp( $basket );
$transports = [];
foreach ( $transports_tmp as $tr )
{
if ( $tr['max_wp'] == null )
$transports[] = $tr;
elseif ( $tr['max_wp'] != null and $wp_summary <= $tr['max_wp'] )
$transports[] = $tr;
}
if ( \Shared\Helpers\Helpers::normalize_decimal( \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ) ) >= \Shared\Helpers\Helpers::normalize_decimal( $settings['free_delivery'] ) )
{
for ( $i = 0; $i < count( $transports ); $i++ ) {
if ( $transports[$i]['delivery_free'] == 1 ) {
$transports[$i]['cost'] = 0.00;
}
}
}
return $transports;
}
/**
* Koszt transportu z cache
*/
public function transportCostCached( $transportId )
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport_cost_' . $transportId;
$cached = $cacheHandler->get( $cacheKey );
if ( $cached )
{
return unserialize( $cached );
}
$cost = $this->getTransportCost( (int)$transportId );
$cacheHandler->set( $cacheKey, $cost );
return $cost;
}
/**
* Aktywny transport z cache
*/
public function findActiveByIdCached( $transportId )
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport' . $transportId;
$cached = $cacheHandler->get( $cacheKey );
if ( $cached )
{
return unserialize( $cached );
}
$transport = $this->findActiveById( (int)$transportId );
$cacheHandler->set( $cacheKey, $transport );
return $transport;
}
/**
* Transporty powiązane z metodą płatności
*/
public function forPaymentMethod( int $paymentMethodId ): array
{
if ( $paymentMethodId <= 0 )
{
return [];
}
$transportIds = $this->db->select(
'pp_shop_transport_payment_methods',
'id_transport',
['id_payment_method' => $paymentMethodId]
);
if ( !is_array( $transportIds ) || empty( $transportIds ) )
{
return [];
}
$transports = $this->db->select(
'pp_shop_transports',
'*',
['AND' => ['id' => $transportIds, 'status' => 1], 'ORDER' => ['o' => 'ASC']]
);
if ( !is_array( $transports ) )
{
return [];
}
foreach ( $transports as &$transport )
{
$transport = $this->normalizeTransport( $transport );
}
unset( $transport );
return $transports;
}
private function savePaymentMethodLinks(int $transportId, $paymentMethods): void
{
if (is_array($paymentMethods)) {

View File

@@ -192,7 +192,7 @@ class ShopOrderController
'order' => $this->service->details($orderId),
'order_statuses' => $this->service->statuses(),
'transport' => \shop\Transport::transport_list(),
'payment_methods' => \shop\PaymentMethod::method_list(),
'payment_methods' => ( new \Domain\PaymentMethod\PaymentMethodRepository( $GLOBALS['mdb'] ) )->allActive(),
]);
}

View File

@@ -8,10 +8,12 @@ class ShopBasketController
];
private $orderRepository;
private $paymentMethodRepository;
public function __construct( \Domain\Order\OrderRepository $orderRepository )
public function __construct( \Domain\Order\OrderRepository $orderRepository, \Domain\PaymentMethod\PaymentMethodRepository $paymentMethodRepository )
{
$this->orderRepository = $orderRepository;
$this->paymentMethodRepository = $paymentMethodRepository;
}
public function basketMessageSave()
@@ -146,7 +148,7 @@ class ShopBasketController
$values['attributes'] = $attributes;
}
$values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] );
$values['wp'] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getWeightCached( (int)$values[ 'product-id' ] );
$attributes_implode = '';
if ( is_array( $attributes ) and count( $attributes ) > 0 )
@@ -247,8 +249,8 @@ class ShopBasketController
echo json_encode( [
'result' => 'ok',
'payment_methods' => \front\view\ShopPaymentMethod::basket_payment_methods(
\front\factory\ShopPaymentMethod::payment_methods_by_transport( \Shared\Helpers\Helpers::get( 'transport_method_id' ) ),
'payment_methods' => \front\Views\ShopPaymentMethod::basketPaymentMethods(
$this->paymentMethodRepository->paymentMethodsByTransport( (int)\Shared\Helpers\Helpers::get( 'transport_method_id' ) ),
\Shared\Helpers\Helpers::get( 'payment_method_id' )
)
] );
@@ -271,8 +273,8 @@ class ShopBasketController
'lang_id' => $lang_id,
'client' => \Shared\Helpers\Helpers::get_session( 'client' ),
'basket' => \Shared\Helpers\Helpers::get_session( 'basket' ),
'transport' => \front\factory\ShopTransport::transport( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) ),
'payment_method' => \front\factory\ShopPaymentMethod::payment_method( \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) ),
'transport' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->findActiveByIdCached( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) ),
'payment_method' => $this->paymentMethodRepository->paymentMethodCached( (int)\Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) ),
'addresses' => ( new \Domain\Client\ClientRepository( $GLOBALS['mdb'] ) )->clientAddresses( (int)$client['id'] ),
'settings' => $settings,
'coupon' => \Shared\Helpers\Helpers::get_session( 'coupon' ),
@@ -368,7 +370,7 @@ class ShopBasketController
'coupon' => $coupon,
'transport_id' => \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ),
'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transports_methods' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->transportMethodsFront( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] ),
'payment_method_id' => $payment_method_id,
@@ -394,7 +396,7 @@ class ShopBasketController
'basket_mini_value' => \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ),
'products_count' => count( $basket ),
'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transports_methods' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->transportMethodsFront( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] )
] );

View File

@@ -95,7 +95,7 @@ class ShopOrderController
if ( is_array( $order['products'] ) && count( $order['products'] ) ):
$summary_tmp = 0;
foreach ( $order['products'] as $product ):
$product_tmp = \front\factory\ShopProduct::product_details( $product['product_id'], $lang['id'] );
$product_tmp = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->productDetailsFrontCached( (int)$product['product_id'], $lang['id'] );
$summary_tmp += \Shared\Helpers\Helpers::normalize_decimal( $product['price_netto'] + $product['price_netto'] * $product['vat'] / 100 ) * $product['quantity'];
endforeach;
$summary_tmp += $order['transport_cost'];

View File

@@ -1,21 +1,32 @@
<?php
namespace front\controls;
use shop\Product;
namespace front\Controllers;
class ShopProduct
class ShopProductController
{
static public function lazy_loading_products()
private $categoryRepository;
public function __construct( \Domain\Category\CategoryRepository $categoryRepository )
{
$this->categoryRepository = $categoryRepository;
}
public function lazyLoadingProducts()
{
global $lang_id;
$output = '';
$categoryRepo = new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] );
$categoryId = (int)\Shared\Helpers\Helpers::get( 'category_id' );
$products_ids = $categoryRepo->productsId( $categoryId, $categoryRepo->getCategorySort( $categoryId ), $lang_id, 8, (int)\Shared\Helpers\Helpers::get( 'offset' ) );
$products_ids = $this->categoryRepository->productsId(
$categoryId,
$this->categoryRepository->getCategorySort( $categoryId ),
$lang_id,
8,
(int)\Shared\Helpers\Helpers::get( 'offset' )
);
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
$output .= \Shared\Tpl\Tpl::view('shop-product/product-mini', [
'product' => Product::getFromCache( $product_id, $lang_id )
$output .= \Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => \shop\Product::getFromCache( $product_id, $lang_id )
] );
endforeach;
endif;
@@ -24,13 +35,14 @@ class ShopProduct
exit;
}
public static function warehouse_message()
public function warehouseMessage()
{
global $lang_id;
$values = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true );
foreach( $values as $key => $val )
$attributes = [];
foreach ( $values as $key => $val )
{
if ( $key != 'product-id' and $key != 'quantity' )
$attributes[] = $val;
@@ -41,23 +53,23 @@ class ShopProduct
exit;
}
// wyświetlenie atrybutów w widoku produktu
static public function draw_product_attributes()
public function drawProductAttributes()
{
global $mdb, $lang_id;
global $lang_id;
$combination = '';
$selected_values = \Shared\Helpers\Helpers::get( 'selected_values' );
foreach ( $selected_values as $value ) {
foreach ( $selected_values as $value )
{
$combination .= $value;
if ( $value != end( $selected_values ) )
$combination .= '|';
}
$product_id = \Shared\Helpers\Helpers::get( 'product_id' );
$product = Product::getFromCache( $product_id, $lang_id );
$product_data = $product -> getProductDataBySelectedAttributes( $combination );
$product = \shop\Product::getFromCache( $product_id, $lang_id );
$product_data = $product->getProductDataBySelectedAttributes( $combination );
echo json_encode( [ 'product_data' => $product_data ] );
exit;

View File

@@ -0,0 +1,13 @@
<?php
namespace front\Views;
class ShopPaymentMethod
{
public static function basketPaymentMethods( $payment_methods, $payment_id )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->payment_methods = $payment_methods;
$tpl->payment_id = $payment_id;
return $tpl->render( 'shop-basket/basket-payments-methods' );
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace front\Views;
class ShopProduct
{
public static function productUrl( $product )
{
if ( $product['language']['seo_link'] )
{
return '/' . $product['language']['seo_link'];
}
if ( $product['parent_id'] )
return '/p-' . $product['parent_id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
return '/p-' . $product['id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
}
}

View File

@@ -170,7 +170,8 @@ class Site
'ShopBasket' => function() {
global $mdb;
return new \front\Controllers\ShopBasketController(
new \Domain\Order\OrderRepository( $mdb )
new \Domain\Order\OrderRepository( $mdb ),
new \Domain\PaymentMethod\PaymentMethodRepository( $mdb )
);
},
'ShopClient' => function() {
@@ -197,6 +198,12 @@ class Site
new \Domain\Producer\ProducerRepository( $mdb )
);
},
'ShopProduct' => function() {
global $mdb;
return new \front\Controllers\ShopProductController(
new \Domain\Category\CategoryRepository( $mdb )
);
},
];
}
}

View File

@@ -1,74 +0,0 @@
<?php
namespace front\factory;
class ShopPaymentMethod
{
private static function repo(): \Domain\PaymentMethod\PaymentMethodRepository
{
global $mdb;
return new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
}
// get_apilo_payment_method_id
static public function get_apilo_payment_method_id( $payment_method_id ) {
return self::repo()->getApiloPaymentTypeId( (int)$payment_method_id );
}
public static function payment_methods_by_transport( $transport_method_id )
{
$transport_method_id = (int)$transport_method_id;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_methods_by_transport' . $transport_method_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( $objectData ) {
return unserialize( $objectData );
}
$payments = self::repo()->forTransport( $transport_method_id );
$cacheHandler->set( $cacheKey, $payments );
return $payments;
}
public static function is_payment_active( $payment_method_id )
{
return self::repo()->isActive( (int)$payment_method_id );
}
public static function payment_method( $payment_method_id )
{
$payment_method_id = (int)$payment_method_id;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_method' . $payment_method_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$payment_method = self::repo()->findActiveById( $payment_method_id );
$cacheHandler->set( $cacheKey, $payment_method );
}
else
{
return unserialize( $objectData );
}
return $payment_method;
}
public static function payment_methods()
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_methods';
$objectData = $cacheHandler->get( $cacheKey );
if ( $objectData ) {
return unserialize( $objectData );
}
$payment_methods = self::repo()->allActive();
$cacheHandler->set( $cacheKey, $payment_methods );
return $payment_methods;
}
}

View File

@@ -1,410 +0,0 @@
<?php
namespace front\factory;
class ShopProduct
{
// get_product_sku
static public function get_product_sku( $product_id, $parent = false )
{
global $mdb;
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => $product_id ] );
if ( !$sku and $parent )
{
$parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] );
if ( $parent_id )
return \front\factory\ShopProduct::get_product_sku( $parent_id, true );
else
return false;
}
else
{
return $sku;
}
}
// get_product_ean
static public function get_product_ean( $product_id, $parent = false )
{
global $mdb;
$ean = $mdb -> get( 'pp_shop_products', 'ean', [ 'id' => $product_id ] );
if ( !$ean and $parent )
{
$parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] );
if ( $parent_id )
return \front\factory\ShopProduct::get_product_ean( $parent_id, true );
else
return false;
}
else
{
return $ean;
}
}
static public function is_product_active( int $product_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopProduct::is_product_active:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$is_active = $mdb -> get( 'pp_shop_products', 'status', [ 'id' => $product_id ] );
$cacheHandler -> set( $cacheKey, $is_active );
}
else
{
return unserialize( $objectData );
}
return $is_active;
}
static public function product_url( $product )
{
if ( $product['language']['seo_link'] )
{
$url = '/' . $product['language']['seo_link'];
}
else
{
if ( $product['parent_id'] )
$url = '/p-' . $product['parent_id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
else
$url = '/p-' . $product['id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
}
return $url;
}
static public function get_minimal_price( $id_product, $price_brutto_promo = null )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'get_minimal_price:' . $id_product;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$price = $mdb -> min( 'pp_shop_product_price_history', 'price', [ 'AND' => [ 'id_product' => $id_product, 'price[!]' => str_replace( ',', '.', $price_brutto_promo ) ] ] );
$cacheHandler->set( $cacheKey, $price );
}
else
{
return unserialize( $objectData );
}
return $price;
}
public static function product_categories( $product_id )
{
global $mdb;
if ( $parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] ) )
return \R::getAll( 'SELECT category_id FROM pp_shop_products_categories WHERE product_id = ?', [ $parent_id ] );
else
return \R::getAll( 'SELECT category_id FROM pp_shop_products_categories WHERE product_id = ?', [ $product_id ] );
}
public static function product_name( $product_id )
{
global $mdb, $lang_id;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_name' . $lang_id . '_' . $product_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$product_name = $mdb -> get( 'pp_shop_products_langs', 'name', [ 'AND' => [ 'product_id' => (int)$product_id, 'lang_id' => $lang_id ] ] );
$cacheHandler->set( $cacheKey, $product_name );
}
else
{
return unserialize( $objectData );
}
return $product_name;
}
public static function product_image( $product_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_image:' . $product_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT src FROM pp_shop_products_images WHERE product_id = :product_id ORDER BY o ASC LIMIT 1', [ ':product_id' => (int)$product_id ] ) -> fetchAll( \PDO::FETCH_ASSOC );
$product_image = $results[ 0 ][ 'src' ];
$cacheHandler->set( $cacheKey, $product_image );
}
else
{
return unserialize( $objectData );
}
return $product_image;
}
public static function product_wp( $product_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopProduct::product_wp:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$product_wp = $mdb -> get( 'pp_shop_products', 'wp', [ 'id' => $product_id ] );
$cacheHandler -> set( $cacheKey, $product_wp );
}
else
{
return unserialize( $objectData );
}
return $product_wp;
}
public static function random_products( $product_id, $lang_id = 'pl' )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'random_products_' . $product_id . '_' . $lang_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT id FROM pp_shop_products WHERE status = 1 ORDER BY RAND() LIMIT 6' ) -> fetchAll();
if ( is_array( $results ) and!empty( $results ) )
foreach ( $results as $row )
$products[] = \front\factory\ShopProduct::product_details( $row[ 'id' ], $lang_id );
$cacheHandler->set( $cacheKey, $products );
}
else
{
return unserialize( $objectData );
}
return $products;
}
public static function promoted_products( $limit = 6 )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "promoted_products-$limit";
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT id FROM pp_shop_products WHERE status = 1 AND promoted = 1 ORDER BY RAND() LIMIT ' . $limit ) -> fetchAll();
if ( is_array( $results ) and!empty( $results ) )
foreach ( $results as $row )
$products[] = $row[ 'id' ];
$cacheHandler->set( $cacheKey, $products );
}
else
{
return unserialize( $objectData );
}
return $products;
}
public static function top_products( $limit = 6 )
{
global $mdb;
$date_30_days_ago = date('Y-m-d', strtotime('-30 days'));
$products = $mdb -> query( "SELECT COUNT(0) AS sell_count, psop.parent_product_id FROM pp_shop_order_products AS psop INNER JOIN pp_shop_orders AS pso ON pso.id = psop.order_id WHERE pso.date_order >= '$date_30_days_ago' GROUP BY parent_product_id ORDER BY sell_count DESC")->fetchAll(\PDO::FETCH_ASSOC);
foreach ( $products as $product )
{
if ( \front\factory\ShopProduct::is_product_active( $product['parent_product_id'] ) )
$product_ids[] = $product['parent_product_id'];
}
return $product_ids;
}
public static function new_products( $limit = 10 ) {
global $mdb;
$results = $mdb->query("
SELECT id
FROM pp_shop_products
WHERE status = 1
ORDER BY date_add DESC
LIMIT $limit
")->fetchAll(\PDO::FETCH_ASSOC);
return array_column($results, 'id');
}
public static function product_details( $product_id, $lang_id )
{
global $mdb;
if ( !$product_id )
return false;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopProduct::product_details:$product_id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$product = $mdb -> get( 'pp_shop_products', '*', [ 'id' => (int)$product_id ] );
$results = $mdb -> select( 'pp_shop_products_langs', '*', [ 'AND' => [ 'product_id' => (int)$product_id, 'lang_id' => $lang_id ] ] );
if ( is_array( $results ) )
foreach ( $results as $row )
{
if ( $row[ 'copy_from' ] )
{
$results2 = $mdb -> select( 'pp_shop_products_langs', '*', [ 'AND' => [ 'product_id' => (int)$product_id, 'lang_id' => $row[ 'copy_from' ] ] ] );
if ( is_array( $results2 ) )
foreach ( $results2 as $row2 )
$product[ 'language' ] = $row2;
}
else
$product[ 'language' ] = $row;
}
$results = $mdb -> query( 'SELECT '
. 'DISTINCT( attribute_id ) '
. 'FROM '
. 'pp_shop_products_attributes AS pspa '
. 'INNER JOIN pp_shop_attributes AS psa ON psa.id = pspa.attribute_id '
. 'WHERE '
. 'product_id = ' . (int)$product_id . ' '
. 'ORDER BY '
. 'o ASC' ) -> fetchAll();
if ( is_array( $results ) )
foreach ( $results as $row )
{
$row[ 'type' ] = $mdb -> get( 'pp_shop_attributes',
'type',
[ 'id' => $row[ 'attribute_id' ] ]
);
$row[ 'language' ] = $mdb -> get( 'pp_shop_attributes_langs',
[ 'name' ],
[ 'AND' =>
[ 'attribute_id' => $row[ 'attribute_id' ], 'lang_id' => $lang_id ]
]
);
$results2 = $mdb -> query( 'SELECT '
. 'value_id, is_default '
. 'FROM '
. 'pp_shop_products_attributes AS pspa '
. 'INNER JOIN pp_shop_attributes_values AS psav ON psav.id = pspa.value_id '
. 'WHERE '
. 'product_id = :product_id '
. 'AND '
. 'pspa.attribute_id = :attribute_id ',
[
':product_id' => $product_id,
':attribute_id' => $row[ 'attribute_id' ]
]
) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $results2 ) )
foreach ( $results2 as $row2 )
{
$row2[ 'language' ] = $mdb -> get( 'pp_shop_attributes_values_langs',
[ 'name', 'value' ],
[ 'AND' =>
[ 'value_id' => $row2[ 'value_id' ], 'lang_id' => $lang_id ]
]
);
$row[ 'values' ][] = $row2;
}
$product[ 'attributes' ][] = $row;
}
$product[ 'images' ] = $mdb -> select( 'pp_shop_products_images', '*', [ 'product_id' => (int)$product_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
$product[ 'files' ] = $mdb -> select( 'pp_shop_products_files', '*', [ 'product_id' => (int)$product_id ] );
$product[ 'categories' ] = $mdb -> select( 'pp_shop_products_categories', 'category_id', [ 'product_id' => (int)$product_id ] );
$product[ 'products_related' ] = $mdb -> select( 'pp_shop_products_related', 'product_related_id', [ 'product_id' => (int)$product_id ] );
$set_id = $mdb -> select( 'pp_shop_product_sets_products', 'set_id', [ 'product_id' => (int)$product_id ] );
$products_sets = $mdb -> select( 'pp_shop_product_sets_products', 'product_id', [ 'set_id' => (int)$set_id ] );
$products_sets = array_unique( $products_sets );
$product[ 'products_sets' ] = $products_sets;
$attributes = $mdb -> select( 'pp_shop_products_attributes', [ 'attribute_id', 'value_id' ], [ 'product_id' => (int)$product_id ] );
if ( is_array( $attributes ) ): foreach ( $attributes as $attribute ):
$attributes_tmp[ $attribute[ 'attribute_id' ] ][] = $attribute[ 'value_id' ];
endforeach;
endif;
if ( is_array( $attributes_tmp ) )
$product[ 'permutations' ] = \Shared\Helpers\Helpers::array_cartesian_product( $attributes_tmp );
$cacheHandler -> set( $cacheKey, $product );
}
else
{
return unserialize($objectData);
}
return $product;
}
public static function warehouse_message_zero( $id_product, $lang_id )
{
global $mdb, $lang_id;
return $mdb -> get( 'pp_shop_products_langs', 'warehouse_message_zero', [ 'AND' => [ 'product_id' => $id_product, 'lang_id' => $lang_id ] ] );
}
public static function warehouse_message_nonzero( $id_product, $lang_id )
{
global $mdb, $lang_id;
return $mdb -> get( 'pp_shop_products_langs', 'warehouse_message_nonzero', [ 'AND' => [ 'product_id' => $id_product, 'lang_id' => $lang_id ] ] );
}
//TO:DO do usunięcia
public static function product_both_price( $product_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_products', [ 'price_brutto', 'price_brutto_promo' ], [ 'id' => (int)$product_id ] );
}
//TO:DO do usunięcia
public static function product_price( $product_id )
{
global $mdb;
$product = $mdb -> get( 'pp_shop_products', [ 'price_brutto', 'price_brutto_promo', 'vat' ], [ 'id' => (int)$product_id ] );
if ( $product[ 'price_brutto_promo' ] )
return $product[ 'price_brutto_promo' ];
else
return $product[ 'price_brutto' ];
}
}

View File

@@ -1,215 +0,0 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace front\factory;
/**
* Description of class
*
* @author Dom - Jacek
*/
class ShopPromotion
{
//! promocja na wszystkie produkty z kategori 1 lub 2
static public function promotion_type_03( $basket, $promotion )
{
$categories = json_decode( $promotion -> categories );
$condition_categories = json_decode( $promotion -> condition_categories );
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion -> include_product_promo )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $condition_categories ) or in_array( $category_tmp[ 'category_id' ], $categories ) )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
}
return $basket;
}
//! promocja na produkty z kategorii 1 i 2
static public function promotion_type_02( $basket, $promotion )
{
$condition_1 = false; $condition_2 = false;
$categories = json_decode( $promotion -> categories );
$condition_categories = json_decode( $promotion -> condition_categories );
// sprawdzanie czy warunki są spełnione
if ( is_array( $condition_categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
// sprawdzam produkt pod kątem I kategorii
if ( !$condition_1 and in_array( $category_tmp[ 'category_id' ], $condition_categories ) )
{
$condition_1 = true;
unset( $basket_tmp[ $key ] );
}
}
}
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
// sprawdzam produkt pod kątem II kategorii
if ( !$condition_2 and in_array( $category_tmp[ 'category_id' ], $categories ) )
$condition_2 = true;
}
}
}
// jeżeli warunki są spełnione to szukam produktów, którym można obniżyć cenę
if ( $condition_1 and $condition_2 )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $categories ) or in_array( $category_tmp['category_id'], $condition_categories ) )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
}
return $basket;
}
//! promocja na najtańszy produkt z kategorii 1 lub 2
static public function promotion_type_04( $basket, $promotion )
{
$condition_1 = false;
$categories = json_decode( $promotion -> categories );
//! sprawdzanie czy warunki są spełnione
if ( is_array( $categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion -> include_product_promo )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
//! sprawdzam produkt pod kątem I kategorii
if ( !$condition_1[$key] and in_array( $category_tmp[ 'category_id' ], $categories ) )
$condition_1[$key] = true;
}
}
}
}
if ( count( $condition_1 ) >= $promotion -> min_product_count )
{
foreach ( $basket as $key => $val )
{
$price = \shop\Product::get_product_price( $val['product-id'] );
if ( !$cheapest_position or $cheapest_position['price'] > $price )
{
$cheapest_position['price'] = $price;
$cheapest_position['key'] = $key;
}
}
$basket[$cheapest_position['key']]['quantity'] = 1;
$basket[$cheapest_position['key']]['discount_type'] = 3;
$basket[$cheapest_position['key']]['discount_amount'] = $promotion -> price_cheapest_product;
$basket[$cheapest_position['key']]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$cheapest_position['key']]['include_product_promo'] = $promotion -> include_product_promo;
}
return $basket;
}
//! promocja na cały koszyk
static public function promotion_type_05( $basket, $promotion )
{
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion -> include_product_promo )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
return $basket;
}
//! Rabat procentowy na produkty z kategorii I jeżeli w koszyku jest produkt z kategorii II
static public function promotion_type_01( $basket, $promotion )
{
$condition = false;
$categories = json_decode( $promotion -> categories );
$condition_categories = json_decode( $promotion -> condition_categories );
// sprawdzanie czy warunki są spełnione
if ( is_array( $condition_categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $condition_categories ) )
{
$condition = true;
}
}
}
}
// jeżeli warunki są spełnione to szukam produktów, którym można obniżyć cenę
if ( $condition )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $categories ) )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
}
return $basket;
}
}

View File

@@ -1,20 +0,0 @@
<?php
namespace front\factory;
class ShopStatuses {
// get_apilo_status_id
static public function get_apilo_status_id( $status_id ) {
global $mdb;
$repo = new \Domain\ShopStatus\ShopStatusRepository( $mdb );
return $repo->getApiloStatusId( (int)$status_id );
}
// get_shop_status_by_integration_status_id
static public function get_shop_status_by_integration_status_id( $integration, $integration_status_id )
{
global $mdb;
$repo = new \Domain\ShopStatus\ShopStatusRepository( $mdb );
return $repo->getByIntegrationStatusId( (string)$integration, (int)$integration_status_id );
}
}

View File

@@ -1,99 +0,0 @@
<?php
namespace front\factory;
class ShopTransport
{
static public function get_apilo_carrier_account_id( $transport_method_id )
{
global $mdb;
$repo = new \Domain\Transport\TransportRepository($mdb);
return $repo->getApiloCarrierAccountId($transport_method_id);
}
public static function transport_methods( $basket, $coupon )
{
global $mdb, $settings;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopTransport::transport_methods";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$repo = new \Domain\Transport\TransportRepository($mdb);
$transports_tmp = $repo->allActive();
$cacheHandler -> set( $cacheKey, $transports_tmp );
}
else
{
$transports_tmp = unserialize( $objectData );
}
$wp_summary = \Domain\Basket\BasketCalculator::summaryWp( $basket );
foreach ( $transports_tmp as $tr )
{
if ( $tr['max_wp'] == null )
$transports[] = $tr;
elseif ( $tr['max_wp'] != null and $wp_summary <= $tr['max_wp'] )
$transports[] = $tr;
}
if ( \Shared\Helpers\Helpers::normalize_decimal( \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ) ) >= \Shared\Helpers\Helpers::normalize_decimal( $settings['free_delivery'] ) )
{
for ( $i = 0; $i < count( $transports ); $i++ ){
if($transports[ $i ]['delivery_free'] == 1) {
$transports[ $i ]['cost'] = 0.00;
}
}
}
return $transports;
}
public static function transport_cost( $transport_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport_cost_' . $transport_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$repo = new \Domain\Transport\TransportRepository($mdb);
$cost = $repo->getTransportCost($transport_id);
$cacheHandler->set( $cacheKey, $cost );
}
else
{
return unserialize( $objectData );
}
return $cost;
}
public static function transport( $transport_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport' . $transport_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$repo = new \Domain\Transport\TransportRepository($mdb);
$transport = $repo->findActiveById($transport_id);
$cacheHandler->set( $cacheKey, $transport );
}
else
{
return unserialize( $objectData );
}
return $transport;
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace front\view;
class ShopPaymentMethod
{
public static function basket_payment_methods( $payment_methods, $payment_id )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl -> payment_methods = $payment_methods;
$tpl -> payment_id = $payment_id;
return $tpl -> render( 'shop-basket/basket-payments-methods' );
}
}

View File

@@ -1,6 +0,0 @@
<?php
namespace front\view;
class ShopTransport
{
}

View File

@@ -82,7 +82,7 @@ class Site
$html = str_replace( $pattern,
\Shared\Tpl\Tpl::view( 'shop-product/promoted-products', [
'products' => \front\factory\ShopProduct::promoted_products( $limit )
'products' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->promotedProductIdsCached( $limit )
] ),
$html
);
@@ -285,7 +285,7 @@ class Site
$products_top[1] ? $pattern = '[PRODUKTY_TOP:' . $products_top[1] . ']' : $pattern = '[PRODUKTY_TOP]';
$products_id_arr = \front\factory\ShopProduct::top_products( $limit );
$products_id_arr = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->topProductIds( $limit );
foreach ( $products_id_arr as $product_id ){
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
@@ -313,7 +313,7 @@ class Site
$products_top[1] ? $pattern = '[PRODUKTY_NEW:' . $products_top[1] . ']' : $pattern = '[PRODUKTY_NEW]';
$products_id_arr = \front\factory\ShopProduct::new_products( $limit );
$products_id_arr = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->newProductIds( $limit );
foreach ( $products_id_arr as $product_id ){

View File

@@ -331,7 +331,7 @@ class Order implements \ArrayAccess
if ( !(int)$this -> apilo_order_id )
return true;
$payment_type = (int)\front\factory\ShopPaymentMethod::get_apilo_payment_method_id( (int)$this -> payment_method_id );
$payment_type = (int)( new \Domain\PaymentMethod\PaymentMethodRepository( $mdb ) )->getApiloPaymentTypeId( (int)$this -> payment_method_id );
if ( $payment_type <= 0 )
$payment_type = 1;
@@ -390,7 +390,7 @@ class Order implements \ArrayAccess
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
'id' => $this -> apilo_order_id,
'status' => (int)\front\factory\ShopStatuses::get_apilo_status_id( $status )
'status' => (int)( new \Domain\ShopStatus\ShopStatusRepository( $mdb ) )->getApiloStatusId( (int)$status )
] ) );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,

View File

@@ -1,43 +0,0 @@
<?php
namespace shop;
class PaymentMethod implements \ArrayAccess
{
private static function repo(): \Domain\PaymentMethod\PaymentMethodRepository
{
global $mdb;
return new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
}
// lista dostepnych form platnosci
static public function method_list()
{
return self::repo()->allActive();
}
// get_apilo_payment_method_id
static public function get_apilo_payment_method_id( $payment_method_id )
{
return self::repo()->getApiloPaymentTypeId( (int)$payment_method_id );
}
public function offsetExists( $offset )
{
return isset( $this -> $offset );
}
public function offsetGet( $offset )
{
return $this -> $offset;
}
public function offsetSet( $offset, $value )
{
$this -> $offset = $value;
}
public function offsetUnset( $offset )
{
unset( $this -> $offset );
}
}

View File

@@ -344,7 +344,7 @@ class Product implements \ArrayAccess
foreach ( $products as $product_id )
{
if ( !\front\factory\ShopProduct::is_product_active( $product_id ) )
if ( !( new \Domain\Product\ProductRepository( $mdb ) )->isProductActiveCached( (int)$product_id ) )
$products = array_diff( $products, [ $product_id ] );
}
@@ -739,14 +739,14 @@ class Product implements \ArrayAccess
if ( $quantity )
{
if ( $msg = \front\factory\ShopProduct::warehouse_message_nonzero( $id_product, $lang_id ) )
if ( $msg = ( new \Domain\Product\ProductRepository( $mdb ) )->getWarehouseMessageNonzero( (int)$id_product, $lang_id ) )
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
else if ( $settings[ 'warehouse_message_nonzero_' . $lang_id ] )
$result = [ 'msg' => $settings[ 'warehouse_message_nonzero_' . $lang_id ], 'quantity' => $quantity ];
}
else
{
if ( $msg = \front\factory\ShopProduct::warehouse_message_zero( $id_product, $lang_id ) )
if ( $msg = ( new \Domain\Product\ProductRepository( $mdb ) )->getWarehouseMessageZero( (int)$id_product, $lang_id ) )
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
else if ( $settings[ 'warehouse_message_zero_' . $lang_id ] )
$result = [ 'msg' => $settings[ 'warehouse_message_zero_' . $lang_id ], 'quantity' => $quantity ];

View File

@@ -74,29 +74,31 @@ class Promotion
$results = self::get_active_promotions();
if ( is_array( $results ) and count( $results ) )
{
$promoRepo = new \Domain\Promotion\PromotionRepository( $mdb );
foreach ( $results as $row )
{
$promotion = new \shop\Promotion( $row );
// Promocja na cały koszyk
if ( $promotion -> condition_type == 4 )
return \front\factory\ShopPromotion::promotion_type_05( $basket_tmp, $promotion );
return $promoRepo->applyTypeWholeBasket( $basket_tmp, $promotion );
// Najtańszy produkt w koszyku (z wybranych kategorii) za X zł
if ( $promotion -> condition_type == 3 )
return \front\factory\ShopPromotion::promotion_type_04( $basket_tmp, $promotion );
return $promoRepo->applyTypeCheapestProduct( $basket_tmp, $promotion );
// Rabat procentowy na produkty z kategorii 1 lub kategorii 2
if ( $promotion -> condition_type == 5 )
return \front\factory\ShopPromotion::promotion_type_03( $basket_tmp, $promotion );
return $promoRepo->applyTypeCategoriesOr( $basket_tmp, $promotion );
// Rabat procentowy na produkty z kategorii I i kategorii II
if ( $promotion -> condition_type == 2 )
return \front\factory\ShopPromotion::promotion_type_02( $basket_tmp, $promotion );
return $promoRepo->applyTypeCategoriesAnd( $basket_tmp, $promotion );
// Rabat procentowy na produkty z kategorii I jeżeli w koszyku jest produkt z kategorii II
if ( $promotion -> condition_type == 1 )
return \front\factory\ShopPromotion::promotion_type_01( $basket_tmp, $promotion );
return $promoRepo->applyTypeCategoryCondition( $basket_tmp, $promotion );
}
}
return $basket;