Javascript Issue In Product Detail Page





{include file="buttons/update_for_all.tpl" display=$show_update_for_all object_id='full_description' name="update_all_vendors[full_description]"}

{__("notes")} : {__("product_detail_char_limit")}




I want to copy the Description from the Description field to the Seo Meta Description field while some one is updating the description. Tried that using the javascript as below but it doesnt work for the textarea - description field whereas the same code works for the product name field (product_description_product), can some one help me debug what can be the issue?


{literal}

{/literal}




It seems that the issue is because the textbox is redactor editor. I have no clue how to track keypress events on a wysiwyg editor. Any inputs ?

It does not work due to the WYSIWYG editor. If you switch it to the “source code” mode, it will work correctly. But the WYSIWYG in common mode does not use textearea field. Instead of javascript code we suggest you to use the update_product_pre hook in the fn_update_product function (app/functions/fn.catalog.php)

Hi Ecom,



Thanks for the info.



Where do we need to edit the code for update_product_pre , do we need to create a separate file for this in my_changes or should we just edit the code in the fn_update_product function?

  1. Enable the “My changes” module.


  2. Create “app/addons/my_changes/func.php” file with the code:


if (!defined('BOOTSTRAP')) { die('Access denied'); }

function fn_my_changes_update_product_pre(&$product_data, $product_id, $lang_code, $can_update)
{
$product_data['meta_description'] = $product_data['product'] . ' ' . strip_tags($product_data['full_description']);
}




3. Create “app/addons/my_changes/init.php” file with the code:


if (!defined('BOOTSTRAP')) { die('Access denied'); }

fn_register_hooks(
'update_product_pre'
);




(!) Not tested

Oh great, let me test this out and I will let you know the feedback.



You are awesome Ecom , whats your good name ?

Thanks Ecom, we will test it. Can you let us know one thing how can we add category name to the same string ?

[quote name=‘fleaffair’ timestamp=‘1437619942’ post=‘224035’]

Thanks Ecom, we will test it. Can you let us know one thing how can we add category name to the same string ?

[/quote]



Please try:


<br />
<?php<br />
if (!defined('BOOTSTRAP')) { die('Access denied'); }<br />
function fn_my_changes_update_product_pre(&$product_data, $product_id, $lang_code, $can_update)<br />
{<br />
    if (!empty($product_data['main_category'])) {<br />
	    $product_data['meta_description'] = $product_data['product'] . ' ' . strip_tags($product_data['full_description']) . ' ' . fn_get_category_name($product_data['main_category']);<br />
    }<br />
}<br />

```<br />
<br />
[quote name='technoob' timestamp='1437567187' post='223953']<br />
Oh great, let me test this out and I will let you know the feedback.<br />
<br />
You are awesome Ecom , whats your good name ?<br />
[/quote]<br />
<br />
Nikita, Alex and Oleg <img src="upload://rA9Qa8gnUPZzRZRdI8kt3dpjkrs.png" class="bbc_emoticon" alt=":)">

Thanks Ecom , it works for us.



Just one query , this code works when we enter a new product and update an existing product.



How can we ensure that the same logic happens when we import new products using Import Product functionality, is there a way to call the same code while import for each product so that it becomes consistent.



Thanks.

[quote name='fleaffair' timestamp='1437648077' post='224079']

Thanks Ecom , it works for us.



Just one query , this code works when we enter a new product and update an existing product.



How can we ensure that the same logic happens when we import new products using Import Product functionality, is there a way to call the same code while import for each product so that it becomes consistent.



Thanks.

[/quote]



I am afraid, there is no easy way to do it. Additional code modifications are required

Hi Ecom,



Can you let me know which file and function is responsible for this and then i can have a look at that code and modify accordingly. Thanks once again for all the help.



Amit

There is the fn_exim_send_product_notifications function in the app\schemas\exim\products.functions.php file which is called when the import process is completed. This function can be corrected according to your needs

Hi Ecom,



This function is called when all the processing is completed. We need to update the Product - Meta Keywords, Title and Meta Descriptions while import is happening. I am not sure if this is the right function. Please confirm.


function fn_exim_send_product_notifications($primary_object_ids, $import_data)
{
if (empty($primary_object_ids) || !is_array($primary_object_ids)) {
return true;
}
$auth = & $_SESSION['auth'];
//Send notification for all updated products. Notification will be sent only if product have subscribers.
foreach ($primary_object_ids as $k => $v) {
if (!empty($v['product_id'])) {
$product_amount = db_get_field('SELECT amount FROM ?:products WHERE product_id = ?i', $v['product_id']);
if ($product_amount > 0) {
fn_send_product_notifications($v['product_id']);
}
}
}
return true;
}


Thanks.