Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/mage-os/mirror-magento2
Browse files Browse the repository at this point in the history
 into 2.4-develop
  • Loading branch information
mage-os-ci committed Jun 1, 2024
2 parents f9e1b46 + 3056e9c commit 2d831e4
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks;
use Magento\Catalog\Model\Product\Link\Resolver as LinkResolver;
use Magento\Catalog\Model\Product\LinkTypeProvider;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -278,6 +280,7 @@ public function initialize(Product $product)
* @param Product $product
* @return Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @throws NoSuchEntityException
* @since 101.0.0
*/
protected function setProductLinks(Product $product)
Expand All @@ -301,20 +304,18 @@ protected function setProductLinks(Product $product)
}

foreach ($linkTypes as $linkType => $readonly) {
if (isset($links[$linkType]) && !$readonly) {
foreach ((array) $links[$linkType] as $linkData) {
if (empty($linkData['id'])) {
continue;
}

$linkProduct = $this->productRepository->getById($linkData['id']);
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())
->setLinkedProductSku($linkProduct->getSku())
->setLinkType($linkType)
->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0);
$productLinks[] = $link;
}
$isReadOnlyLinks = $readonly && in_array($linkType, ['upsell', 'related']);
if ($isReadOnlyLinks) {
$productLinks = null;
break;
} else {
$productLinks = $this->setProductLinksForNotReadOnlyItems(
$productLinks,
$product,
$links,
$linkType,
$readonly
);
}
}

Expand Down Expand Up @@ -401,6 +402,9 @@ private function overwriteValue($optionId, $option, $overwriteOptions)
$option['is_delete_store_title'] = 1;
}
}
if (CustomOptions::FIELD_TITLE_NAME === $fieldName) {
$option[CustomOptions::FIELD_IS_USE_DEFAULT] = $overwrite;
}
}
}

Expand Down Expand Up @@ -523,4 +527,39 @@ private function setCategoryLinks(Product $product): void
$extensionAttributes->setCategoryLinks(!empty($newCategoryLinks) ? $newCategoryLinks : null);
$product->setExtensionAttributes($extensionAttributes);
}

