Author Topic: multilanguage feature  (Read 144719 times)

esteve

  • Jr. Member
  • **
  • Posts: 65
multilanguage feature
« on: April 08, 2005, 17:46:36 pm »
Hi Soeren,
your shop is excellent!
I put a feature to it: multi-language front end. (mambelfish)

Some table column types have to change from varchar to int.
mos_pshop_category:       category_id varchar ->int
mos_pshop_category_xref:      category_parent_id, category_child_id  varchar ->int
mos_pshop_product_category_xref: category_id  varchar ->int

And in ps_product_category.php line 299

Code: [Select]
//      $category_id = md5(uniqid($hash_secret));
      $category_id = $this->get_categories_size(); //<-- mod by ei

And of course add this function:
Code: [Select]
  function get_categories_size() {
    $db = new ps_DB;
    $q = "SELECT count(*) AS num FROM #__pshop_category ";
    $db->query( $q );
    if($db->next_record())
        return $db->f("num")+1;
else
    return 0;
  }

That's all in connection with phpshop. (I hope it is not problem that categories are not identified by long hexa numbers, only by simple ints.)

Other part is belong to Mambelfish (which is also a very good component).
We have to modify it, to be able to handle tables with different column name (than "id").

administrator\components\com_mambelfish\mambelfish.class.php line 317
Code: [Select]
original:
case "referenceid":

if( strtolower($tableField->Name) != "id" ) {
$sqlFields[] = 'c.' .$tableField->Name. ' as id';
}

suggestion:
case "referenceid":

//MOD by ei
$contentid_exist = (isset($contentid) && $contentid!=-1 );
if( strtolower($tableField->Name) != "id" ) {
$sqlFields[] = 'c.' .$tableField->Name. ' as id';

//MOD by ei
if( $contentid_exist)           
$where[] = 'c.' .$tableField->Name. '=' .$contentid ;
}else {
    if( $contentid_exist )
$where[] = 'c.id=' .$contentid ;
}
//End of MOD by ei
               
administrator\components\com_mambelfish\mambelfish.class.php line 356
Code: [Select]
//$where[] = "c.id=" .$contentid . ""; //<-- commented out by ei

\components\com_mambelfish\classes\mambelfish.class.php in line 182 add a new func call
Code: [Select]

//MOD by ei
function help_non_standard_tables(&$content){
      if (!isset( $content->id )) {
//it would be better to parse from xml
if (isset( $content->product_id ))
$content->id = $content->product_id;
elseif (isset( $content->category_id ))
$content->id = $content->category_id;
  }
  }
//end MOD by ei

/** Cover function which tries to find out the id from the object
*
*/
  function translate( $content, $reference_table, $language ) {

        MambelFish::help_non_standard_tables($content); // <-- MOD by ei
  if( isset( $content->id ) ) {
$id = $content->id;

return MambelFish::translateWithID( $content, $id, $reference_table, $language );
  } else {
  return $content;
  }
}


There was an error in some cases in Mambelfish sql query:
mbf_content.reference_table='mos_pshop_product,'

This comma caused no hit (no product translation). So I added a little fix to
administrator\components\com_mambelfish\mambelfish.class.php line 1025:
Code: [Select]
$table = ereg_replace( ",", "", $table) ; //MOD by ei


After this we are ready. Now we can translate phpshop component, as any other component. Let's define xmls for mambelfish, for example

pshop_category.xml:
Code: [Select]
<?xml version="1.0" ?>
<mambelfish type="contentelement">
  <name>phpShop Product Category</name>
  <author>EI</author>
  <version>1.0</version>
  <description>Definition for phpShop component (Product Category)</description>
  <reference>
  <table name="pshop_category">
  <field type="referenceid" name="category_id" translate="0">ID</field>
  <field type="titletext" name="category_name" translate="1">Name</field>
  <field type="textarea" name="category_description" translate="1">Description</field>
  </table>
  </reference>
</mambelfish>

pshop_product.xml:
Code: [Select]
<?xml version="1.0" ?>
<mambelfish type="contentelement">
  <name>phpShop Products</name>
  <author>EI</author>
  <version>1.0</version>
  <description>Definition for phpShop component (Products)</description>
  <reference>
  <table name="pshop_product">
  <field type="referenceid" name="product_id" translate="0">ID</field>
  <field type="titletext" name="product_name" translate="1">Name</field>
  <field type="textarea" name="product_s_desc" translate="1">Short description</field>
  <field type="htmltext" name="product_desc" translate="1">Description</field>
  <field type="created_date" name="cdate" translate="0">Created</field>
  <field type="modified_date" name="mdate" translate="0">Modified</field>
  </table>
  </reference>
</mambelfish>

Copy this 2 xmls into administrator\components\com_mambelfish\contentelements\.
Finished. :)

cheers,
Steve

Soeren

  • Administrator
  • Hero Member
  • *
  • Posts: 3106
  • VirtueMart Starter
    • virtuemart.net
