-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-5683: #16832 - Reworked query in getAttributeRawValue so that …
…it returns a store specific value even if there is no default value #23369 - Merge Pull Request #23369 from semajeg/magento2:16382-getAttributeRawValue-no-default - Merged commits: 1. 01f1f15 2. 64184b3 3. 35c5185 4. 9ae33c8 5. 8c4bfa6 6. 7b0e528 7. c34f83c 8. 4d380bf 9. 540f03e
- Loading branch information
Showing
4 changed files
with
233 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...ion/testsuite/Magento/Catalog/_files/product_simple_with_custom_store_scope_attribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\ProductFactory; | ||
use Magento\Catalog\Api\Data\ProductAttributeInterface; | ||
use Magento\Catalog\Api\ProductAttributeRepositoryInterface; | ||
use Magento\Catalog\Setup\CategorySetup; | ||
use Magento\Eav\Model\Entity; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Type; | ||
|
||
/** @var \Magento\TestFramework\ObjectManager $objectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->get(ProductRepositoryInterface::class); | ||
/** @var ProductFactory $productFactory */ | ||
$productFactory = $objectManager->get(ProductFactory::class); | ||
/** @var ProductAttributeRepositoryInterface $attributeRepository */ | ||
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class); | ||
|
||
|
||
/** @var $installer CategorySetup */ | ||
$installer = $objectManager->create(CategorySetup::class); | ||
$entityModel = $objectManager->create(Entity::class); | ||
$attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default'); | ||
$entityTypeId = $entityModel->setType(Product::ENTITY) | ||
->getTypeId(); | ||
$groupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); | ||
|
||
/** @var ProductAttributeInterface $attribute */ | ||
$attribute = $objectManager->create(ProductAttributeInterface::class); | ||
|
||
$attribute->setAttributeCode('store_scoped_attribute_code') | ||
->setEntityTypeId($entityTypeId) | ||
->setIsVisible(true) | ||
->setFrontendInput('text') | ||
->setIsFilterable(1) | ||
->setIsUserDefined(1) | ||
->setUsedInProductListing(1) | ||
->setBackendType('varchar') | ||
->setIsUsedInGrid(1) | ||
->setIsVisibleInGrid(1) | ||
->setIsFilterableInGrid(1) | ||
->setFrontendLabel('nobody cares') | ||
->setAttributeGroupId($groupId) | ||
->setAttributeSetId(4); | ||
|
||
$attributeRepository->save($attribute); | ||
|
||
$product = $productFactory->create() | ||
->setTypeId(Type::TYPE_SIMPLE) | ||
->setAttributeSetId(4) | ||
->setName('Simple With Store Scoped Custom Attribute') | ||
->setSku('simple_with_store_scoped_custom_attribute') | ||
->setPrice(100) | ||
->setVisibility(1) | ||
->setStockData( | ||
[ | ||
'use_config_manage_stock' => 1, | ||
'qty' => 100, | ||
'is_in_stock' => 1, | ||
] | ||
) | ||
->setStatus(1); | ||
$product->setCustomAttribute('store_scoped_attribute_code', 'default_value'); | ||
$productRepository->save($product); |
41 changes: 41 additions & 0 deletions
41
...uite/Magento/Catalog/_files/product_simple_with_custom_store_scope_attribute_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\Registry; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Catalog\Api\ProductAttributeRepositoryInterface; | ||
|
||
/** @var Magento\Framework\ObjectManagerInterface $objectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->get(ProductRepositoryInterface::class); | ||
/** @var ProductAttributeRepositoryInterface $attributeRepository */ | ||
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class); | ||
/** @var Registry $registry */ | ||
$registry = $objectManager->get(Registry::class); | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
|
||
try { | ||
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */ | ||
$product = $productRepository->get('simple_with_store_scoped_custom_attribute'); | ||
$productRepository->delete($product); | ||
} catch (NoSuchEntityException $e) { | ||
} | ||
|
||
try { | ||
/** @var \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute */ | ||
$attribute = $attributeRepository->get('store_scoped_attribute_code'); | ||
$attributeRepository->delete($attribute); | ||
} catch (NoSuchEntityException $e) { | ||
} | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |