I am trying to get a multi-price, multi-currency, multilingual site working using D 6.19, UC 2.4 and associated helpful modules ...

I have run into 'one or two' issues today but this one relates to the interaction between i18n (1.7), UC 2.4 and multiprice (latest dev release 2010-07-11).

In short:
I have a 'shop' with one product (in English). A translation for this node exists (in Spanish). Without uc_multiprice installed, a change in the price in either of the nodes has no effect on the price in the other. Once I have installed uc-multiprice and attempt the same action, the price(s) in the other associated node are deleted.

I will start reviewing the multiprice code but if anyone has had a similar experience please let me know. I cannot launch this site without the above-mentioned functionality so essentially this is a showstopper for me

If anyone wants some additional information I am only to happy to provide it.

Thanks and regards

Adam

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anea02’s picture

update:

I switched on the 'devel' module and had a look at the SQL being executed with and without the uc_multiprice module. Here are the results:

WITH uc_multiprice
Calling function: uc_product_update
UPDATE uc_products SET model = '1133', list_price = 0, cost = 0, sell_price = 0, weight = 0, weight_units = 'kg', length = 0, width = 0, height = 0, length_units = 'cm', pkg_qty = 1, default_qty = 1, ordering = 0, shippable = 1 WHERE vid = 17

WITHOUT uc_multprice
Calling function: uc_product_update
UPDATE uc_products SET model = '1133', list_price = 10, cost = 0, sell_price = 10, weight = 0, weight_units = 'kg', length = 0, width = 0, height = 0, length_units = 'cm', pkg_qty = 1, default_qty = 1, ordering = 0, shippable = 1 WHERE vid = 17

Note the different 'sell_price' and 'list_price' in each querystring.

Additionally with uc_multiprice installed the 'DELETE SQL query string in the uc_multiprice module is called with the other (translated) node as the node ID.

Is there anybody out there? Any suggested steps? Should I be pushing this to the Ubercart guys?

Thanks

Adam

Docc’s picture

To be honest. Didnt test the module on a multilanguage install.

The module takes the values of the default country and saves them as default product price/cost/list
Try to uncomment lines 227, 228 and 229 and let me know

          $node->sell_price = check_plain($node->multiprice['countries'][0]['sell_price']);
          $node->list_price = check_plain($node->multiprice['countries'][0]['list_price']);
          $node->cost       = check_plain($node->multiprice['countries'][0]['cost']);
anea02’s picture

Thanks Docc

I tried your suggestion above - the result is the the 'default' price for the product is deleted (set to 0) when the product page is saved. (multiprice) GUI for translated page was adversely affected too.

I will keep reading through code. Any other suggestions Docc are extremely welcome

Thanks

Adam

anea02’s picture

If I switch off 'translation synchronisation' module the translation pricing is unaffected. So that's good news for uc_multiprice but bad news for site functionality. So when translation module loads 'linked' node and saves its changes your code is getting run but your code does not understand the fact that it is a linked node you are working on and therefore (I suspect) certain price info is not available to your code and hence it is resetting the prices. (I think). Hope that makes sense.

I'll keep digging. If you have any more suggestions ...

Jose Reyero’s picture

Category: bug » support
Priority: Major » Normal

You'll need to read the code and comments in i18nsync module and make sure these fields are actually in the 'synchronizable list'

There's one condition synchronization needs to work. That this doesn't really affect the node:

node_save(node_load(xxx));

If that doesn't work, I'm afraid you will need to code your own synchronization.

Bartezz’s picture

Hi all,

I am experiencing exactly the same problems. Working on a multilingual multi-price project too.
Using D6.19, i18n 6.x-1.7, ubercart 6.x-2.4 and uc_multiprice 6.x-1.0 (latest dev).

Hopefully this will get some attention asap as I think uc_multiprice is a brilliant module yet
desperately needs some TLC!

Cheers

Docc’s picture

Title: Enabling Multiprice causes prices to be deleted off product translations » Multilanguage support

What jose says.

Ubercart out of the box is terrible with multilanguage. There are many sources to find on this subject.

For example: http://www.firewing1.com/taxonomy/term/67 (thanks for the link Bartezz, was suprised to find my name and code snippet on that page. Didnt see it yet)

Now try to use the i18nsync module to add support for the product node type and multiprice. Let me know how this works out for ya.

Bartezz’s picture

Hi guys,

Yeah it is terrible! Well Drupal itself is not very well with multilanguage either... lots of duplicates in the db....
Anyway I started an issue on this here http://drupal.org/node/943630 which is now marked as a duplicate of this issue.

I have tried the code by firewing1 but couldn't manage synchronizing multiprice fields with it, if someone else is succesfull at this I'd love to hear it.

Was reading up on how i18n_synch works last thursday at work as to why this possibly might not work, can't find the link now :( If I remember correctly it had to do with node_load/update callbacks... will have to see if I can find the issue tomorrow.

Cheers

Bartezz’s picture

Hi,

I've tried and tried but can't find a way to synchronize prices across translations (with firewing1's code), I reckon this is because the multiprice variable is an array instead of an integer or string. I don't think i18nsync works with arrays as there are problems with synchronizing attributes as well.

Will try and find a solution, any tips/hints are welcome!

Cheers

PS. Docc when do you think you will be able to release a stable 2.0? And is there anything i can do to help other then sorting out this sync prob?!

Docc’s picture

This issue and #539358: javascript error are blockers.

Im hoping to have some time to look into this issue this week. Multilanguage is important to me aswell. We probaply need a custom solution if i18nsync doesn't work with arrays.
So any suggestions about this issue are welcome.

Bartezz’s picture

Hi Docc,

Well I'm kinda shocked... was so easy that I can't believe it works.... but it does so far!

I'm using the module/code by firewing1

function custommodule_i18nsync_fields_alter($fields, $type) {
  // by firewing1 http://www.firewing1.com/node/27
  $fields['uc_products']['#title'] = 'Products';
  // These values were found by doing a print_r($node) in node-product.tpl.php
  $fields['uc_products']['#options'] = array (
    'model' => 'SKU',
    'list_price' => 'List Price',
    'cost' => 'Cost',
    'sell_price' => 'Sell Price',
    'weight' => 'Weight',
    'weight_units' => 'Weight Units',
    'length' => 'Length',
    'width' => 'Width',
    'height' => 'Height',
    'length_units' => 'Length Units',
    'pkg_qty' => 'Quantity',
    'default_qty' => 'Default quantity to add to cart',
    // add this line for multiprice sync!
    'multiprice' => 'Allows price overide on a country level'
  );
}

Then I changed a single line in the uc_multiprice module, see patch.

Looks like it's working so far :)

Please test this folks and post back if it needs more work!

Cheers

Bartezz’s picture

More feedback... when saving the translated node (node-2) the default price of node-1 is erased... will look into this!

Hope you appreciate my infringing, need this module soon :)

Cheers

Bartezz’s picture

Docc,

I've made some progress... please see my new patch rerolled against 6.x-2.x-dev 2010-Oct-17.

These issues have been fixed;

- Multiprice doesn't sync upon translation creation (using firewing1's module above to sync ubercart product data)
Fixed on line #210
- Multiprice values aren't renedered correctly (eg. 11.000 instead of 11.00)
Fixed on line #226 thru #228
- Multiprice replace product price with multiprice if it's not node form
Line #234 Added possible arguments for node clone and node convert
- Multiprice translations delete default price of orginal node
Fixed on line #246 thru #251
- Multiprice values remain stored in DB upon node deletion
Fixed on line #268 thro #270

I have tested the changes and everything seems to work perfect now. Can you confirm and commit?

Cheers

Bartezz’s picture

Docc,

Sorry, I found out that without syncing the multiprice values of the original node were deleted upon save of translation. Didn't notice this earlier, maybe my form got cached by firefox when F5-ing... Made some changes around line #256 which solve the problem. (moved the db call to delete and the call to unset after the if statement)

Please see my new patch rerolled against 6.x-2.x-dev 2010-Oct-17

Cheers

Docc’s picture

Hey barthezz,

Thank you for your trouble.
Ill have a look when i found the time. Probably wont be sooner then the end of the week.

Bartezz’s picture

Drop the h... I'm not the crappy DJ :p hehehe

No worries... that's what open source is about... glad I had something to work with instead of developing it all myself.

I'm also planning on extending the module and adding 2 features. Am not sure if I can/should do this in a helper module or in the module itself.

