Jump to content
Tsimi

quickly adding products description?

Recommended Posts

I didn't know where to start a topic so I hope I'm in the right place here.

 

The past few days I needed to add a lot new products and realized how time consuming and repetitive it is to always copy & paste the products description for 3 different languages.

In my case I don't always use "the exact" same description for all items, similar but not same.

I was wondering if there is an easy way of doing that and looked around in the add-ons section and found this

 

Comment Toolbar

 

What it does?

 

 

The purpose of this modification is to basically make the life
easier of those of you whom rely heavily on the comments box
to give your customer information about their order.

I got quite tired of typing or copying and pasting in the same
text to let their customer know their order has been shipped,
backordered, etc.

Comments Toolbar simply adds any number of buttons under your
comments box for orders.php in admin that basically act as macro
buttons.

 

I looked at the code to see if it would be possible to have that changed to work in a similar fashion but instead of adding status updates add pre-defined products descriptions.

This add-on uses java script and it works only if you have "one" input field.

 

What needs to be done to make that work for multiple text input fields?

Edited by Tsimi

Share this post


Link to post
Share on other sites

I may not understand what you are looking for but it sounds like you want something that will convert the text to another language for you. In that case, no, there's nothing in oscommerce that does that, at least that I know of. You could install the google language translator code and it will translate the pages for you. You still have to have the text in place though. But that would be an easy job for Easy Populate or you could alter the code in admin to automatically fill in the other language descriptions using the one you fill in. 

Share this post


Link to post
Share on other sites

Hi Jack

 

I don't want it to translate the description. I would like to predefine the text/description for all languages.

Imagine you have buttons in the add/edit products area. Button 1 has a description in english, Button 2 has the same description in french, Button 3 same description in german. Now what i do is click on the "english" text input field and press Button 1. Now i should have the predefined english description inserted. Next i click on the french text input field and click on Button 2 to insert the predefined french description.

Does that make sense?

Edited by Tsimi

Share this post


Link to post
Share on other sites

Thanks. I think I understand now. That functionality doesn't exist in a standard shop so you would have to add it. There aren't any addons that do that that I am aware of. You can add one button to load one piece of text to all language descriptions, or have a button for each language if the text needs to be different.

Share this post


Link to post
Share on other sites

After some more research and with help of the Comment Toolbar Add-on mentioned above I created this so far;

 

inside the admin/categories.php where this code is

<td class="main"><?php echo tep_draw_textarea_field('products_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (empty($pInfo->products_id) ? '' : tep_get_products_description($pInfo->products_id, $languages[$i]['id']))); ?></td>

I added right after it this code

<td><?php echo tep_draw_separator('pixel_trans.gif', '24', '15'); ?></td>
<td>
 <button onClick="return addText('<?php echo(TEXT_AREA_TEXT); ?>');"><?php echo TEXT_BUTTON_01; ?></button>
 <button onClick="return addText('<?php echo(TEXT_AREA_TEXT2); ?>');"><?php echo TEXT_BUTTON_02; ?></button>
 <button onClick="return killbox();"><?php echo TEXT_BUTTON_RESET; ?></button>
</td>

just near that area I added this

<script language="javascript">
function addText(obj) {
			var textareas = document.getElementsByTagName('textarea');
			var myTextarea = textareas.item(0);	{
			myTextarea.value = obj;
			}
			return false;			
   }

   function killbox() {
			var box = document.getElementsByTagName('textarea');
			var killbox = box.item(0);
			killbox.value = '';
			return false;
	}
</script>

then added the following language definitions to the english.php file

define('TEXT_AREA_TEXT', 'This is a test description text!');
define('TEXT_AREA_TEXT2', 'This is another test description tex!');
define('TEXT_BUTTON_RESET', 'Reset');
define('TEXT_BUTTON_01', 'Description 1');
define('TEXT_BUTTON_02', 'Description 2');

Now I can predefine the descriptions inside the english.php and add as many I need by duplicating the buttons and language definitions.

The last problem left is that it doesn't work with multiple languages.

If you have only english it works like a charm but if you have additional languages like german or french and so on....the buttons don't work for that language field.

As you can see in the following image there are buttons next to each field but they won't add any predefined text. (other language description is defined inside the german.php or french.php)

 

 

 

Unfortunately my skill comes to an end here and I would appreciate if someone could lend me a hand with this one to figure out the missing piece of the puzzle.

 

 

Share this post


Link to post
Share on other sites

It's because your javascript is only setup to handle the first textarea. Even if you change it to handle the others, it will create a problem should you ever install an addon that adds more textarea's. You need to include an ID for the textarea's you want to edit and then cycle through all of the textarea and only change the ones with the correct ID's. Or, if you are going to have a separate button per textarea, just add another function for the other textarea's. So you would end up with something like

function addText2(obj) {
			var textareas = document.getElementsByTagName('textarea');
			var myTextarea = textareas.item(1);

That method uses more code than is necessary but it works. Or, you can pass the ID of the textarea to the function so that it is something like

function addText(whichone) {
			var textareas = document.getElementsByTagName('textarea');
			var myTextarea = textareas.item(whichone);

Share this post


Link to post
Share on other sites

Thanks for your answer Jack.

 

What you are saying makes perfectly sense.

The thing is that there is actually only one textarea (defined in html_output.php) and only added additional when a new language is detected.

If I would create the textareas by myself in HTML then it would be very easy but I have no clue as how osC is creating these additional, other language textareas.

They have an id if i take a look at the site by using FF webdev tool id="products_description[4]" (4 = german) but any attempt to use that failed so far.

Share this post


Link to post
Share on other sites

That is built using the language ID. You can build javascript to handle it but it is not a simple change if you are not familiar with such things. The textarea in html_output is the function used to create the textarea's. You shouldn't be editing it. You need to edit the code in the categories.php file. Just change this code

 <button onClick="return addText('<?php echo(TEXT_AREA_TEXT); ?>');"><?php echo TEXT_BUTTON_01; ?></button>
 <button onClick="return addText('<?php echo(TEXT_AREA_TEXT2); ?>');"><?php echo TEXT_BUTTON_02; ?></button>

to this

 <button onClick="return addText('1');"><?php echo TEXT_BUTTON_01; ?></button>
 <button onClick="return addText('2');"><?php echo TEXT_BUTTON_02; ?></button>

Then check that number in the addText function and populate as needed.

Share this post


Link to post
Share on other sites

Hi Jack

 

Just wanted to inform that I finally got it working.

It was more complex then I thought. To have it for only one language is pretty straight forward but to have it for multiple languages was very difficult to achieve with the approach that I was trying so far.

Whitehat coded something that helped me achieve what I wanted.

Changes that needed to be done were, two new database tables, some javascript in the categories.php and a brand new page in the admin to add/edit and remove the descriptions.

 

Thanks again for your help.

 

P.S.

And also a BIG thank you to Whitehat, gadlol and burt for giving me the right code pieces and hints.

Edited by Tsimi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×