'Koszyk' ]; public static function basket_message_save() { \S::set_session( 'basket_message', \S::get( 'basket_message' ) ); echo json_encode( [ 'result' => 'ok' ] ); exit; } public static function basket_remove_product() { global $lang_id; $basket = \S::get_session( 'basket' ); $coupon = \S::get_session( 'coupon' ); $product_hash = \S::get( 'product_hash' ); $basket_transport_method_id = \S::get_session( 'basket-transport-method-id' ); unset( $basket[ $product_hash ] ); $basket = \shop\Promotion::find_promotion( $basket ); \S::set_session( 'basket', $basket ); echo json_encode( [ 'basket' => \Tpl::view( 'shop-basket/basket-details', [ 'basket' => $basket, 'lang_id' => $lang_id, 'coupon' => $coupon ] ), 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), 'products_count' => count( $basket ), 'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [ 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), 'transport_id' => $basket_transport_method_id ] ) ] ); exit; } public static function basket_increase_quantity_product() { global $lang_id; $basket = \S::get_session( 'basket' ); $coupon = \S::get_session( 'coupon' ); $product_hash = \S::get( 'product_hash' ); $basket_transport_method_id = \S::get_session( 'basket-transport-method-id' ); $basket[ $product_hash ][ 'quantity' ]++; \shop\Basket::check_product_quantity_in_stock( $basket, false ); $basket = \S::get_session( 'basket' ); $basket = \shop\Promotion::find_promotion( $basket ); \S::set_session( 'basket', $basket ); echo json_encode( [ 'basket' => \Tpl::view( 'shop-basket/basket-details', [ 'basket' => $basket, 'lang_id' => $lang_id, 'coupon' => $coupon ] ), 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), 'products_count' => count( $basket ), 'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [ 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), 'transport_id' => $basket_transport_method_id ] ) ] ); exit; } public static function basket_decrease_quantity_product() { global $lang_id; $basket = \S::get_session( 'basket' ); $coupon = \S::get_session( 'coupon' ); $product_hash = \S::get( 'product_hash' ); $basket_transport_method_id = \S::get_session( 'basket-transport-method-id' ); $basket[ $product_hash ][ 'quantity' ]--; if ( $basket[ $product_hash ][ 'quantity' ] < 1 ) unset( $basket[ $product_hash ] ); $basket = \shop\Promotion::find_promotion( $basket ); \S::set_session( 'basket', $basket ); echo json_encode( [ 'basket' => \Tpl::view( 'shop-basket/basket-details', [ 'basket' => $basket, 'lang_id' => $lang_id, 'coupon' => $coupon ] ), 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), 'products_count' => count( $basket ), 'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [ 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), 'transport_id' => $basket_transport_method_id ] ) ] ); exit; } public static function basket_change_quantity_product() { global $lang_id; $basket = \S::get_session( 'basket' ); $coupon = \S::get_session( 'coupon' ); $product_hash = \S::get( 'product_hash' ); $basket_transport_method_id = \S::get_session( 'basket-transport-method-id' ); $basket[ $product_hash ][ 'quantity' ] = (int)\S::get( 'quantity' ); if ( $basket[ $product_hash ][ 'quantity' ] < 1 ) unset( $basket[ $product_hash ] ); $basket = \shop\Promotion::find_promotion( $basket ); \shop\Basket::check_product_quantity_in_stock( $basket, false ); $basket = \S::get_session( 'basket' ); echo json_encode( [ 'basket' => \Tpl::view( 'shop-basket/basket-details', [ 'basket' => $basket, 'lang_id' => $lang_id, 'coupon' => $coupon ] ), 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), 'products_count' => count( $basket ), 'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [ 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), 'transport_id' => $basket_transport_method_id ] ) ] ); exit; } static public function product_message_change() { $basket = \S::get_session( 'basket' ); $basket[ \S::get( 'position_code' ) ]['message'] = \S::get( 'product_message' ); \S::set_session( 'basket', $basket ); exit; } public static function basket_add_product() { $basket = \shop\Basket::validate_basket( \S::get_session( 'basket' ) ); $values_tmp = json_decode( \S::get( 'values' ), true ); foreach( $values_tmp as $key => $val ) $values[ $val['name'] ] = $val['value']; // sprawdzam pola pod kątem wybranych atrybutów foreach( $values as $key => $val ) { if ( $key != 'product-id' and $key != 'quantity' and $key != 'product-message' and strpos( $key, 'custom_field' ) === false ) $attributes[] = $val; } // stwórz tablicę dodatkowych pól wyszukując na podstawie custom_field[1], custom_field[2] itd. foreach( $values as $key => $val ) { if ( strpos( $key, 'custom_field' ) !== false ) { // extract number from custom_field[1], custom_field[2] etc. preg_match( '/\d+/', $key, $matches ); $custom_field_id = $matches[0]; $custom_fields[ $custom_field_id ] = $val; } } if ( \S::is_array_fix( $attributes ) ) { $values['parent_id'] = $values[ 'product-id' ]; $values['product-id'] = \shop\Product::get_product_id_by_attributes( $values[ 'product-id' ], $attributes ); $values['attributes'] = $attributes; } $values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] ); $attributes_implode = ''; // generuj unikalny kod produktu dodanego do koszyka if ( is_array( $attributes ) ) $attributes_implode = implode( '|', $attributes ); $product_code = md5( $values['product-id'] . $attributes_implode . $values['product-message'] . json_encode( $custom_fields ) ); if ( isset( $basket[ $product_code ] ) ) $basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ]; else $basket[ $product_code ] = $values; $basket[ $product_code ]['message'] = $values['product-message']; $basket[ $product_code ]['custom_fields'] = $custom_fields; $basket = \shop\Promotion::find_promotion( $basket ); \S::set_session( 'basket', $basket ); $coupon = \S::get_session( 'coupon' ); echo json_encode( [ 'result' => 'ok', 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), 'product_sets' => \shop\Product::product_sets_when_add_to_basket( (int)$values['product-id'] ) ] ); exit; } // sprawdzam czy została wybrana forma wysylki inpost i czy został wybrany paczkomat static public function transport_method_inpost_check() { if ( \S::get_session( 'basket-transport-method-id' ) === '2' or \S::get_session( 'basket-transport-method-id' ) === '1' ) { if ( !\S::get_session( 'basket-inpost-info' ) ) { echo json_encode( [ 'result' => 'bad' ] ); exit; } } echo json_encode( [ 'result' => 'ok' ] ); exit; } // sprawdzam czy został wybrany paczkomat static public function inpost_check() { if ( !\S::get_session( 'basket-inpost-info' ) ) echo json_encode( [ 'result' => 'bad' ] ); else echo json_encode( [ 'result' => 'ok' ] ); exit; } public static function inpost_save() { \S::set_session( 'basket-inpost-info', \S::get( 'paczkomat' ) ); echo json_encode( [ 'result' => 'ok' ] ); exit; } public static function basket_payment_method_set() { \S::set_session( 'basket-payment-method-id', \S::get( 'payment_method_id' ) ); echo json_encode( [ 'result' => 'ok' ] ); exit; } public static function basket_transport_method_set() { \S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) ); echo json_encode( [ 'result' => 'ok' ] ); exit; } public static function basket_payments_methods() { \S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) ); echo json_encode( [ 'result' => 'ok', 'payment_methods' => \front\view\ShopPaymentMethod::basket_payment_methods( \front\factory\ShopPaymentMethod::payment_methods_by_transport( \S::get( 'transport_method_id' ) ), \S::get( 'payment_method_id' ) ) ] ); exit; } public static function summary_view() { global $lang_id, $settings; if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) ) { header( 'Location: /koszyk' ); exit; } $client = \S::get_session( 'client' ); return \Tpl::view( 'shop-basket/summary-view', [ 'lang_id' => $lang_id, 'client' => \S::get_session( 'client' ), 'basket' => \S::get_session( 'basket' ), 'transport' => \front\factory\ShopTransport::transport( \S::get_session( 'basket-transport-method-id' ) ), 'payment_method' => \front\factory\ShopPaymentMethod::payment_method( \S::get_session( 'basket-payment-method-id' ) ), 'addresses' => \front\factory\ShopClient::client_addresses( $client[ 'id' ] ), 'settings' => $settings, 'coupon' => \S::get_session( 'coupon' ), 'basket_message' => \S::get_session( 'basket_message' ) ] ); } // zapisanie koszyka jako zamówienie static public function basket_save() { $client = \S::get_session( 'client' ); $payment_method = \S::get_session( 'basket-payment-method-id' ); if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) ) { header( 'Location: /koszyk' ); exit; } if ( $order_id = \front\factory\ShopOrder::basket_save( $client[ 'id' ], \S::get_session( 'basket' ), \S::get_session( 'basket-transport-method-id' ), \S::get_session( 'basket-payment-method-id' ), \S::get( 'email', true ), \S::get( 'phone', true ), \S::get( 'name', true ), \S::get( 'surname', true ), \S::get( 'firm', true ), \S::get( 'street' ), \S::get( 'postal_code', true ), \S::get( 'city', true ), \S::get_session( 'basket-inpost-info' ), \S::get_session( 'coupon' ), \S::get_session( 'basket_message' ) ) ) { \S::alert( \S::lang( 'zamowienie-zostalo-zlozone-komunikat' ) ); \S::delete_session( 'basket' ); \S::delete_session( 'basket-transport-method-id' ); \S::delete_session( 'basket-payment-method-id' ); \S::delete_session( 'basket-inpost-info' ); \S::delete_session( 'coupon' ); \S::delete_session( 'basket_message' ); \S::set_session( 'piksel_purchase', true ); \S::set_session( 'google-adwords-purchase', true ); \S::set_session( 'google-analytics-purchase', true ); \S::set_session( 'ekomi-purchase', true ); $redis = \RedisConnection::getInstance() -> getConnection(); if ( $redis ) $redis -> flushAll(); header( 'Location: /zamowienie/' . \front\factory\ShopOrder::order_hash( $order_id ) ); exit; } else { \S::error( \S::lang( 'zamowienie-zostalo-zlozone-komunikat-blad' ) ); header( 'Location: /koszyk' ); exit; } } public static function main_view() { global $lang_id, $page, $settings; $page[ 'language' ][ 'meta_title' ] = 'Koszyk'; $basket = \S::get_session( 'basket' ); $coupon = \S::get_session( 'coupon' ); $payment_method_id = \S::get_session( 'payment_method_id' ); $basket_transport_method_id = \S::get_session( 'basket-transport-method-id' ); if ( \shop\Basket::check_product_quantity_in_stock( $basket ) ) { header( 'Location: /koszyk' ); exit; } $basket = \shop\Promotion::find_promotion( $basket ); return \Tpl::view( 'shop-basket/basket', [ 'basket' => $basket, 'coupon' => $coupon, 'transport_id' => \S::get_session( 'basket-transport-method-id' ), 'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [ 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), 'transport_id' => $basket_transport_method_id ] ), 'payment_method_id' => $payment_method_id, 'basket_details' => \Tpl::view( 'shop-basket/basket-details', [ 'basket' => $basket, 'lang_id' => $lang_id, 'coupon' => $coupon, 'basket_message' => \S::get_session( 'basket_message' ), 'settings' => $settings ] ) ] ); } }