The first feature I'm planning of developing are an price import feature via a csv file. Most administrative software I've seen allows exporting prices into a csv. If one could export a 4 column csv sku|list_price|cost|see_price and then import it on a per country level it would save editing a gazillion nodes upon price changes. The easiest way to achieve this is to add a column in the multiprice table where I store the SKU of the nodes. I know this causes duplicate data, storing SKU in the db twice, yet it will ask less from a database updating 1000s of table rows without having to join queries.

Do you think this is a feature that could improve your module?

Another feature I'll be needing for my next project is price per role. I've looked into http://drupal.org/project/uc_price_per_role but I'm not sure this will be working in conjunction with you rmodule. Besides the import function I'll be developing will only work for your module and I'd have to develop another import function for uc_price_per_role.

What do you think!?

Cheers

Docc’s picture

Ah yes now i know why your username sounds so familiar :)
And to think ive seen and listen to him live on stage...argg..

First off, after stable release i have no intention of adding features. Ill only maintain it on a bug/security level.
Though patches are always welcome and i will commit them. And if you want to create your own addon module instead be my guest.

Now for your ideas. Dont know if importing data should be in the module itself.
Im thinking using a module meant for import is better to use for it.
For example node import. Just write a plugin for that?

Price for role, didn't look at the code but little change it works together. Though if needed a patch can be committed to this module or the other to make sure they work together.

regards

Bartezz’s picture

Hi Docc,

Thanx for the prompt response.

I thought of using existing modules to import data yet these are all for node creation. All I want to do is to update the prices uc_multiprice table. Therefor I think it should be a uc_multiprice module feature.

I thought there would be little chance of price per role and uc_multiprice working together. And like I said, if I manage to add this feature to your module then these prices could be updated via the import feature as well.

Thanx for being open minded, will see what I can accomplish!

Will you still check out the v2 patch later this week?

Cheers

Docc’s picture

Thats not correct.Though the name suggest otherwise, you can import anything with node import.
By default you can import users aswell, and i made a few plugins myself wich arent node related like role expirations.

Docc’s picture

Status: Active » Closed (fixed)

Commited to DEV. Tnx Bartezz

amirtaiar’s picture

I have tried to follow the patch but unfortunetly I have no expirience doing that well and I didn't suceed.
Can you please upload the file ufter all the changings?

And another question just to know if I am in the good place for my issue.
What I want is a price for eache language node:
- product 1 - english - cost:3$
- product 1 - Hebrew - cost:1ils.

Does'nt metter from which country I am viewing the site.

Bartezz’s picture

Hi Amirtaiar,

The patch has been comitted to .dev so if you download that you have the version with all the changes from the patch.

But I don't think this module helps in achieving your goals. You are looking for prices based on language and not based on country, which is what this module does. I doubt you will find a module that does just that cause it is not a common thing to have prices based on language spoken. Prices can change between countries because of import/export duties, currencies, etc etc. Changing prices based on language spoken sounds rather discriminating imho. I guess you will have to code your own module for that.

Cheers

amirtaiar’s picture

Hi Bartezz,
Thank you for the reply.

What I want to understand is that - When a visitor in england will view my store he will see the price in Pound? Is this happen auto by me just adding England and when editing the Englinsh product node I will enable this option? Couse if so, thats grate then! I can Add only english adn then what will happen?
I am sorry but it's really hard to understand this, for me anyway...

As for what I want - I don't want to change the price based on language. I will do it manually! Meaning, when editing the English node I will say it's a 10$, and when adding the Hebrew node I will say it's a 3ils.

Bartezz’s picture

Amirtaiar,

UC_multiprice will let you set prices by country. No matter if you are using multiple languages. I would suggest to use a module called i18n_sync to synchronize certain values between translations. For product nodes I would suggest doing this for SKU/model, weight etc. but also price. This way a product shown in Hebrew or shown in English will always have the same SKU/model, weight and price. So one single product node can have multiple prices attached to it!!!! Looky here; http://drupal.org/node/995488
To synchronize ubercart values have a look at this; http://www.firewing1.com/taxonomy/term/67

