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

@@ -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 ){