Re: multilanguage feature
« Reply #1 on: April 13, 2005, 21:54:22 pm »
Wow, thanks a lot for your solution!

Anyone got this working in a live shop?

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

html

  • Beginner
  • *
  • Posts: 1
Re: multilanguage feature
« Reply #2 on: April 22, 2005, 18:56:41 pm »
Hello,

it works with the above mmodifications.

Another modification is needed in

administrator\components\com_phpshop\classes\ps_csv.php

for

Code: [Select]
// $category_id = md5(uniqid($hash_secret));
$category_id = $this->get_categories_size();


Thank you both.


For soeren:
- Is it important for you to keep the category_id varchar instead of int?
- Could you make the changes in the next version of phpShop?

Regards.

Soeren

  • Administrator
  • Hero Member
  • *
  • Posts: 3106
  • VirtueMart Starter
    • virtuemart.net
Re: multilanguage feature
« Reply #3 on: April 24, 2005, 19:01:09 pm »
Hello,

I have made the necessary changes to the tables where the category ID is held. I agree to change the field type for the category ID from VARCHAR(32) to INT(11).

But I don't use the new function get_categories_size, because we can use the AUTO_INCREMENT value from the category_id field in the table mos_pshop_category. That's  easier and faster.

Thanks for this Mod.

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

Marcin

  • Beginner
  • *
  • Posts: 1
Re: multilanguage feature
« Reply #4 on: April 25, 2005, 09:32:45 am »
Hello,

I have several small corrections

administrator\components\com_mambelfish\mambelfish.class.php line 1025:
comma is necessary
Code: [Select]
$table = ereg_replace( "[\n,]", "", $table);
administrator\components\com_phpshop\classes\ps_product_category.php
add to queries $q, in functions:
get_child_list, get_child_descryption, print_subcategory, ...
field category_id
Code: [Select]
"SELECT category_id ..."
thnx Steve

Tim Brennan

  • Beginner
  • *
  • Posts: 3
Re: multilanguage feature
« Reply #5 on: April 28, 2005, 21:15:13 pm »
Boy I sure would like to know if anyone has this working properly.  I ran through the  hack, however i am unable to update the tables from VARCHAR to INT, getting an error:

SQL-query:
ALTER TABLE `mos_pshop_category` CHANGE `category_id` `category_id` INT( 32 ) NOT NULL
MySQL said: Documentation
#1062 - Duplicate entry '0' for key 1

Any suggestions???

Secondly,
When i load up the phpshop_category within mambelfish, i get a whack of errors that resemble:

Notice: Unknown column 'd0f7dfa472584ef9188f046d624b89f0' in 'where clause' in W:\www\Mambo451\includes\database.php on line 184
Unknown column \'d0f7dfa472584ef9188f046d624b89f0\' in \'where clause\' SQL=select * \n from mos_mbf_content\n where reference_id=d0f7dfa472584ef9188f046d624b89f0\n and reference_table=\'pshop_category\'
Warning: Invalid argument supplied for foreach() in W:\www\Mambo451\administrator\components\com_mambelfish\mambelfish.class.php on line 696


The categories still load, however i have yet to try and save....

Any suggestions on this??

BTW, excellent work..  Sure hope to get this working.

Cheers,

esteve

  • Jr. Member
  • **
  • Posts: 65
Re: multilanguage feature
« Reply #6 on: April 29, 2005, 11:08:05 am »
Hi Tim,

the reason of the error: your category table contains data.
First you should help to the data:
'd0f7dfa472584ef9188f046d624b89f' value cannot be converted to int, mysql has right.

Try to understand the 3 table and their relation (mos_pshop_category, mos_pshop_category_xref,
mos_pshop_product_category_xref), then you can change long hexa values to uniq int values (with hand). After this column types can be changed, and mambelfish can work on the table.

Soeren:
autoincrement is good idea. My function worked fine until I delete a category. After that size info is not sure uniq. I modified the function get_categories_size():
Code: [Select]
//    $q = "SELECT count(*) AS num FROM #__pshop_category ";
    $q = "SELECT max(category_id) AS num FROM #__pshop_category ";

Steve

Soeren

  • Administrator
  • Hero Member
  • *
  • Posts: 3106
  • VirtueMart Starter
    • virtuemart.net
Re: multilanguage feature
« Reply #7 on: April 29, 2005, 19:09:19 pm »
Hello,

this script is for upgrading the category field types to 1.2 stable:

Code: [Select]
/** THIS IS FOR MAMBELFISH - INTEGRATION
******************************************/
$database->setQuery( "SELECT category_id FROM #__pshop_category ORDER BY cdate" );
$category_rows = $database->loadObjectList();
$categories = Array();
$i = 1;
foreach( $category_rows as $category_row ) {
  $categories["old_id"] = $category_row->category_id;
  // assign the new_id to a Key named like the old_id
  $categories[$category_row->category_id] = $i++;
}
// Now as we have stored the old IDs we can update the table
// mos_pshop_categories
foreach( $category_rows as $category_row ) {
  $q = "UPDATE #__pshop_category SET category_id='".$categories[$category_row->category_id]."' WHERE category_id='".$category_row->category_id."'";
  $database->setQuery( $q ); $database->query();
}
// Alter the Table now
$database->setQuery( "ALTER TABLE `#__pshop_category` CHANGE `category_id` `category_id` INT( 11 ) NOT NULL AUTO_INCREMENT;" ); $database->query();