Now uc_multiprice will provide users with a block with dropdown form in which one can select which country he or she is from. Based on this the prices will change. This way a Hebrew speaking person living in the USA will see a product description in Hebrew with a price of $10 and a Hebrew speaking person living in Isreal will see a product description in Hebrew with a price of 3ils. And an English speaking person living in USA will see a product description in English with a price of $10 and an English speaking person living in Israel will see a product description in English with a price of 3ils. Catch my drift?

Currency is country dependent, not language dependent. Don't make any mistakes about this or you'll be looking for functionality which simply isn't there nor logic for that matter :)

Cheers

amirtaiar’s picture

I have been practising this module and it seems feet.
Though, what I didn't understand is the behevior of it.
I have been doing along this - http://www.firewing1.com/taxonomy/term/67.
So now when I create English product the price is in $.
When I translate the price is still in $, and it seems like it's not respond when I delete the defualt curency option witch is English.

By the way - How do I set the defualt curency?

Thank for your kind.

Bartezz’s picture

amirtaiar,

A product always has to have a default price, in a default currency. The default currency is based on your store information set in ubercart. The module provided by firewing1 allows you to synchronise data between node translations. So if you delete a price in the english node for product X it will also delete that same price in the hebrew node for product X. By synchronizing data you save yourself the hassle of having to update every translation for a product node when changing the price in the translation source node. All prices set for a product node will be available for each language when synchronizing. As I said language has nothing to do with uc_multiprice....

Cheers

amirtaiar’s picture

Thank you, got the idea and it's all working well.
I think it can be a good idea to have a drop and drop option for the main curency in the curent language edit page.
For example - When I edit the en product, I will put the $ at the front, and when I edit the He product I will put the ils in the front.

Bartezz’s picture

Amirtaiar,

Are you putting $ and ils into the price fields?? You shouldn't do this (didn't think this was possible) as it will mess things up. Or are you doing it by theming?

You can set the currency to use for Israel to isl and to use $ for USA here; admin/store/settings/countries/edit/formats
This will automatically add the $ to a price for USA customers for instance.

Also have a look at the help on this settings page admin/store/settings/multiprice/currencies

Cheers

janton’s picture

Yes looking for simular thing.. but Amirtaiar would it not be better to have a Language selector AND a currency selector.. (and currency changes to default of that language, but still possible to change of course)

Just like http://www.namecheap.com/ for example.. I can switch from dollar to euro! only they don't provide the option to change language.. (perhaps i also don't need language switch..) changing to other currency is what is missing..
I personally don't understand why multiprice works on Country, perhaps because of the shipping..? but the whole point is the currency.. (in my opinion, or am i wrong Bartezz?) i know there is this module multicurrency, but this does not give the opportunity to add different prices for other currency's. (why, i don't like strainge 12.14 prices, i would like them 11.99 for example)

I'm not a great developer, but i will ask a php programmer friend if he can help me... problem is i got a deadline :( aaaaa

Bartezz’s picture

I personally don't understand why multiprice works on Country

Janton, I see you are from the Netherlands. So let me ask you this; there are HEMA stores in the Netherlands and Belgium, prices of exactly the same products are different between the two countries, you even used to see the Belgian price on the products sold in the Netherlands before the Euro era. But have you ever walked into a shop on holiday in Italy and were charged differently for the same product than the Italian speaking guy in front of you because you ordered in German?

Hope this makes you understand :) In business language is not a factor in determining price, location is as explained before. That's why this module works the way it does...

That said, uc_multiprice has a hook uc_multiprice_country_id(). If you know your way around php you could call this hook when a user changes language thereby changing the price (and currency if set) upon language change. It'll make your website unlogic and will make customers run away but that's your call.

One more question, if a user changes to French will you show the price and currency for France in Euro's, French Canada in CND, Cameroon in XAF, Switserland in CHF, etc etc... just wondering ;)

Cheers

Bartezz’s picture

Just came to mind;

If you forget about language determining price and currency and just want a currency dropdown then you could use multiprice module to be able to administer different prices. Just set currencies for countries, then add prices per country for a product. Hide the region selector block. Create your own dropdown block with currencies as options and country ids as values and call uc_multiprice_country_id() with the selected value when a user selects a currency. For a user it will seem that he/she selected a currency in stead of a country.

Now in checkout form you will have to unbind the jquery script that reloads the page when a user changes the delivery country, this jquery is added by multiprice module but will prevent the functionality you wish to implement.

There might be other obstacles but this is the route I'd take...

Cheers

janton’s picture

Bartezz, thx for the last comment! That is exactly what i was looking for!
In your first reply i think you understood me wrong... i tried to say i just want to have a currency dropdown, and perhaps also a language selector but both are independent from each other. Only what i ment was if somebody selects Language Netherlands the default currency would be EURO, but users could change this if they like to.. with Language English this is already a problem.. dollar and Pound.. so perhaps i will try to make ip2cc module make the default selection, problem is i thought of using the boost module for my site.. but i guess that will not work with ip2cc module. (i try to figure something out)

Nice metaphor about the HEMA ;)
I will ask my friend to join me this weekend to try what you suggested!

janton’s picture

Bartezz perhaps you can help me out.. i just created this code.. it almost works but when i select the currency it does not change.. it reloads the page.. i think i have something small wrong:

function uc_multiprice_currency_form($form_state, $show_label = FALSE) {
  $result = db_query("SELECT * FROM {uc_multiprice_currencies} ORDER BY currency_code ASC");
  while ($currency = db_fetch_object($result)) {
    $currencies[$currency->country_id] = $currency->currency_code;
  }

  $form['country_id'] = array(
    '#type' => 'select',
    '#title' => ($show_label ? t('Choose currency') : ''),
    '#default_value' => uc_multiprice_country_id(),
    '#options' => $currencies,
    '#attributes' => array('onchange' => 'javascript:this.form.submit();'),
  );
  
  // hide the submit button
  $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#attributes' => array('style' => 'display:none;'));
  return $form;  
}
 
  
/**
 * Implementation of hook_block().
 */
function uc_multiprice_select_currency_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks = array();
      $blocks[0] = array(
        'info' => t('Currency Selector'),
        'cache' => BLOCK_NO_CACHE,
      );
      return $blocks;
    case 'configure':
      break;
    case 'save':
      break;
    case 'view':
      if ($delta == 0) {
        $block = array(
          'subject' => t('Currency'),
          'content' => drupal_get_form('uc_multiprice_currency_form'),
        );
        return $block;
      }
      break;
  }
}
janton’s picture

aha i think i undestand.. i'm sending the value GBP USD or EUR.. mmh now i need to think about a solution

janton’s picture

yes i forgot this :

function uc_multiprice_currency_form_submit($form, &$form_state) {
  uc_multiprice_country_id($form_state['values']['country_id']);
}
Bartezz’s picture

Nice, almost there!

Don't forget to unbind the jquery script from the delivery country dropdown in the checkout form....

Cheers

janton’s picture

i now just disabled the dropdown in cart? /admin/store/settings/cart/edit/panes
so i disabled: Multiprice - country switcher i guess this is not enough?

i sell virtual products.. so i totally disabled the Delivery information in /admin/store/settings/checkout/edit/panes

FooZee’s picture

Hi there,
I had a client who needed the following configuration, (which makes changing price based on language look a bit reasonable, and he just insist on that, though I explained what Bartezz have said, to him :D).

However, I'm writing my solution here just in case anyone else stuck with a determined client like mine :D

The configuration is like follows:
Store has 2 langs, English (which sells in Euro) and Danish (which sells in Danish Kroner dkk) so regardless of his country a customer viewing the site in english would see prices in Euro, and vice versa.

please, if someone sees any place for optimization in this approach. please let me know as I'm not very experienced with Ubercart or drupal module development :)

1- Set the default currency at /admin/store/settings/store/edit/format to the one used for all other countries (Euro in my case)
2- go to admin/store/settings/countries and add all needed countries, and don't forget to set the exception countries (ones with different languages and different currencies )
3- Sure, you should have added languages earlier at some stage :)
4- you need to add this simple snippet to your custom module (it only checks for language and then sets the country currency accordingly) --please if anyone has any ideas on enhancing this code, please let me know coz I need to know it :)


function module_init()
{
global $language;
// check can be extended with switch or something :D this is just enough for my case :)
if ($language->language == 'da')

/*  now you need to know is the $country_id corresponding to your country, 208 in my case ...  a simple lookup at the table called uc_multiprice_currencies would just do it :D */

uc_multiprice_country_id(208);
}

5- if you want, you may want to leave the the block of choosing region which will allow ppl to override your previous choice!