/**
* Set product links when readonly is false
*
* @param array $productLinks
* @param Product $product
* @param array $links
* @param string $linkType
* @param mixed $readonly
* @return array
* @throws NoSuchEntityException
*/
private function setProductLinksForNotReadOnlyItems(
array $productLinks,
Product $product,
array $links,
string $linkType,
mixed $readonly
): array {
if (isset($links[$linkType]) && !$readonly) {
foreach ((array)$links[$linkType] as $linkData) {
if (empty($linkData['id'])) {
continue;
}
$linkProduct = $this->productRepository->getById($linkData['id']);
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())
->setLinkedProductSku($linkProduct->getSku())
->setLinkType($linkType)
->setPosition(isset($linkData['position']) ? (int)$linkData['position'] : 0);
$productLinks[] = $link;
}
}
return $productLinks;
}
}
16 changes: 6 additions & 10 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/**
* Catalog product custom option resource model
*
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
Expand All @@ -25,15 +24,11 @@ class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
protected $metadataPool;

/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;

/**
* Currency factory
*
* @var \Magento\Directory\Model\CurrencyFactory
*/
protected $_currencyFactory;
Expand Down Expand Up @@ -259,12 +254,13 @@ protected function _saveValueTitles(AbstractModel $object)
}
} else {
// we should insert record into not default store only of if it does not exist in default store
if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore) ||
if (((int)$storeId === Store::DEFAULT_STORE_ID && !$existInDefaultStore) ||
(
$storeId != Store::DEFAULT_STORE_ID &&
!$existInCurrentStore &&
!$isDeleteStoreTitle
)
(int)$storeId !== Store::DEFAULT_STORE_ID &&
!$isDeleteStoreTitle &&
($object->getDefaultTitle() !== null && $object->getTitle() !== $object->getDefaultTitle())
) ||
($object->getIsUseDefault() !== null && !(int)$object->getIsUseDefault())
) {
$data = $this->_prepareDataForTable(
new \Magento\Framework\DataObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
class Value extends AbstractDb
{
/**
* Store manager
*
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* Currency factory
*
* @var CurrencyFactory
*/
protected $_currencyFactory;
Expand Down Expand Up @@ -288,8 +284,12 @@ protected function _saveValueTitles(AbstractModel $object)
Store::DEFAULT_STORE_ID
);
// we should insert record into not default store only of if it does not exist in default store
if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore)
|| ($storeId != Store::DEFAULT_STORE_ID && !$existInCurrentStore)
if (((int)$storeId === Store::DEFAULT_STORE_ID && !$existInDefaultStore) ||
(
(int)$storeId !== Store::DEFAULT_STORE_ID &&
($object->getDefaultTitle() !== null && $object->getTitle() !== $object->getDefaultTitle())
) ||
($object->getIsUseDefault() !== null && !(int)$object->getIsUseDefault())
) {
$bind = [
'option_type_id' => (int)$object->getId(),
Expand Down Expand Up @@ -456,6 +456,7 @@ public function duplicate(OptionValue $object, $oldOptionId, $newOptionId)
*
* @return FormatInterface
* @deprecated 101.0.8
* @see Avoid direct use of ObjectManager
*/
private function getLocaleFormatter()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ protected function setUp(): void
->getMock();
$this->productLinksMock = $this->createMock(ProductLinks::class);
$this->linkTypeProviderMock = $this->createMock(LinkTypeProvider::class);
$this->productLinksMock->expects($this->any())
->method('initializeLinks')
->willReturn($this->productMock);

$this->attributeFilterMock = $this->createMock(AttributeFilter::class);
$this->localeFormatMock = $this->createMock(Format::class);

Expand Down Expand Up @@ -221,6 +219,7 @@ protected function setUp(): void
* @param array|null $tierPrice
* @dataProvider initializeDataProvider
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function testInitialize(
$isSingleStore,
Expand All @@ -229,8 +228,17 @@ public function testInitialize(
$links,
$linkTypes,
$expectedLinks,
$tierPrice = null
$tierPrice = null,
$isReadOnlyRelatedItems = null,
$isReadOnlyUpSellItems = null,
$ignoreLinksFlag = false
) {
$this->productMock->setData('related_readonly', $isReadOnlyRelatedItems);
$this->productMock->setData('upsell_readonly', $isReadOnlyUpSellItems);
$this->productLinksMock->expects($this->any())
->method('initializeLinks')
->willReturn($this->productMock);

$this->linkTypeProviderMock->expects($this->once())
->method('getItems')
->willReturn($this->assembleLinkTypes($linkTypes));
Expand Down Expand Up @@ -346,6 +354,11 @@ function () {

$productLinks = $this->productMock->getProductLinks();
$this->assertCount(count($expectedLinks), $productLinks);
if ($ignoreLinksFlag) {
$this->assertTrue($this->productMock->getDataByKey('ignore_links_flag'));
} else {
$this->assertFalse($this->productMock->getDataByKey('ignore_links_flag'));
}
$resultLinks = [];

$this->assertEquals($tierPrice ?: [], $this->productMock->getData('tier_price'));
Expand Down Expand Up @@ -559,6 +572,34 @@ public static function initializeDataProvider()
['type' => 'related', 'linked_product_sku' => 'Test'],
],
],

// readonly links
[
'single_store' => false,
'website_ids' => ['1' => 1, '2' => 2],
'expected_website_ids' => ['1' => 1, '2' => 2],
'links' => [
'related' => [
0 => [
'id' => 1,
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
'name' => 'Test',
'status' => 'Enabled',
'attribute_set' => 'Default',
'sku' => 'Test',
'price' => 1.00,
'position' => 1,
'record_id' => 1,
],
],
],
'linkTypes' => ['related', 'upsell', 'crosssell'],
'expected_links' => [],
'tierPrice' => [],
true,
true,
true
],
];
}

Expand Down Expand Up @@ -660,6 +701,7 @@ public static function mergeProductOptionsDataProvider()
'default_key2' => 'val22',
],
],
'is_use_default' => 1,
],
],
],
Expand Down Expand Up @@ -702,6 +744,7 @@ public static function mergeProductOptionsDataProvider()
'default_key1' => 'val11',
'default_title' => 'val22',
'is_delete_store_title' => 1,
'is_use_default' => 1,
],
],
],
Expand Down
30 changes: 23 additions & 7 deletions app/code/Magento/CustomerImportExport/Model/Export/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav
* Names that begins with underscore is not an attribute. This name convention is for
* to avoid interference with same attribute name.
*/
const COLUMN_EMAIL = 'email';
public const COLUMN_EMAIL = 'email';

const COLUMN_WEBSITE = '_website';
public const COLUMN_WEBSITE = '_website';

const COLUMN_STORE = '_store';
public const COLUMN_STORE = '_store';

private const COLUMN_CREATED_AT = 'created_at';

private const COLUMN_UPDATED_AT = 'updated_at';

/**
* Attribute collection name
* A constant declaration for attribute collection name
*/
const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class;
public const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class;

/**
* XML path to page size parameter
*/
const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer';
public const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer';

/**
* @var array
Expand Down Expand Up @@ -139,7 +143,7 @@ protected function _getEntityCollection()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
protected function _getHeaderColumns()
{
Expand All @@ -159,6 +163,18 @@ public function exportItem($item)
$row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()];
$row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()];

if (isset($row[self::COLUMN_CREATED_AT])) {
$row[self::COLUMN_CREATED_AT] = $this->_localeDate
->scopeDate(null, $item->getCreatedAt(), true)
->format('Y-m-d H:i:s');
}

if (isset($row[self::COLUMN_UPDATED_AT])) {
$row[self::COLUMN_UPDATED_AT] = $this->_localeDate
->scopeDate(null, $item->getUpdatedAt(), true)
->format('Y-m-d H:i:s');
}

$this->getWriter()->writeRow($row);
}

Expand Down
Loading

0 comments on commit 2d831e4

Please sign in to comment.