Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed May 16, 2024
1 parent be57ecc commit 59a84f3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Catalog/Test/product/attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class attribute extends \Df\Core\TestCase {
function t00():void {}

/** 2020-01-31 @test */
function df_product_att_val_s():void {
function df_product_att_val():void {
$p = df_product(45); /** @var P $p */
echo df_product_att_val_s($p, 'description');
echo df_product_att_val_s($p, 'color');
echo df_product_att_val($p, 'description');
echo df_product_att_val($p, 'color');
}
}
15 changes: 3 additions & 12 deletions Catalog/lib/product/attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function df_product_atts_r():R {return df_o(R::class);}
/**
* 2019-08-21
* @used-by df_product_att_options()
* @used-by df_product_att_val_s()
* @used-by df_product_att_val()
* @param F|bool|mixed $onE [optional]
* @return A|null
* @throws NSE
Expand Down Expand Up @@ -55,17 +55,8 @@ function df_product_sku2id(string $sku):int {return (int)df_product_res()->getId
* 2020-01-31
* @see \Magento\Catalog\Model\Product::getAttributeText()
* @uses \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::getOptionText()
* @used-by \Df\Catalog\Test\product\attribute::df_product_att_val_s()
* @used-by \Df\Catalog\Test\product\attribute::df_product_att_val()
* @used-by \Dfe\Sift\Payload\OQI::p()
* @throws NSE
*/
function df_product_att_val_s(P $p, string $c, string $d = ''):string {return df_try(function() use($p, $c):string {
/** @var string|false|string[] $r */ /** @var string|int $v */
$r = df_product_att($c)->getSource()->getOptionText($v = $p[$c]);
/**
* 2020-01-31
* @see \Magento\Eav\Model\Entity\Attribute\Source\Table::getOptionText() can return an empty array
* for an attribute's value (e.g., for the `description` attribute), if the value contains a comma.
*/
return strval(false === $r || is_array($r) ? $v : $r);
}, $onE);}
function df_product_att_val(P $p, string $c, string $d = ''):string {return df_att_val($p, df_product_att($c), $d);}
1 change: 1 addition & 0 deletions Eav/lib/attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function df_att_code2id(string $c):int {return df_first(df_fetch_col_int(
/**
* 2024-05-16 "Implement `df_att_val_s()`": https://github.com/mage2pro/core/issues/373
* @uses \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::getOptionText()
* @used-by df_product_att_val()
*/
function df_att_val(M $m, A $a, string $d = ''):string {return df_fnes($r = $m[$a->getAttributeCode()]) ? $d : (
!$a->usesSource() ? $r : (
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/core"
,"version": "10.9.5"
,"version": "10.9.6"
,"description": "Mage2.PRO core package."
,"type": "magento2-module"
,"homepage": "https://mage2.pro"
Expand Down

0 comments on commit 59a84f3

Please sign in to comment.