Child pages
  • [In-Commerce] Wrong discounted item name is displayed for discount/coupon items [5.2.1]
Skip to end of metadata
Go to start of metadata

When creating/editing discount/coupon it's possible to select specific categories/products which will be affected by that discount/coupon.

Unfortunately there are 2 issues with that:

  1. selected product name is displayed always from 1st created language (if we make 2nd language primary and don't enter product name on 1st language, then we'll see empty product name)
  2. category name is always empty

Problem comes from ItemName calculated field definition in both cases:

'ItemName' => 'IF(p.Name IS NULL,c.Name,p.l1_Name)',

Solution

  1. make ItemName translatable
  2. prefix usage of Name fields with l%2$s_

In previous In-Portal versions such implementation (making virtual field multi-lingual) might create some issues, but all should be find in 5.2.x versions.

Related Tasks

1 Comment

  1. I've found following code in "di:OnAfterConfigRead" that did that in non-obvious way:

    discount_items_event_handler.php
    $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields');
    
    $language_id = $this->Application->GetVar('m_lang');
    $primary_language_id = $this->Application->GetDefaultLanguageId();
    
    $calculated_fields['']['ItemName'] = 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)';
    $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields);

    Here is why current implementation is bad:

    • the kMultiLanguage formatter is not used, so this is code duplication
    • the c.Name part is completely removed from SQL and therefore we're always showing product name instead of selected category name