// Now update the Category XREF Table
foreach( $category_rows as $category_row ) {
  $q = "UPDATE #__pshop_category_xref SET category_parent_id='".$categories[$category_row->category_id]."' WHERE category_parent_id='".$category_row->category_id."'";
  $database->setQuery( $q );  $database->query();
  $q = "UPDATE #__pshop_category_xref SET category_child_id='".$categories[$category_row->category_id]."' WHERE category_child_id='".$category_row->category_id."'";
  $database->setQuery( $q );  $database->query();
}
// When we have done that, Alter the Table!
$database->setQuery( "ALTER TABLE `#__pshop_category_xref`
CHANGE `category_parent_id` `category_parent_id` INT( 11 ) DEFAULT '0' NOT NULL ,
CHANGE `category_child_id` `category_child_id` INT( 11 ) DEFAULT '0' NOT NULL;" ); $database->query();

// Now update the Product <-> Category XREF Table
foreach( $category_rows as $category_row ) {
  $q = "UPDATE #__pshop_product_category_xref SET category_id='".$categories[$category_row->category_id]."' WHERE category_id='".$category_row->category_id."'";
  $database->setQuery( $q );  $database->query();
}
// Alter the Table now
$database->setQuery( "ALTER TABLE `#__pshop_product_category_xref` CHANGE `category_id` `category_id` INT( 11 ) NOT NULL;" ); $database->query();
/*********************************
END MAMBELFISH ADJUSTMENT **/

I'm not sure wether you can integrate that into an Mambo Component to execute it once.

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

Tim Brennan

  • Beginner
  • *
  • Posts: 3
Re: multilanguage feature
« Reply #8 on: April 29, 2005, 19:21:19 pm »
Hi Soren,

Being somewhat new to mysql, etc..., where would i execute this script?  Would it be in phpmyadmin? 


Cheers,

Soeren

  • Administrator
  • Hero Member
  • *
  • Posts: 3106
  • VirtueMart Starter
    • virtuemart.net
Re: multilanguage feature
« Reply #9 on: April 29, 2005, 19:27:47 pm »
Hello,
there's a really "dirty" way to execute it: Just copy the code into the file /index.php of your Mambo Installation.
Insert it right after

Code: [Select]
$acl = new gacl_api();
Call your page ONCE. And then remove the code instantly.

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

sparx

  • Beginner
  • *
  • Posts: 1
Re: multilanguage feature
« Reply #10 on: June 01, 2005, 16:10:17 pm »
Hi,
i have upgrade the phpshop component from 1.2rc to 1.2pl2, and made the modifications to mambelfish.class.php and copied the xml files as well.
in mambelfish i can make the translation and i see the translated values, but when i change the language on the front end of the site nothing happens, also when i try to get "sample data" for products or category names in mambelfish i get a mysql error.

do i need to modify anything in the php_Shop component ?

Roxxinger

  • Beginner
  • *
  • Posts: 31
Re: multilanguage feature
« Reply #11 on: June 02, 2005, 11:20:58 am »
hi

ich have a problem with this hack too :(

i did all the modification from above and had no problem until
i wanted to translate a product/product category but the text wasnt saved as i pushed the save button

so it seems that it will not save the translation into the database for anyreason :(

anyone got an idea what is wrong?

oh just got a error as i tried to call the translate site in mambelfish:

You have an error in your SQL syntax near \'and reference_table=\'pshop_product\'\n and language_id=1\' at line 4 SQL=select * \n from mos_mbf_content\n where reference_id=\n and reference_table=\'pshop_product\'\n and language_id=1



thx for help :)

jan

p.s.: the original translation is also screwed :/ in frontend its is still correkct but in backand i cant add a new translation or change an existing one or unpublish it :(

Roxxinger

  • Beginner
  • *
  • Posts: 31
Re: multilanguage feature
« Reply #12 on: June 02, 2005, 14:02:32 pm »
so now i deleted every modification and i got the same error but the original translation works.

Roxxinger

  • Beginner
  • *
  • Posts: 31
Re: multilanguage feature
« Reply #13 on: June 03, 2005, 09:36:23 am »
update:

now it works but it shows no translation in the frontend or in the backend in the list...

the translation was insert into mos_mbf_content and publish was set to 1 but nothing change in the frontend or backend.

need help :)

jan

sergi_mambo

  • Beginner
  • *
  • Posts: 1
Re: multilanguage feature
« Reply #14 on: June 03, 2005, 18:39:17 pm »
language configuration -> code ISO is empty??

VirtueMart Forum

Re: multilanguage feature
« Reply #14 on: June 03, 2005, 18:39:17 pm »