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

fix 38000: duplicate call getAttributeOptions #38001

Draft
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
<?php
/**
* Configurable product type resource model
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Type;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Catalog\Model\ResourceModel\Product\Relation as ProductRelation;
use Magento\Framework\Model\ResourceModel\Db\Context as DbContext;
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Catalog\Model\ResourceModel\Product\Relation as ProductRelation;
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
use Magento\ConfigurableProduct\Model\AttributeOptionProviderInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionProvider;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Framework\Model\ResourceModel\Db\Context as DbContext;

/**
* Configurable product resource model.
*/
class Configurable extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
* Catalog product relation
* Catalog product relation class
*
* @var ProductRelation
*/
Expand All @@ -46,6 +43,13 @@ class Configurable extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
private $optionProvider;

/**
* List of attribute options data
*
* @var array
*/
protected $attributeOptions = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be marked as private instead of protected right?
If classes extend from this one (which is against Magento's policy) they'll need to call the public function to get the value, not use this property.
There is no good reason (unless I'm missing something) to expose this property to classes that extend from this one, right?


/**
* @param DbContext $context
* @param ProductRelation $catalogProductRelation
Expand Down Expand Up @@ -236,6 +240,13 @@ public function getConfigurableOptions($product, $attributes)
*/
public function getAttributeOptions(AbstractAttribute $superAttribute, $productId)
{
return $this->attributeOptionProvider->getAttributeOptions($superAttribute, $productId);
$key = $superAttribute->getAttributeId() . '-' . $productId;
if (!array_key_exists($key, $this->attributeOptions)) {
$this->attributeOptions[$key] = $this->attributeOptionProvider->getAttributeOptions(
$superAttribute,
$productId
);
}
return $this->attributeOptions[$key];
}
}