Skip to content

Commit 4ddae72

Browse files
committed
Merge branch '2.4-develop' of https://github.com/srsathish92/magento2 into bug/26992-rating-checkbox-alignment
2 parents 0831958 + 3455667 commit 4ddae72

File tree

176 files changed

+5762
-1560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+5762
-1560
lines changed

app/code/Magento/CardinalCommerce/Test/Mftf/Test/AdminCardinalCommerceSettingsHiddenTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<annotations>
1212
<stories value="Cardinal Commerce Settings"/>
1313
<features value="CardinalCommerce"/>
14+
<stories value="Configure CardinalCommerce"/>
1415
<title value="CardinalCommerce settings hidden" />
1516
<description value="CardinalCommerce config shouldn't be visible if the 3D secure is disabled for Authorize.Net."/>
1617
<severity value="MINOR"/>

app/code/Magento/Catalog/Api/ProductLinkManagementInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface ProductLinkManagementInterface
1717
*
1818
* @param string $sku
1919
* @param string $type
20+
* @throws \Magento\Framework\Exception\NoSuchEntityException
2021
* @return \Magento\Catalog\Api\Data\ProductLinkInterface[]
2122
*/
2223
public function getLinkedItemsByType($sku, $type);
@@ -28,6 +29,7 @@ public function getLinkedItemsByType($sku, $type);
2829
* @param \Magento\Catalog\Api\Data\ProductLinkInterface[] $items
2930
* @throws \Magento\Framework\Exception\NoSuchEntityException
3031
* @throws \Magento\Framework\Exception\CouldNotSaveException
32+
* @throws \Magento\Framework\Exception\InputException
3133
* @return bool
3234
*/
3335
public function setProductLinks($sku, array $items);

app/code/Magento/Catalog/Block/Product/ImageFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function getLabel(Product $product, string $imageType): string
123123
if (empty($label)) {
124124
$label = $product->getName();
125125
}
126-
return (string) $label;
126+
return (string)$label;
127127
}
128128

129129
/**
@@ -161,15 +161,15 @@ public function create(Product $product, string $imageId, array $attributes = nu
161161
}
162162

163163
$attributes = $attributes === null ? [] : $attributes;
164-
164+
165165
$data = [
166166
'data' => [
167167
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
168168
'image_url' => $imageAsset->getUrl(),
169169
'width' => $imageMiscParams['image_width'],
170170
'height' => $imageMiscParams['image_height'],
171171
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
172-
'ratio' => $this->getRatio($imageMiscParams['image_width'], $imageMiscParams['image_height']),
172+
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
173173
'custom_attributes' => $this->getStringCustomAttributes($attributes),
174174
'class' => $this->getClass($attributes),
175175
'product_id' => $product->getId()

app/code/Magento/Catalog/Model/Product.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
1212
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
13+
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
1314
use Magento\Catalog\Model\FilterProductCustomAttribute;
1415
use Magento\Framework\Api\AttributeValueFactory;
1516
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -108,7 +109,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
108109
/**
109110
* Product object customization (not stored in DB)
110111
*
111-
* @var array
112+
* @var OptionInterface[]
112113
*/
113114
protected $_customOptions = [];
114115

@@ -2062,7 +2063,7 @@ public function addCustomOption($code, $value, $product = null)
20622063
/**
20632064
* Sets custom options for the product
20642065
*
2065-
* @param array $options Array of options
2066+
* @param OptionInterface[] $options Array of options
20662067
* @return void
20672068
*/
20682069
public function setCustomOptions(array $options)
@@ -2073,7 +2074,7 @@ public function setCustomOptions(array $options)
20732074
/**
20742075
* Get all custom options of the product
20752076
*
2076-
* @return array
2077+
* @return OptionInterface[]
20772078
*/
20782079
public function getCustomOptions()
20792080
{
@@ -2084,14 +2085,11 @@ public function getCustomOptions()
20842085
* Get product custom option info
20852086
*
20862087
* @param string $code
2087-
* @return array
2088+
* @return OptionInterface|null
20882089
*/
20892090
public function getCustomOption($code)
20902091
{
2091-
if (isset($this->_customOptions[$code])) {
2092-
return $this->_customOptions[$code];
2093-
}
2094-
return null;
2092+
return $this->_customOptions[$code] ?? null;
20952093
}
20962094

20972095
/**
@@ -2101,11 +2099,7 @@ public function getCustomOption($code)
21012099
*/
21022100
public function hasCustomOptions()
21032101
{
2104-
if (count($this->_customOptions)) {
2105-
return true;
2106-
} else {
2107-
return false;
2108-
}
2102+
return (bool)count($this->_customOptions);
21092103
}
21102104

21112105
/**
@@ -2405,16 +2399,14 @@ public function reloadPriceInfo()
24052399
}
24062400
}
24072401

2408-
// phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
24092402
/**
24102403
* Return Data Object data in array format.
24112404
*
24122405
* @return array
24132406
* @todo refactor with converter for AbstractExtensibleModel
24142407
*/
2415-
public function __toArray()
2408+
public function __toArray() //phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
24162409
{
2417-
// phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
24182410
$data = $this->_data;
24192411
$hasToArray = function ($model) {
24202412
return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);

app/code/Magento/Catalog/Model/Product/Type.php

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,37 @@
66
namespace Magento\Catalog\Model\Product;
77

88
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Type\Pool;
10+
use Magento\Catalog\Model\Product\Type\Price;
11+
use Magento\Catalog\Model\Product\Type\Price\Factory as PriceFactory;
12+
use Magento\Catalog\Model\Product\Type\Simple;
13+
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
914
use Magento\Framework\Data\OptionSourceInterface;
15+
use Magento\Framework\Pricing\PriceInfo\Factory as PriceInfoFactory;
1016

1117
/**
1218
* Product type model
1319
*
20+
*
1421
* @api
1522
* @since 100.0.2
1623
*/
1724
class Type implements OptionSourceInterface
1825
{
19-
/**#@+
20-
* Available product types
21-
*/
2226
const TYPE_SIMPLE = 'simple';
2327

2428
const TYPE_BUNDLE = 'bundle';
2529

2630
const TYPE_VIRTUAL = 'virtual';
27-
/**#@-*/
2831

29-
/**
30-
* Default product type
31-
*/
3232
const DEFAULT_TYPE = 'simple';
3333

34-
/**
35-
* Default product type model
36-
*/
37-
const DEFAULT_TYPE_MODEL = \Magento\Catalog\Model\Product\Type\Simple::class;
34+
const DEFAULT_TYPE_MODEL = Simple::class;
3835

39-
/**
40-
* Default price model
41-
*/
42-
const DEFAULT_PRICE_MODEL = \Magento\Catalog\Model\Product\Type\Price::class;
36+
const DEFAULT_PRICE_MODEL = Price::class;
4337

4438
/**
45-
* @var \Magento\Catalog\Model\ProductTypes\ConfigInterface
39+
* @var ConfigInterface
4640
*/
4741
protected $_config;
4842

@@ -77,35 +71,35 @@ class Type implements OptionSourceInterface
7771
/**
7872
* Product type factory
7973
*
80-
* @var \Magento\Catalog\Model\Product\Type\Pool
74+
* @var Pool
8175
*/
8276
protected $_productTypePool;
8377

8478
/**
8579
* Price model factory
8680
*
87-
* @var \Magento\Catalog\Model\Product\Type\Price\Factory
81+
* @var PriceFactory
8882
*/
8983
protected $_priceFactory;
9084

9185
/**
92-
* @var \Magento\Framework\Pricing\PriceInfo\Factory
86+
* @var PriceInfoFactory
9387
*/
9488
protected $_priceInfoFactory;
9589

9690
/**
9791
* Construct
9892
*
99-
* @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $config
100-
* @param \Magento\Catalog\Model\Product\Type\Pool $productTypePool
101-
* @param \Magento\Catalog\Model\Product\Type\Price\Factory $priceFactory
102-
* @param \Magento\Framework\Pricing\PriceInfo\Factory $priceInfoFactory
93+
* @param ConfigInterface $config
94+
* @param Pool $productTypePool
95+
* @param PriceFactory $priceFactory
96+
* @param PriceInfoFactory $priceInfoFactory
10397
*/
10498
public function __construct(
105-
\Magento\Catalog\Model\ProductTypes\ConfigInterface $config,
106-
\Magento\Catalog\Model\Product\Type\Pool $productTypePool,
107-
\Magento\Catalog\Model\Product\Type\Price\Factory $priceFactory,
108-
\Magento\Framework\Pricing\PriceInfo\Factory $priceInfoFactory
99+
ConfigInterface $config,
100+
Pool $productTypePool,
101+
PriceFactory $priceFactory,
102+
PriceInfoFactory $priceInfoFactory
109103
) {
110104
$this->_config = $config;
111105
$this->_productTypePool = $productTypePool;
@@ -116,8 +110,8 @@ public function __construct(
116110
/**
117111
* Factory to product singleton product type instances
118112
*
119-
* @param \Magento\Catalog\Model\Product $product
120-
* @return \Magento\Catalog\Model\Product\Type\AbstractType
113+
* @param \Magento\Catalog\Api\Data\ProductInterface $product
114+
* @return \Magento\Catalog\Model\Product\Type\AbstractType
121115
*/
122116
public function factory($product)
123117
{
@@ -139,8 +133,8 @@ public function factory($product)
139133
/**
140134
* Product type price model factory
141135
*
142-
* @param string $productType
143-
* @return \Magento\Catalog\Model\Product\Type\Price
136+
* @param string $productType
137+
* @return \Magento\Catalog\Model\Product\Type\Price
144138
*/
145139
public function priceFactory($productType)
146140
{

app/code/Magento/Catalog/Model/ProductLink/Management.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,42 @@
66

77
namespace Magento\Catalog\Model\ProductLink;
88

9-
use Magento\Catalog\Api\Data;
109
use Magento\Framework\Exception\CouldNotSaveException;
1110
use Magento\Framework\Exception\NoSuchEntityException;
1211
use Magento\Framework\Exception\InputException;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Catalog\Model\Product\LinkTypeProvider;
14+
use Magento\Catalog\Api\ProductLinkManagementInterface;
1315

14-
class Management implements \Magento\Catalog\Api\ProductLinkManagementInterface
16+
/**
17+
* Manage product links from api
18+
*/
19+
class Management implements ProductLinkManagementInterface
1520
{
1621
/**
17-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
22+
* @var ProductRepositoryInterface
1823
*/
1924
protected $productRepository;
2025

2126
/**
22-
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
27+
* @var LinkTypeProvider
2328
*/
2429
protected $linkTypeProvider;
2530

2631
/**
27-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
28-
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
32+
* @param ProductRepositoryInterface $productRepository
33+
* @param LinkTypeProvider $linkTypeProvider
2934
*/
3035
public function __construct(
31-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
32-
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
36+
ProductRepositoryInterface $productRepository,
37+
LinkTypeProvider $linkTypeProvider
3338
) {
3439
$this->productRepository = $productRepository;
3540
$this->linkTypeProvider = $linkTypeProvider;
3641
}
3742

3843
/**
39-
* {@inheritdoc}
44+
* @inheritdoc
4045
*/
4146
public function getLinkedItemsByType($sku, $type)
4247
{
@@ -63,47 +68,42 @@ public function getLinkedItemsByType($sku, $type)
6368
}
6469

6570
/**
66-
* {@inheritdoc}
71+
* @inheritdoc
6772
*/
6873
public function setProductLinks($sku, array $items)
6974
{
75+
76+
if (empty($items)) {
77+
throw InputException::invalidFieldValue('items', 'empty array');
78+
}
79+
7080
$linkTypes = $this->linkTypeProvider->getLinkTypes();
7181

7282
// Check if product link type is set and correct
73-
if (!empty($items)) {
74-
foreach ($items as $newLink) {
75-
$type = $newLink->getLinkType();
76-
if ($type == null) {
77-
throw InputException::requiredField("linkType");
78-
}
79-
if (!isset($linkTypes[$type])) {
80-
throw new NoSuchEntityException(
81-
__('The "%1" link type wasn\'t found. Verify the type and try again.', $type)
82-
);
83-
}
83+
foreach ($items as $newLink) {
84+
$type = $newLink->getLinkType();
85+
if ($type == null) {
86+
throw InputException::requiredField("linkType");
87+
}
88+
if (!isset($linkTypes[$type])) {
89+
throw new NoSuchEntityException(
90+
__('The "%1" link type wasn\'t found. Verify the type and try again.', $type)
91+
);
8492
}
8593
}
8694

8795
$product = $this->productRepository->get($sku);
8896

89-
// Replace only links of the specified type
9097
$existingLinks = $product->getProductLinks();
91-
$newLinks = [];
92-
if (!empty($existingLinks)) {
93-
foreach ($existingLinks as $link) {
94-
if ($link->getLinkType() != $type) {
95-
$newLinks[] = $link;
96-
}
97-
}
98-
$newLinks = array_merge($newLinks, $items);
99-
} else {
100-
$newLinks = $items;
101-
}
98+
$newLinks = array_merge($existingLinks, $items);
99+
102100
$product->setProductLinks($newLinks);
103101
try {
104102
$this->productRepository->save($product);
105103
} catch (\Exception $exception) {
106-
throw new CouldNotSaveException(__('The linked products data is invalid. Verify the data and try again.'));
104+
throw new CouldNotSaveException(
105+
__('The linked products data is invalid. Verify the data and try again.')
106+
);
107107
}
108108

109109
return true;

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@
212212
<data key="quantity">1001</data>
213213
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
214214
</entity>
215+
<entity name="SimpleProductDisabledStockQuantityZero" type="product">
216+
<data key="sku" unique="suffix">testSku</data>
217+
<data key="type_id">simple</data>
218+
<data key="attribute_set_id">4</data>
219+
<data key="name" unique="suffix">Simple Product Disabled Quantity Zero</data>
220+
<data key="price">123.00</data>
221+
<data key="visibility">4</data>
222+
<data key="status">2</data>
223+
<data key="quantity">0</data>
224+
<requiredEntity type="product_extension_attribute">EavStock0</requiredEntity>
225+
</entity>
215226
<entity name="SimpleProductNotVisibleIndividually" type="product">
216227
<data key="name" unique="suffix">Simple Product Not Visible Individually</data>
217228
<data key="sku" unique="suffix">simple_product_not_visible_individually</data>

0 commit comments

Comments
 (0)