Created
December 19, 2017 05:36
-
-
Save uzaharova/618fa0f59e9601a1f23855a9b4d566a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/google_export/func.php b/app/addons/google_export/func.php | |
index 3f9c0dd..0f0c506 100644 | |
--- a/app/addons/google_export/func.php | |
+++ b/app/addons/google_export/func.php | |
@@ -599,6 +599,8 @@ function fn_export_get_options_product_google_export($data, &$result, &$export_f | |
$product_id = $data[$k_result][$lang_code]['product_id']; | |
} | |
+ $product = $data[$k_result][$lang_code]; | |
+ | |
foreach ($export_options as $export_option) { | |
if (!empty($d_product[$lang_code][$export_option]) && is_array($d_product[$lang_code][$export_option])) { | |
$options[$export_option] = $d_product[$lang_code][$export_option]; | |
@@ -656,6 +658,17 @@ function fn_export_get_options_product_google_export($data, &$result, &$export_f | |
$cart_id | |
); | |
+ /** | |
+ * Changes the product data account for combinations. | |
+ * | |
+ * @param array $product Array with export the product data | |
+ * @param int $product_id Product identifier | |
+ * @param array $product_options Array with product options | |
+ * @param array $data_product Array with product data | |
+ * @param int $cart_id Combination hash | |
+ */ | |
+ fn_set_hook('google_export_change_product', $product, $product_id, $product_options['product_options'], $data_product, $cart_id); | |
+ | |
if (!empty($data_product)) { | |
$count_products++; | |
@@ -698,7 +711,7 @@ function fn_export_get_options_product_google_export($data, &$result, &$export_f | |
$d_combination['item_group_id'] = $product_id; | |
$d_combination['Product id'] = $cart_id; | |
- | |
+ | |
foreach ($combination as $k_combination => $_combination) { | |
if (isset($d_combination[$k_combination])) { | |
$d_combination[$k_combination] = $_combination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/func.php b/app/addons/product_variations/func.php | |
index 68a109f..fae8275 100644 | |
--- a/app/addons/product_variations/func.php | |
+++ b/app/addons/product_variations/func.php | |
@@ -15,75 +15,13 @@ | |
use Tygh\Registry; | |
use Tygh\Addons\ProductVariations\Product\Manager as ProductManager; | |
use Tygh\Addons\ProductVariations\Product\AdditionalDataLoader; | |
-use Tygh\Common\OperationResult; | |
use Tygh\Enum\ProductTracking; | |
use Tygh\Storage; | |
-use Tygh\BlockManager\Block; | |
use Tygh\BlockManager\ProductTabs; | |
if (!defined('BOOTSTRAP')) { die('Access denied'); } | |
/** | |
- * Add-on install handler | |
- */ | |
-function fn_product_variations_install() | |
-{ | |
- if (fn_allowed_for('ULTIMATE')) { | |
- $company_ids = fn_get_all_companies_ids(); | |
- } else { | |
- $company_ids = array(0); | |
- } | |
- | |
- $block = Block::instance(); | |
- $product_tabs = ProductTabs::instance(); | |
- | |
- foreach ($company_ids as $company_id) { | |
- $block_data = array( | |
- 'type' => 'products', | |
- 'properties' => array( | |
- 'template' => 'addons/product_variations/blocks/products/variations_list.tpl', | |
- 'product_variations.hide_add_to_wishlist_button' => 'N', | |
- 'hide_add_to_cart_button' => 'N', | |
- ), | |
- 'content_data' => array( | |
- 'content' => array( | |
- 'items' => array( | |
- 'filling' => 'product_variations.variations_filling', | |
- 'limit' => '10', | |
- 'variations_in_stock' => 'N', | |
- ), | |
- ), | |
- ), | |
- 'company_id' => $company_id, | |
- ); | |
- | |
- $block_description = array( | |
- 'lang_code' => DEFAULT_LANGUAGE, | |
- 'name' => __('product_variations.variations_list_block_name', array(), DEFAULT_LANGUAGE), | |
- ); | |
- | |
- $block_id = $block->update($block_data, $block_description); | |
- | |
- $tab_data = array( | |
- 'tab_type' => 'B', | |
- 'block_id' => $block_id, | |
- 'template' => '', | |
- 'addon' => 'product_variations', | |
- 'status' => 'A', | |
- 'is_primary' => 'N', | |
- 'position' => false, | |
- 'product_ids' => null, | |
- 'company_id' => $company_id, | |
- 'show_in_popup' => 'Y', | |
- 'lang_code' => DEFAULT_LANGUAGE, | |
- 'name' => __('product_variations.variations_list_tab_name', array(), DEFAULT_LANGUAGE), | |
- ); | |
- | |
- $product_tabs->update($tab_data); | |
- } | |
-} | |
- | |
-/** | |
* Returns a value indicating whether the give value is "empty". | |
* | |
* The value is considered "empty", if one of the following conditions is satisfied: | |
@@ -213,186 +151,6 @@ function fn_product_variations_normalize_tracking($tracking) | |
} | |
/** | |
- * Fetches available options based on existent variations | |
- * | |
- * @param int $product_id Product id | |
- * | |
- * @return \Tygh\Common\OperationResult | |
- */ | |
-function fn_product_variations_get_available_options($product_id) | |
-{ | |
- /** @var ProductManager $product_manager */ | |
- $product_manager = Tygh::$app['addons.product_variations.product.manager']; | |
- | |
- /** @var \Tygh\Common\OperationResult $result */ | |
- $result = new OperationResult(); | |
- | |
- $product_options = fn_get_product_options($product_id, CART_LANGUAGE, true, true); | |
- | |
- if ($product_manager->hasProductVariations($product_id)) { | |
- $data = array(); | |
- $used_option_ids = $product_manager->getProductVariationOptionsValue($product_id); | |
- | |
- foreach ($used_option_ids as $option_id) { | |
- // if there is an option, that used for existent variations, but now, the option is not available | |
- // we cannot generate variations | |
- if (!isset($product_options[$option_id])) { | |
- $result->addError( | |
- 'unable_to_generate_variations', | |
- __('product_variations.cannot_generate_variations_reason_options') | |
- ); | |
- break; | |
- } | |
- | |
- $data[$option_id] = $product_options[$option_id]; | |
- } | |
- | |
- $result->setData($data); | |
- } else { | |
- $result->setData($product_options); | |
- } | |
- | |
- $result->setSuccess(!$result->hasErrors()); | |
- | |
- return $result; | |
-} | |
- | |
-/** | |
- * Fetches options combinations by provided options and variants and rearranges them | |
- * | |
- * @param array $product_data Product data | |
- * @param array $product_options Array of product options | |
- * | |
- * @return array | |
- */ | |
-function fn_product_variations_get_options_combinations($product_data, $product_options) | |
-{ | |
- /** @var ProductManager $product_manager */ | |
- $product_manager = Tygh::$app['addons.product_variations.product.manager']; | |
- | |
- $result = array(); | |
- $selected_options_ids = $selected_variant_ids = array(); | |
- | |
- foreach ($product_options as $option_id => $option) { | |
- $selected_options_ids[$option_id] = $option_id; | |
- | |
- foreach ($option['variants'] as $variant_id => $variant) { | |
- $selected_variant_ids[$option_id][$variant_id] = $variant_id; | |
- } | |
- } | |
- | |
- if (!empty($selected_options_ids) && !empty($selected_variant_ids)) { | |
- $options_combinations = fn_get_options_combinations($selected_options_ids, $selected_variant_ids); | |
- | |
- foreach ($options_combinations as $item) { | |
- // restore original options order | |
- $selected_options = array_reverse($item, true); | |
- $name_parts = array(); | |
- $variation_code = $product_manager->getVariationCode($product_data['product_id'], $selected_options); | |
- | |
- $combination = array( | |
- 'selected_options' => $selected_options, | |
- 'variants' => array(), | |
- 'exists' => $product_manager->existsProductVariation($product_data['product_id'], $variation_code) | |
- ); | |
- | |
- foreach ($selected_options as $option_id => $variant_id) { | |
- $option = $product_options[$option_id]; | |
- $variant = $option['variants'][$variant_id]; | |
- $variant['option_name'] = $option['option_name']; | |
- | |
- $combination['variants'][$variant_id] = $variant; | |
- | |
- $name_parts[] = sprintf('%s: %s', $option['option_name'], $variant['variant_name']); | |
- } | |
- | |
- $combination['name'] = implode(', ', $name_parts); | |
- | |
- $result[$variation_code] = $combination; | |
- } | |
- } | |
- | |
- return $result; | |
-} | |
- | |
-/** | |
- * Gets variation by selected options. | |
- * | |
- * @param array $product Product data | |
- * @param array $product_options Product options | |
- * @param array $selected_options List of selected options | |
- * @param int $index Current variation index | |
- * | |
- * @return array | |
- */ | |
-function fn_product_variations_get_variation_by_selected_options( | |
- $product, | |
- $product_options, | |
- $selected_options, | |
- $index = 0 | |
-) { | |
- /** @var ProductManager $product_manager */ | |
- $product_manager = Tygh::$app['addons.product_variations.product.manager']; | |
- | |
- $options = array(); | |
- $name_parts = array('product_name' => $product['product']); | |
- $variation_code = $product_manager->getVariationCode($product['product_id'], $selected_options); | |
- | |
- foreach ($selected_options as $option_id => $variant_id) { | |
- $option_id = (int) $option_id; | |
- $variant_id = (int) $variant_id; | |
- | |
- $option = $product_options[$option_id]; | |
- $option['value'] = $variant_id; | |
- | |
- $variant = $product_options[$option_id]['variants'][$variant_id]; | |
- $name_parts[$option_id] = $option['option_name'] . ': ' . $variant['variant_name']; | |
- | |
- $options[$option_id] = $option; | |
- } | |
- | |
- $combination = array( | |
- 'name' => implode(', ', $name_parts), | |
- 'price' => $product['price'], | |
- 'list_price' => $product['list_price'], | |
- 'weight' => $product['weight'], | |
- 'amount' => empty($product['amount']) ? 1 : $product['amount'], | |
- 'code' => !empty($product['product_code']) ? $product['product_code'] . $index : '', | |
- 'options' => $options, | |
- 'selected_options' => $selected_options, | |
- 'variation' => $variation_code, | |
- 'status' => 'A', | |
- ); | |
- | |
- return $combination; | |
-} | |
- | |
-/** | |
- * Gets last used index for variation product code | |
- * | |
- * @param int $product_id Product id | |
- * | |
- * @return int | |
- */ | |
-function fn_product_variations_get_last_product_code_index($product_id) | |
-{ | |
- /** @var ProductManager $product_manager */ | |
- $product_manager = Tygh::$app['addons.product_variations.product.manager']; | |
- | |
- $index_list = array(0); | |
- $product_code = $product_manager->getProductFieldValue($product_id, 'product_code'); | |
- $variation_skus = db_get_fields('SELECT product_code FROM ?:products WHERE parent_product_id = ?i', $product_id); | |
- | |
- foreach ($variation_skus as $sku) { | |
- if (strpos($sku, $product_code) === 0) { | |
- $index_list[] = (int) str_replace($product_code, '', $sku); | |
- } | |
- } | |
- | |
- return max($index_list); | |
-} | |
- | |
-/** | |
* Hook handler: after delete all product option. | |
*/ | |
function fn_product_variations_poptions_delete_product_post($product_id) | |
@@ -667,7 +425,6 @@ function fn_product_variations_update_product_pre(&$product_data, $product_id, $ | |
{ | |
/** @var \Tygh\Addons\ProductVariations\Product\Manager $product_manager */ | |
$product_manager = Tygh::$app['addons.product_variations.product.manager']; | |
- $current_product_data = $parent_product_data = array(); | |
if (!empty($product_id)) { | |
$current_product_data = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $product_id); | |
@@ -692,20 +449,9 @@ function fn_product_variations_update_product_pre(&$product_data, $product_id, $ | |
} | |
if ($product_type === ProductManager::PRODUCT_TYPE_VARIATION) { | |
- $current_variation_options = isset($current_product_data['variation_options']) ? json_decode($current_product_data['variation_options'], true) : null; | |
+ $current_variation_options = isset($current_product_data['variation_options']) ? json_decode($current_product_data['variation_code']) : null; | |
$variation_options = isset($product_data['variation_options']) ? $product_data['variation_options'] : null; | |
- if (!$variation_options | |
- && isset($product_data['variation_code']) | |
- && $product_data['variation_code'] != $current_product_data['variation_code'] | |
- ) { | |
- $variation_options = $product_manager->getSelectedOptionsByVariationCode($product_data['variation_code']); | |
- | |
- if (empty($variation_options)) { | |
- fn_set_notification('E', __('error'), __('product_variations.cannot_change_variation_options')); | |
- } | |
- } | |
- | |
if (empty($parent_product_data)) { | |
fn_set_notification('E', __('error'), __('product_variations.error.product_variation_must_have_parent_product')); | |
$can_update = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/init.php b/app/addons/product_variations/init.php | |
index 751f37d..466c4fe 100644 | |
--- a/app/addons/product_variations/init.php | |
+++ b/app/addons/product_variations/init.php | |
@@ -57,5 +57,6 @@ fn_register_hooks( | |
'delete_product_post', | |
'tools_change_status', | |
'get_product_data_pre', | |
- 'load_products_extra_data' | |
+ 'load_products_extra_data', | |
+ 'google_export_change_product' | |
); | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment