Created
June 22, 2020 08:39
-
-
Save ichaykin/397a5187b22a30b8f9ae82cdd0711871 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/master_products/func.php b/app/addons/master_products/func.php | |
index 1593311..144289a 100644 | |
--- a/app/addons/master_products/func.php | |
+++ b/app/addons/master_products/func.php | |
@@ -137,7 +137,7 @@ function fn_master_products_get_products( | |
} | |
$condition .= db_quote(' AND products.master_product_id = ?i', $master_product_id); | |
- } elseif (empty($params['runtime_company_id']) && empty($params['pid'])) { | |
+ } elseif (empty($params['runtime_company_id']) && empty($params['pid']) && empty($params['only_for_counting'])) { | |
$condition .= db_quote(' AND products.master_product_id = ?i AND (products.company_id > 0 OR products.master_product_offers_count > 0)', 0); | |
if (fn_allowed_for('MULTIVENDOR')) { | |
@@ -1129,3 +1129,56 @@ function fn_master_products_after_options_calculation($mode, $data) | |
$view->assign('no_capture', false); | |
} | |
} | |
+ | |
+/** | |
+ * The "discussion_is_user_eligible_to_write_review_for_product_post" hook handler. | |
+ * | |
+ * Actions performed: | |
+ * - Checks if common product is bought by chosen user | |
+ * | |
+ * @see fn_discussion_is_user_eligible_to_write_review_for_product | |
+ */ | |
+function fn_master_products_discussion_is_user_eligible_to_write_review_for_product_post($user_id, $product_id, &$result, $need_to_buy_first) | |
+{ | |
+ if (!$result && $need_to_buy_first) { | |
+ $product_map = ServiceProvider::getProductIdMap(); | |
+ if ($product_map->isVendorProduct($product_id)) { | |
+ $master_product_id = $product_map->getMasterProductId($product_id); | |
+ } else { | |
+ $master_product_id = $product_id; | |
+ } | |
+ $product_repository = ServiceProvider::getProductRepository(); | |
+ $product_ids = $product_repository->findVendorProductIds($master_product_id); | |
+ if (!empty($product_ids)) { | |
+ $query = VariationsServiceProvider::getQueryFactory()->createQuery( | |
+ 'orders', | |
+ ['user_id' => $user_id], | |
+ ['orders.order_id'], | |
+ 'orders' | |
+ ); | |
+ $query->addLeftJoin('details', 'order_details', ['order_id' => 'order_id'], ['product_id' => $product_ids]); | |
+ $query->setLimit(1); | |
+ $result = (bool) $query->column(); | |
+ } | |
+ } | |
+} | |
+ | |
+/** | |
+ * The "create_seo_name_pre" hook handler. | |
+ * | |
+ * Actions performed: | |
+ * - Updates object name for vendor common product. | |
+ * | |
+ * @see fn_create_seo_name | |
+ */ | |
+function fn_master_products_create_seo_name_pre($object_id, $object_type, &$object_name, $index, $dispatch, $company_id, $lang_code, $params) | |
+{ | |
+ if ($object_type === 'p') { | |
+ $repository = ServiceProvider::getProductRepository(); | |
+ $product = current($repository->findVendorProductsInfo([$object_id])); | |
+ | |
+ if (!empty($product['master_product_id']) && !empty($product['company_id'])) { | |
+ $object_name = fn_seo_get_name('p', $product['master_product_id']) . SEO_DELIMITER . fn_seo_get_name('m', $product['company_id']); | |
+ } | |
+ } | |
+} |
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/master_products/init.php b/app/addons/master_products/init.php | |
index 2591392..5f773e1 100644 | |
--- a/app/addons/master_products/init.php | |
+++ b/app/addons/master_products/init.php | |
@@ -66,5 +66,7 @@ fn_register_hooks( | |
['master_products_create_vendor_product', '', 'product_variations'], | |
'seo_get_schema_org_markup_items_post', | |
- 'after_options_calculation' | |
+ 'after_options_calculation', | |
+ 'discussion_is_user_eligible_to_write_review_for_product_post', | |
+ 'create_seo_name_pre' | |
); |
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/design/themes/responsive/templates/addons/discussion/hooks/companies/data_block.pre.tpl b/design/themes/responsive/templates/addons/discussion/hooks/companies/data_block.pre.tpl | |
index 77dc119..6b74bf8 100644 | |
--- a/design/themes/responsive/templates/addons/discussion/hooks/companies/data_block.pre.tpl | |
+++ b/design/themes/responsive/templates/addons/discussion/hooks/companies/data_block.pre.tpl | |
@@ -10,6 +10,7 @@ | |
{include file="addons/discussion/views/discussion/components/stars.tpl" | |
stars=$average_rating|fn_get_discussion_rating | |
link="companies.view?company_id={$company.company_id}&selected_section=discussion#discussion" | |
+ link_target="url" | |
} | |
{/if} | |
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/design/themes/responsive/templates/addons/discussion/views/discussion/components/stars.tpl b/design/themes/responsive/templates/addons/discussion/views/discussion/components/stars.tpl | |
index 72db62b..4ac1f16 100644 | |
--- a/design/themes/responsive/templates/addons/discussion/views/discussion/components/stars.tpl | |
+++ b/design/themes/responsive/templates/addons/discussion/views/discussion/components/stars.tpl | |
@@ -1,13 +1,18 @@ | |
+{$link_target=$link_target|default:"auto"} | |
+{if !($link_target === "auto" | |
+ && ($runtime.controller == "products" || $runtime.controller == "companies") | |
+ && $runtime.mode === "view" | |
+ && !$product.average_rating) | |
+} | |
+ {$link_target = "url"} | |
+{/if} | |
+ | |
<span class="ty-nowrap ty-stars"> | |
{if $link} | |
- {if ($runtime.controller == "products" || $runtime.controller == "companies") && $runtime.mode == "view"} | |
- {if $product.average_rating} | |
- <a href="{$link|fn_url}"> | |
- {else} | |
- <a class="cm-external-click" data-ca-scroll="content_discussion" data-ca-external-click-id="discussion"> | |
- {/if} | |
- {else} | |
+ {if $link_target === "url"} | |
<a href="{$link|fn_url}"> | |
+ {else} | |
+ <a class="cm-external-click" data-ca-scroll="content_discussion" data-ca-external-click-id="discussion"> | |
{/if} | |
{/if} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment