Skip to content

Instantly share code, notes, and snippets.

@uzaharova
Created October 27, 2017 10:38
Show Gist options
  • Save uzaharova/c2c1b063f68292e2ae491864a6d748fe to your computer and use it in GitHub Desktop.
Save uzaharova/c2c1b063f68292e2ae491864a6d748fe to your computer and use it in GitHub Desktop.
diff --git a/_docs/developer_changes/patch.md b/_docs/developer_changes/patch.md
index 5898f69..55e19d5 100644
--- a/_docs/developer_changes/patch.md
+++ b/_docs/developer_changes/patch.md
@@ -8,6 +8,11 @@
### New function
* `Settings::getEditableSettingsEditionTypes($use_access_level = true)` - Provides editable settings' edition types.
+* `fn_get_data_of_changed_product($params, $auth, $mode)` - Prepares the array of data of the product that is being changed in cart or in the order, and returns the template of the product with the product data. The function is used only in controllers.
+* `fn_get_additional_product_data($product_data, $auth)` - Gets the data about the product's stock and options based on the passed data of the product that is being changed in cart or in the order. The function is used only in controllers.
+* `fn_update_product_image_in_template($params)` - Updates the image of the product in the product list template. The function is used only in controllers.
+* `fn_get_product_options_data($cart_products, $cart)` - Gets the product data depending on the newly-selected options, and records the data in the $cart session array. The function is used only in controllers.
+* `fn_change_product_data_in_cart($cart_products, $cart)` - Changes the product data in the $cart array. The function is used only in controllers.
### Changed functions
diff --git a/app/controllers/backend/order_management.php b/app/controllers/backend/order_management.php
index d2bf620..6013b6f 100644
--- a/app/controllers/backend/order_management.php
+++ b/app/controllers/backend/order_management.php
@@ -281,10 +281,27 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
if ($mode == 'options') {
+ define('GET_OPTIONS', true);
+ $_auth = $auth;
+ $params = $_REQUEST;
+
+ // Apply the specific block template settings
+ if (!empty($params['appearance'])) {
+ foreach ($params['appearance'] as $setting => $value) {
+ Tygh::$app['view']->assign($setting, $value);
+ }
+ }
+
+ Tygh::$app['view']->assign('show_images', true);
+ Tygh::$app['view']->assign('no_capture', true);
+
+ if (!fn_get_data_of_changed_product($params, $_auth, $mode)) {
+ return array(CONTROLLER_STATUS_NO_PAGE);
+ }
- if (!empty($_REQUEST['cart_products'])) {
+ if (!empty($params['cart_products'])) {
$products = & Tygh::$app['session']['cart']['products'];
- $cart_products = $_REQUEST['cart_products'];
+ $cart_products = $params['cart_products'];
foreach ($cart_products as $product_id => $product) {
if (empty($product['product_options'])) {
@@ -295,10 +312,16 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
return array(CONTROLLER_STATUS_DENIED);
}
- $products[$product_id]['product_options'] = $product['product_options'];
+ $product_options = $product['product_options'];
+
+ if (!empty($params['cart']['products'][$product_id]['product_options'])) {
+ $product_options = $params['cart']['products'][$product_id]['product_options'];
+ }
+
+ $products[$product_id]['product_options'] = $product_options;
if (!empty($products[$product_id]['extra']['product_options'])) {
- $products[$product_id]['extra']['product_options'] = $product['product_options'];
+ $products[$product_id]['extra']['product_options'] = $product_options;
}
}
}
diff --git a/app/controllers/common/products.post.php b/app/controllers/common/products.post.php
index 35be790..b1dc308 100644
--- a/app/controllers/common/products.post.php
+++ b/app/controllers/common/products.post.php
@@ -19,14 +19,11 @@ if (!defined('BOOTSTRAP')) { die('Access denied'); }
if ($mode == 'options') {
define('GET_OPTIONS', true);
$_auth = $auth;
-
- if (empty($_REQUEST['product_data']) && empty($_REQUEST['cart_products'])) {
- return array(CONTROLLER_STATUS_NO_PAGE);
- }
+ $params = $_REQUEST;
// Apply the specific block template settings
- if (!empty($_REQUEST['appearance'])) {
- foreach ($_REQUEST['appearance'] as $setting => $value) {
+ if (!empty($params['appearance'])) {
+ foreach ($params['appearance'] as $setting => $value) {
Tygh::$app['view']->assign($setting, $value);
}
}
@@ -34,223 +31,10 @@ if ($mode == 'options') {
Tygh::$app['view']->assign('show_images', true);
Tygh::$app['view']->assign('no_capture', true);
- if (!empty($_REQUEST['product_data'])) {
- // Product data
- unset($_REQUEST['product_data']['custom_files']);
- $product_data = $_REQUEST;
- list($product_id, $_data) = each($product_data['product_data']);
-
- $product_id = isset($_data['product_id']) ? $_data['product_id'] : $product_id;
- $selected_options = empty($_data['product_options']) ? array() : $_data['product_options'];
- unset($selected_options['AOC']);
-
- if (isset($product_data['additional_info']['info_type']) && $product_data['additional_info']['info_type'] == 'D') {
- $product = fn_get_product_data($product_id, $_auth, CART_LANGUAGE, '', true, true, true, true, ($auth['area'] == 'A'));
- } else {
- $params['pid'] = $product_id;
-
- list($product) = fn_get_products($params);
- $product = reset($product);
- }
-
- if (empty($product)) {
- return array(CONTROLLER_STATUS_NO_PAGE);
- }
-
- $product['changed_option'] = isset($product_data['changed_option']) ? reset($product_data['changed_option']) : '';
- $product['selected_options'] = $selected_options;
- if (!empty($_data['amount'])) {
- $product['selected_amount'] = $_data['amount'];
- }
-
- // Get specific settings
- $params = array(
- 'get_icon' => isset($_REQUEST['additional_info']['get_icon']) ? $_REQUEST['additional_info']['get_icon'] : false,
- 'get_detailed' => isset($_REQUEST['additional_info']['get_detailed']) ? $_REQUEST['additional_info']['get_detailed'] : false,
- 'get_options' => isset($_REQUEST['additional_info']['get_options']) ? $_REQUEST['additional_info']['get_options'] : true,
- 'get_discounts' => isset($_REQUEST['additional_info']['get_discounts']) ? $_REQUEST['additional_info']['get_discounts'] : true,
- 'get_features' => isset($_REQUEST['additional_info']['get_features']) ? $_REQUEST['additional_info']['get_features'] : false,
- );
-
- fn_set_hook('get_additional_information', $product, $product_data);
-
- fn_gather_additional_product_data($product, $params['get_icon'], $params['get_detailed'], $params['get_options'], $params['get_discounts'], $params['get_features']);
- if (isset($product['inventory_amount'])) {
- $product['amount'] = $product['inventory_amount'];
- }
-
- if (!empty($_REQUEST['extra_id'])) {
- $product['product_id'] = $_REQUEST['extra_id'];
- }
-
- Tygh::$app['view']->assign('product', $product);
-
- // Update the images in the list/grid templates
- if (!empty($_REQUEST['image'])) {
- foreach ($_REQUEST['image'] as $div_id => $value) {
- list($obj_id, $width, $height, $type) = explode(',', $value['data']);
- $images_data[$div_id] = array(
- 'obj_id' => $obj_id,
- 'width' => $width,
- 'height' => $height,
- 'type' => $type,
- 'link' => isset($value['link']) ? $value['link'] : '',
- );
- }
-
- Tygh::$app['view']->assign('images', $images_data);
- }
-
- if (AREA == 'C') {
- if (!empty($_REQUEST['appearance']['quick_view'])) {
- $display_tpl = 'views/products/quick_view.tpl';
- } elseif (!empty($_REQUEST['appearance']['details_page'])) {
- $display_tpl = 'views/products/view.tpl';
- } else {
- $display_tpl = 'common/product_data.tpl';
- }
- } else {
- $display_tpl = 'views/products/components/select_product_options.tpl';
- Tygh::$app['view']->assign('product_options', $product['product_options']);
- }
-
- } else {
- // Cart data
- fn_enable_checkout_mode();
-
- unset($_REQUEST['cart_products']['custom_files']);
- $cart_products = $_REQUEST['cart_products'];
- if (!empty($cart_products)) {
- foreach ($cart_products as $cart_id => $product) {
- if (!empty($product['object_id'])) {
- unset($cart_products[$cart_id]);
- $cart_products[$product['object_id']] = $product;
- }
- }
- }
-
- $_cart = Tygh::$app['session']['cart'];
-
- if (AREA == 'A') {
- $_auth = Tygh::$app['session']['customer_auth'];
- if (empty($_auth)) {
- $_auth = fn_fill_auth(array(), array(), false, 'C');
- }
- }
-
- foreach ($cart_products as $cart_id => $item) {
- if (isset($_cart['products'][$cart_id])) {
- $amount = isset($item['amount']) ? $item['amount'] : 1;
- $product_data = fn_get_product_data($item['product_id'], $auth, CART_LANGUAGE, '', false, false, false, false, false, false, false);
-
- if ($product_data['options_type'] == 'S' && isset($item['product_options']) && isset($_REQUEST['changed_option'][$cart_id])) {
- $item['product_options'] = fn_fill_sequential_options($item, $_REQUEST['changed_option'][$cart_id]);
- unset($_REQUEST['changed_option']);
- }
-
- $product_options = isset($item['product_options']) ? $item['product_options'] : array();
- $amount = fn_check_amount_in_stock($item['product_id'], $amount, $product_options, $cart_id, $_cart['products'][$cart_id]['is_edp'], 0, $_cart);
-
- if ($amount === false) {
- continue;
- }
-
- $_cart['products'][$cart_id]['amount'] = $amount;
- $_cart['products'][$cart_id]['selected_options'] = isset($item['product_options']) ? $item['product_options'] : array();
- $_cart['products'][$cart_id]['product_options'] = fn_get_selected_product_options($item['product_id'], $_cart['products'][$cart_id]['selected_options']);
- $_cart['products'][$cart_id] = fn_apply_options_rules($_cart['products'][$cart_id]);
- $_cart['products'][$cart_id]['product_options'] = $_cart['products'][$cart_id]['selected_options'];
-
- if (!empty($_cart['products'][$cart_id]['extra']['saved_options_key'])) {
- $_cart['saved_product_options'][$_cart['products'][$cart_id]['extra']['saved_options_key']] = $_cart['products'][$cart_id]['product_options'];
- }
-
- if (!empty($item['object_id'])) {
- $_cart['products'][$cart_id]['object_id'] = $item['object_id'];
-
- if (!empty($_cart['products'][$cart_id]['extra']['saved_options_key'])) {
- // Product from promotion. Save object_id for this product
- $_cart['saved_object_ids'][$_cart['products'][$cart_id]['extra']['saved_options_key']] = $item['object_id'];
- }
- }
-
- unset($_cart['products'][$cart_id]['extra']['exclude_from_calculate']);
- }
- }
-
- fn_set_hook('calculate_options', $cart_products, $_cart, $auth);
-
- $exclude_products = array();
- foreach ($_cart['products'] as $cart_id => $product) {
- if (!empty($product['extra']['exclude_from_calculate'])) {
- $exclude_products[$cart_id] = true;
- }
- }
-
- list ($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true);
-
- fn_gather_additional_products_data($cart_products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => false));
-
- $changed_options = false;
- foreach ($cart_products as $item_id => $product) {
- if ($_cart['products'][$item_id]['product_options'] != $product['selected_options']) {
- $_cart['products'][$item_id]['product_options'] = $product['selected_options'];
- $changed_options = true;
- }
- }
-
- if ($changed_options) {
- list ($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true);
-
- fn_gather_additional_products_data($cart_products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => false));
- }
-
- if (count(Tygh::$app['session']['cart']['products']) != count($_cart['products'])) {
- $_recalculate = false;
- foreach (Tygh::$app['session']['cart']['products'] as $cart_id => $product) {
- if (!isset($_cart['products'][$cart_id]) && !isset($exclude_products[$cart_id])) {
- $_recalculate = true;
- break;
- }
- }
-
- if ($_recalculate) {
- $_cart = Tygh::$app['session']['cart'];
- list ($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true);
- }
- }
-
- // Restore the cart_id
- if (!empty($cart_products)) {
- foreach ($cart_products as $k => $product) {
- if (!empty($product['object_id'])) {
- $c_product = !empty($_cart['products'][$k]) ? $_cart['products'][$k] : array();
- unset($cart_products[$k], $_cart['products'][$k]);
- $_cart['products'][$product['object_id']] = $c_product;
- $cart_products[$product['object_id']] = $product;
- $k = $product['object_id'];
- }
-
- $cart_products[$k]['changed_option'] = isset($product['object_id']) ? isset($_REQUEST['changed_option'][$product['object_id']]) ? $_REQUEST['changed_option'][$product['object_id']] : '' : isset($_REQUEST['changed_option'][$k]) ? $_REQUEST['changed_option'][$k] : '' ;
- }
- }
-
- Registry::set('navigation', array());
- Tygh::$app['view']->assign('cart_products', $cart_products);
- Tygh::$app['view']->assign('cart', $_cart);
-
- if (AREA == 'C') {
- $display_tpl = 'views/checkout/components/cart_items.tpl';
- } else {
- $display_tpl = 'views/order_management/components/products.tpl';
- }
+ if (!fn_get_data_of_changed_product($params, $_auth, $mode)) {
+ return array(CONTROLLER_STATUS_NO_PAGE);
}
- $data = isset($product_data) ? $product_data : $cart_products;
- fn_set_hook('after_options_calculation', $mode, $data);
-
- Tygh::$app['view']->display($display_tpl);
-
exit;
}
diff --git a/app/functions/fn.catalog.php b/app/functions/fn.catalog.php
index 24f305f..3a51910 100644
--- a/app/functions/fn.catalog.php
+++ b/app/functions/fn.catalog.php
@@ -11338,4 +11338,4 @@ function fn_get_option_modifiers_by_selected_options(array $selected_options, $t
}
return $modifiers;
-}
\ No newline at end of file
+}
diff --git a/app/functions/fn.order_management.php b/app/functions/fn.order_management.php
new file mode 100644
index 0000000..07a0ee6
--- /dev/null
+++ b/app/functions/fn.order_management.php
@@ -0,0 +1,331 @@
+<?php
+/***************************************************************************
+ * *
+ * (c) 2004 Vladimir V. Kalynyak, Alexey V. Vinokurov, Ilya M. Shalnev *
+ * *
+ * This is commercial software, only users who have purchased a valid *
+ * license and accept to the terms of the License Agreement can install *
+ * and use this program. *
+ * *
+ ****************************************************************************
+ * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE *
+ * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. *
+ ****************************************************************************/
+
+use Tygh\Registry;
+
+if (!defined('BOOTSTRAP')) { die('Access denied'); }
+
+/**
+ * Prepares the array of data of the product that is being changed in cart or in the order,
+ * and returns the template of the product with the product data.
+ * The function is used only in controllers.
+ *
+ * @param array $params An array of parameters.
+ * @param array $auth Authentication data.
+ * @param string $mode The directory mode.
+ *
+ * @return array|bool An array with the product data.
+ */
+function fn_get_data_of_changed_product(&$params, $auth, $mode)
+{
+ $cart_products = array();
+ $_auth = $auth;
+
+ if (empty($params['product_data']) && empty($params['cart_products'])) {
+ return false;
+ }
+
+ if (!empty($params['product_data'])) {
+ unset($params['product_data']['custom_files']);
+
+ $product = fn_get_additional_product_data($params, $auth);
+ $product_data = $params;
+
+ fn_update_product_image_in_template($params);
+
+ if (AREA == 'C') {
+ if (!empty($params['appearance']['quick_view'])) {
+ $display_tpl = 'views/products/quick_view.tpl';
+
+ } elseif (!empty($params['appearance']['details_page'])) {
+ $display_tpl = 'views/products/view.tpl';
+
+ } else {
+ $display_tpl = 'common/product_data.tpl';
+ }
+
+ } else {
+ $display_tpl = 'views/products/components/select_product_options.tpl';
+
+ Tygh::$app['view']->assign('product_options', $product['product_options']);
+ }
+
+ } else {
+ fn_enable_checkout_mode();
+
+ unset($params['cart_products']['custom_files']);
+
+ $cart_products = $params['cart_products'];
+ if (!empty($cart_products)) {
+ foreach ($cart_products as $cart_id => $product) {
+ if (!empty($product['object_id'])) {
+ unset($cart_products[$cart_id]);
+ $cart_products[$product['object_id']] = $product;
+ }
+ }
+ }
+
+ if (AREA == 'A') {
+ $_auth = Tygh::$app['session']['customer_auth'];
+ if (empty($_auth)) {
+ $_auth = fn_fill_auth(array(), array(), false, 'C');
+ }
+ }
+
+ $_cart = Tygh::$app['session']['cart'];
+
+ $product_data = fn_get_product_options_data($cart_products, $_cart);
+
+ fn_set_hook('calculate_options', $cart_products, $_cart, $auth);
+
+ $exclude_products = array();
+ foreach ($_cart['products'] as $cart_id => $product) {
+ if (!empty($product['extra']['exclude_from_calculate'])) {
+ $exclude_products[$cart_id] = true;
+ }
+ }
+
+ list($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true);
+
+ fn_gather_additional_products_data($cart_products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => false));
+
+ $changed_options = false;
+ foreach ($cart_products as $item_id => $product) {
+ if ($_cart['products'][$item_id]['product_options'] != $product['selected_options']) {
+ $_cart['products'][$item_id]['product_options'] = $product['selected_options'];
+ $changed_options = true;
+ }
+ }
+
+ if ($changed_options) {
+ list($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true);
+ fn_gather_additional_products_data($cart_products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => false));
+ }
+
+ if (count(Tygh::$app['session']['cart']['products']) != count($_cart['products'])) {
+ $_recalculate = false;
+
+ foreach (Tygh::$app['session']['cart']['products'] as $cart_id => $product) {
+ if (!isset($_cart['products'][$cart_id]) && !isset($exclude_products[$cart_id])) {
+ $_recalculate = true;
+ break;
+ }
+ }
+
+ if ($_recalculate) {
+ $_cart = Tygh::$app['session']['cart'];
+ list($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true);
+ }
+ }
+
+ fn_change_product_data_in_cart($cart_products, $_cart);
+
+ Registry::set('navigation', array());
+ Tygh::$app['view']->assign('cart_products', $cart_products);
+ Tygh::$app['view']->assign('cart', $_cart);
+
+ $params['cart'] = $_cart;
+
+ if (AREA == 'C') {
+ $display_tpl = 'views/checkout/components/cart_items.tpl';
+ } else {
+ $display_tpl = 'views/order_management/components/products.tpl';
+ }
+ }
+
+ $data = isset($product_data) ? $product_data : $cart_products;
+
+ fn_set_hook('after_options_calculation', $mode, $data);
+
+ Tygh::$app['view']->display($display_tpl);
+
+ return true;
+}
+
+/**
+ * Gets the data about the product's stock and options based on the passed data
+ * of the product that is being changed in cart or in the order.
+ * The function is used only in controllers.
+ *
+ * @param array $product_data The data of the chaged product.
+ * @param array $auth Authentication data.
+ *
+ * @return bool|array The array with the product data.
+ */
+function fn_get_additional_product_data(&$product_data, $auth)
+{
+ $_auth = $auth;
+
+ list($product_id, $_data) = each($product_data['product_data']);
+ $product_id = isset($_data['product_id']) ? $_data['product_id'] : $product_id;
+ $selected_options = empty($_data['product_options']) ? array() : $_data['product_options'];
+
+ unset($selected_options['AOC']);
+
+ if (isset($product_data['additional_info']['info_type']) && $product_data['additional_info']['info_type'] == 'D') {
+ $product = fn_get_product_data($product_id, $_auth, CART_LANGUAGE, '', true, true, true, true, ($auth['area'] == 'A'));
+ } else {
+ $specific_settings['pid'] = $product_id;
+ list($product) = fn_get_products($specific_settings);
+ $product = reset($product);
+ }
+
+ if (empty($product)) {
+ return false;
+ }
+
+ $product['changed_option'] = isset($product_data['changed_option']) ? reset($product_data['changed_option']) : '';
+ $product['selected_options'] = $selected_options;
+
+ if (!empty($_data['amount'])) {
+ $product['selected_amount'] = $_data['amount'];
+ }
+
+ // Get specific settings
+ $specific_settings = array(
+ 'get_icon' => isset($params['additional_info']['get_icon']) ? $params['additional_info']['get_icon'] : false,
+ 'get_detailed' => isset($params['additional_info']['get_detailed']) ? $params['additional_info']['get_detailed'] : false,
+ 'get_options' => isset($params['additional_info']['get_options']) ? $params['additional_info']['get_options'] : true,
+ 'get_discounts' => isset($params['additional_info']['get_discounts']) ? $params['additional_info']['get_discounts'] : true,
+ 'get_features' => isset($params['additional_info']['get_features']) ? $params['additional_info']['get_features'] : false,
+ );
+
+ fn_set_hook('get_additional_information', $product, $product_data);
+
+ fn_gather_additional_product_data($product, $specific_settings['get_icon'], $specific_settings['get_detailed'], $specific_settings['get_options'], $specific_settings['get_discounts'], $specific_settings['get_features']);
+
+ if (isset($product['inventory_amount'])) {
+ $product['amount'] = $product['inventory_amount'];
+ }
+
+ if (!empty($params['extra_id'])) {
+ $product['product_id'] = $params['extra_id'];
+ }
+
+ Tygh::$app['view']->assign('product', $product);
+
+ return $product;
+}
+
+/**
+ * Updates the image of the product in the product list template.
+ * The function is used only in controllers.
+ *
+ * @param array $params An array of parameters.
+ *
+ * @return void
+ */
+function fn_update_product_image_in_template($params)
+{
+ // Update the images in the list/grid templates
+ if (!empty($params['image'])) {
+ $images_data = array();
+
+ foreach ($params['image'] as $div_id => $value) {
+ list($obj_id, $width, $height, $type) = explode(',', $value['data']);
+ $images_data[$div_id] = array(
+ 'obj_id' => $obj_id,
+ 'width' => $width,
+ 'height' => $height,
+ 'type' => $type,
+ 'link' => isset($value['link']) ? $value['link'] : '',
+ );
+ }
+
+ Tygh::$app['view']->assign('images', $images_data);
+ }
+}
+
+/**
+ * Gets the product data depending on the newly-selected options,
+ * and records the data in the $cart session array.
+ * The function is used only in controllers.
+ *
+ * @param array $cart_products The data of the product.
+ * @param array $cart Array of cart content.
+ *
+ * @return array|null The array with the product data.
+ */
+function fn_get_product_options_data($cart_products, &$cart)
+{
+ foreach ($cart_products as $cart_id => $item) {
+ if (isset($cart['products'][$cart_id])) {
+ $amount = isset($item['amount']) ? $item['amount'] : 1;
+ $product_data = fn_get_product_data($item['product_id'], $auth, CART_LANGUAGE, '', false, false, false, false, false, false, false);
+
+ if ($product_data['options_type'] == 'S' && isset($item['product_options']) && isset($params['changed_option'][$cart_id])) {
+ $item['product_options'] = fn_fill_sequential_options($item, $params['changed_option'][$cart_id]);
+ unset($params['changed_option']);
+ }
+
+ $product_options = isset($item['product_options']) ? $item['product_options'] : array();
+ $amount = fn_check_amount_in_stock($item['product_id'], $amount, $product_options, $cart_id, $cart['products'][$cart_id]['is_edp'], 0, $cart);
+
+ if ($amount === false) {
+ continue;
+ }
+
+ $cart['products'][$cart_id]['amount'] = $amount;
+ $cart['products'][$cart_id]['selected_options'] = isset($item['product_options']) ? $item['product_options'] : array();
+ $cart['products'][$cart_id]['product_options'] = fn_get_selected_product_options($item['product_id'], $cart['products'][$cart_id]['selected_options']);
+ $cart['products'][$cart_id] = fn_apply_options_rules($cart['products'][$cart_id]);
+ $cart['products'][$cart_id]['product_options'] = $cart['products'][$cart_id]['selected_options'];
+
+ if (!empty($cart['products'][$cart_id]['extra']['saved_options_key'])) {
+ $cart['saved_product_options'][$cart['products'][$cart_id]['extra']['saved_options_key']] = $cart['products'][$cart_id]['product_options'];
+ }
+
+ if (!empty($item['object_id'])) {
+ $cart['products'][$cart_id]['object_id'] = $item['object_id'];
+
+ if (!empty($cart['products'][$cart_id]['extra']['saved_options_key'])) {
+ // Product from promotion. Save object_id for this product
+ $cart['saved_object_ids'][$cart['products'][$cart_id]['extra']['saved_options_key']] = $item['object_id'];
+ }
+ }
+
+ unset($cart['products'][$cart_id]['extra']['exclude_from_calculate']);
+ }
+ }
+
+ return isset($product_data) ? $product_data : null;
+}
+
+/**
+ * Changes the product data in the $cart array.
+ * The function is used only in controllers.
+ *
+ * @param array $cart_products The data of the product.
+ * @param $cart Array of cart content.
+ *
+ * @return void
+ */
+function fn_change_product_data_in_cart(&$cart_products, &$cart)
+{
+ if (!empty($cart_products)) {
+ foreach ($cart_products as $k => $product) {
+ if (!empty($product['object_id'])) {
+ $c_product = !empty($cart['products'][$k]) ? $cart['products'][$k] : array();
+
+ unset($cart_products[$k], $cart['products'][$k]);
+
+ $cart['products'][$product['object_id']] = $c_product;
+ $cart_products[$product['object_id']] = $product;
+ $k = $product['object_id'];
+ }
+
+ $cart_products[$k]['changed_option'] = isset($product['object_id']) ? isset($params['changed_option'][$product['object_id']]) ? $params['changed_option'][$product['object_id']] : '' : isset($params['changed_option'][$k]) ? $params['changed_option'][$k] : '' ;
+ }
+ }
+}
\ No newline at end of file
diff --git a/init.php b/init.php
index fb0381d..f2bd235 100644
--- a/init.php
+++ b/init.php
@@ -65,7 +65,8 @@ $fn_list = array(
'fn.log.php',
'fn.companies.php',
'fn.addons.php',
- 'fn.exim.php'
+ 'fn.exim.php',
+ 'fn.order_management.php'
);
$fn_list[] = 'fn.' . strtolower(PRODUCT_EDITION) . '.php';
diff --git a/install/app/Installer/App.php b/install/app/Installer/App.php
index 9273ea4..ab7f603 100644
--- a/install/app/Installer/App.php
+++ b/install/app/Installer/App.php
@@ -155,7 +155,8 @@ class App
'fn.images.php',
'fn.log.php',
'fn.promotions.php',
- 'fn.locations.php'
+ 'fn.locations.php',
+ 'fn.order_management.php'
);
if (PRODUCT_EDITION == 'MULTIVENDOR' || PRODUCT_EDITION == 'ULTIMATE') {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment