Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoided unnecessary calls to string translation methods for catalog/sales rules labels #3140

Merged
merged 2 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function loadAttributeOptions()
public function loadOperatorOptions()
{
$this->setOperatorOption([
'to_fixed' => Mage::helper('cataloginventory')->__('To Fixed Value'),
'to_percent' => Mage::helper('cataloginventory')->__('To Percentage'),
'by_fixed' => Mage::helper('cataloginventory')->__('By Fixed value'),
'by_percent' => Mage::helper('cataloginventory')->__('By Percentage'),
'to_fixed' => static::$translate ? Mage::helper('cataloginventory')->__('To Fixed Value') : 'To Fixed Value',
'to_percent' => static::$translate ? Mage::helper('cataloginventory')->__('To Percentage') : 'To Percentage',
'by_fixed' => static::$translate ? Mage::helper('cataloginventory')->__('By Fixed value') : 'By Fixed value',
'by_percent' => static::$translate ? Mage::helper('cataloginventory')->__('By Percentage') : 'By Percentage',
]);
return $this;
}
Expand Down
16 changes: 14 additions & 2 deletions app/code/core/Mage/Rule/Model/Action/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@
*/
abstract class Mage_Rule_Model_Action_Abstract extends Varien_Object implements Mage_Rule_Model_Action_Interface
{
/**
* Flag to enable translation for loadOperatorOptions/loadValueOptions/loadAggregatorOptions/getDefaultOperatorOptions
* It's useless to translate these data on frontend
*
* @var bool
*/
protected static $translate;

public function __construct()
{
if (!is_bool(static::$translate)) {
static::$translate = Mage::app()->getStore()->isAdmin();
}

parent::__construct();
$this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();

Expand Down Expand Up @@ -137,8 +149,8 @@ public function getAttributeName()
public function loadOperatorOptions()
{
$this->setOperatorOption([
'=' => Mage::helper('rule')->__('to'),
'+=' => Mage::helper('rule')->__('by'),
'=' => static::$translate ? Mage::helper('rule')->__('to') : 'to',
'+=' => static::$translate ? Mage::helper('rule')->__('by') : 'by',
]);
return $this;
}
Expand Down
36 changes: 24 additions & 12 deletions app/code/core/Mage/Rule/Model/Condition/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
*/
abstract class Mage_Rule_Model_Condition_Abstract extends Varien_Object implements Mage_Rule_Model_Condition_Interface
{
/**
* Flag to enable translation for loadOperatorOptions/loadValueOptions/loadAggregatorOptions/getDefaultOperatorOptions
* It's useless to translate these data on frontend
*
* @var bool
*/
protected static $translate;

/**
* Defines which operators will be available for this condition
*
Expand Down Expand Up @@ -76,6 +84,10 @@ abstract class Mage_Rule_Model_Condition_Abstract extends Varien_Object implemen

public function __construct()
{
if (!is_bool(static::$translate)) {
static::$translate = Mage::app()->getStore()->isAdmin();
}

parent::__construct();

$this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
Expand Down Expand Up @@ -137,18 +149,18 @@ public function getDefaultOperatorOptions()
{
if ($this->_defaultOperatorOptions === null) {
$this->_defaultOperatorOptions = [
'==' => Mage::helper('rule')->__('is'),
'!=' => Mage::helper('rule')->__('is not'),
'>=' => Mage::helper('rule')->__('equals or greater than'),
'<=' => Mage::helper('rule')->__('equals or less than'),
'>' => Mage::helper('rule')->__('greater than'),
'<' => Mage::helper('rule')->__('less than'),
'{}' => Mage::helper('rule')->__('contains'),
'!{}' => Mage::helper('rule')->__('does not contain'),
'[]' => Mage::helper('rule')->__('contains'),
'![]' => Mage::helper('rule')->__('does not contain'),
'()' => Mage::helper('rule')->__('is one of'),
'!()' => Mage::helper('rule')->__('is not one of')
'==' => static::$translate ? Mage::helper('rule')->__('is') : 'is',
'!=' => static::$translate ? Mage::helper('rule')->__('is not') : 'is not',
'>=' => static::$translate ? Mage::helper('rule')->__('equals or greater than') : 'equals or greater than',
'<=' => static::$translate ? Mage::helper('rule')->__('equals or less than') : 'equals or less than',
'>' => static::$translate ? Mage::helper('rule')->__('greater than') : 'greater than',
'<' => static::$translate ? Mage::helper('rule')->__('less than') : 'less than',
'{}' => static::$translate ? Mage::helper('rule')->__('contains') : 'contains',
'!{}' => static::$translate ? Mage::helper('rule')->__('does not contain') : 'does not contain',
'[]' => static::$translate ? Mage::helper('rule')->__('contains') : 'contains',
'![]' => static::$translate ? Mage::helper('rule')->__('does not contain') : 'does not contain',
'()' => static::$translate ? Mage::helper('rule')->__('is one of') : 'is one of',
'!()' => static::$translate ? Mage::helper('rule')->__('is not one of') : 'is not one of',
];
}
return $this->_defaultOperatorOptions;
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Rule/Model/Condition/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public function __construct()
public function loadAggregatorOptions()
{
$this->setAggregatorOption([
'all' => Mage::helper('rule')->__('ALL'),
'any' => Mage::helper('rule')->__('ANY'),
'all' => static::$translate ? Mage::helper('rule')->__('ALL') : 'ALL',
'any' => static::$translate ? Mage::helper('rule')->__('ANY') : 'ANY',
]);
return $this;
}
Expand Down Expand Up @@ -161,8 +161,8 @@ public function getAggregatorElement()
public function loadValueOptions()
{
$this->setValueOption([
1 => Mage::helper('rule')->__('TRUE'),
0 => Mage::helper('rule')->__('FALSE'),
1 => static::$translate ? Mage::helper('rule')->__('TRUE') : 'TRUE',
0 => static::$translate ? Mage::helper('rule')->__('FALSE') : 'FALSE',
]);
return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public function loadAttributeOptions()
public function loadOperatorOptions()
{
$this->setOperatorOption([
'to_fixed' => Mage::helper('salesrule')->__('To Fixed Value'),
'to_percent' => Mage::helper('salesrule')->__('To Percentage'),
'by_fixed' => Mage::helper('salesrule')->__('By Fixed value'),
'by_percent' => Mage::helper('salesrule')->__('By Percentage'),
'to_fixed' => static::$translate ? Mage::helper('salesrule')->__('To Fixed Value') : 'To Fixed Value',
'to_percent' => static::$translate ? Mage::helper('salesrule')->__('To Percentage') : 'To Percentage',
'by_fixed' => static::$translate ? Mage::helper('salesrule')->__('By Fixed value') : 'By Fixed value',
'by_percent' => static::$translate ? Mage::helper('salesrule')->__('By Percentage') : 'By Percentage',
]);
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct()
public function loadValueOptions()
{
$this->setValueOption([
1 => Mage::helper('salesrule')->__('FOUND'),
0 => Mage::helper('salesrule')->__('NOT FOUND')
1 => static::$translate ? Mage::helper('salesrule')->__('FOUND') : 'FOUND',
0 => static::$translate ? Mage::helper('salesrule')->__('NOT FOUND') : 'NOT FOUND',
]);
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public function loadValueOptions()
public function loadOperatorOptions()
{
$this->setOperatorOption([
'==' => Mage::helper('rule')->__('is'),
'!=' => Mage::helper('rule')->__('is not'),
'>=' => Mage::helper('rule')->__('equals or greater than'),
'<=' => Mage::helper('rule')->__('equals or less than'),
'>' => Mage::helper('rule')->__('greater than'),
'<' => Mage::helper('rule')->__('less than'),
'()' => Mage::helper('rule')->__('is one of'),
'!()' => Mage::helper('rule')->__('is not one of'),
'==' => static::$translate ? Mage::helper('rule')->__('is') : 'is',
'!=' => static::$translate ? Mage::helper('rule')->__('is not') : 'is not',
'>=' => static::$translate ? Mage::helper('rule')->__('equals or greater than') : 'equals or greater than',
'<=' => static::$translate ? Mage::helper('rule')->__('equals or less than') : 'equals or less than',
'>' => static::$translate ? Mage::helper('rule')->__('greater than') : 'greater than',
'<' => static::$translate ? Mage::helper('rule')->__('less than') : 'less than',
'()' => static::$translate ? Mage::helper('rule')->__('is one of') : 'is one of',
'!()' => static::$translate ? Mage::helper('rule')->__('is not one of') : 'is not one of',
]);
return $this;
}
Expand Down