Skip to content

Commit cc5fa97

Browse files
committed
Merge remote-tracking branch 'upstream/2.3.0-release' into MAGETWO-95654
2 parents cb2aadc + f0fcaa0 commit cc5fa97

File tree

386 files changed

+7980
-4359
lines changed

Some content is hidden

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

386 files changed

+7980
-4359
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ public function __construct(array $blackList = [])
2727

2828
/**
2929
* Delete custom attribute
30-
* @param array $attributes
30+
*
31+
* @param array $attributes set objects attributes @example ['attribute_code'=>'attribute_object']
3132
* @return array
3233
*/
3334
public function execute(array $attributes): array
3435
{
35-
return array_diff($attributes, $this->blackList);
36+
return array_diff_key($attributes, array_flip($this->blackList));
3637
}
3738
}

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

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,26 @@ protected function _getResource()
498498
}
499499

500500
/**
501-
* Get a list of custom attribute codes that belongs to product attribute set. If attribute set not specified for
502-
* product will return all product attribute codes
501+
* Get a list of custom attribute codes that belongs to product attribute set.
502+
*
503+
* If attribute set not specified for product will return all product attribute codes
503504
*
504505
* @return string[]
505506
*/
506507
protected function getCustomAttributesCodes()
507508
{
508509
if ($this->customAttributesCodes === null) {
509-
$this->customAttributesCodes = array_keys($this->eavConfig->getEntityAttributes(
510-
self::ENTITY,
511-
$this
512-
));
513-
514-
$this->customAttributesCodes = $this->filterCustomAttribute->execute($this->customAttributesCodes);
515-
$this->customAttributesCodes = array_diff($this->customAttributesCodes, ProductInterface::ATTRIBUTES);
510+
$this->customAttributesCodes = array_diff(
511+
array_keys(
512+
$this->filterCustomAttribute->execute(
513+
$this->eavConfig->getEntityAttributes(
514+
self::ENTITY,
515+
$this
516+
)
517+
)
518+
),
519+
ProductInterface::ATTRIBUTES
520+
);
516521
}
517522

518523
return $this->customAttributesCodes;
@@ -584,8 +589,9 @@ public function getPrice()
584589
}
585590

586591
/**
587-
* @codeCoverageIgnoreStart
588592
* Get visibility status
593+
*
594+
* @codeCoverageIgnoreStart
589595
* @see \Magento\Catalog\Model\Product\Visibility
590596
*
591597
* @return int
@@ -662,6 +668,7 @@ public function getStatus()
662668

663669
/**
664670
* Retrieve type instance of the product.
671+
*
665672
* Type instance implements product type depended logic and is a singleton shared by all products of the same type.
666673
*
667674
* @return \Magento\Catalog\Model\Product\Type\AbstractType
@@ -822,9 +829,10 @@ public function getStoreIds()
822829

823830
/**
824831
* Retrieve product attributes
825-
* if $groupId is null - retrieve all product attributes
826832
*
827-
* @param int $groupId Retrieve attributes of the specified group
833+
* If $groupId is null - retrieve all product attributes
834+
*
835+
* @param int $groupId Retrieve attributes of the specified group
828836
* @param bool $skipSuper Not used
829837
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
830838
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -916,6 +924,7 @@ public function beforeSave()
916924

917925
/**
918926
* Check/set if options can be affected when saving product
927+
*
919928
* If value specified, it will be set.
920929
*
921930
* @param bool $value
@@ -1036,9 +1045,11 @@ public function reindex()
10361045

10371046
/**
10381047
* Clear cache related with product and protect delete from not admin
1048+
*
10391049
* Register indexing event before delete product
10401050
*
10411051
* @return \Magento\Catalog\Model\Product
1052+
* @throws \Magento\Framework\Exception\LocalizedException
10421053
*/
10431054
public function beforeDelete()
10441055
{
@@ -1545,12 +1556,12 @@ public function hasGalleryAttribute()
15451556
/**
15461557
* Add image to media gallery
15471558
*
1548-
* @param string $file file path of image in file system
1549-
* @param string|array $mediaAttribute code of attribute with type 'media_image',
1550-
* leave blank if image should be only in gallery
1551-
* @param boolean $move if true, it will move source file
1552-
* @param boolean $exclude mark image as disabled in product page view
1559+
* @param string $file file path of image in file system
1560+
* @param string|array $mediaAttribute code of type 'media_image', leave blank if image should be only in gallery
1561+
* @param boolean $move if true, it will move source file
1562+
* @param boolean $exclude mark image as disabled in product page view
15531563
* @return \Magento\Catalog\Model\Product
1564+
* @throws \Magento\Framework\Exception\LocalizedException
15541565
*/
15551566
public function addImageToMediaGallery($file, $mediaAttribute = null, $move = false, $exclude = true)
15561567
{
@@ -1711,7 +1722,6 @@ public function getIsSalable()
17111722

17121723
/**
17131724
* Check is a virtual product
1714-
* Data helper wrapper
17151725
*
17161726
* @return bool
17171727
*/
@@ -1804,8 +1814,8 @@ public function formatUrlKey($str)
18041814
* Save current attribute with code $code and assign new value
18051815
*
18061816
* @param string $code Attribute code
1807-
* @param mixed $value New attribute value
1808-
* @param int $store Store ID
1817+
* @param mixed $value New attribute value
1818+
* @param int $store Store ID
18091819
* @return void
18101820
*/
18111821
public function addAttributeUpdate($code, $value, $store)
@@ -1875,6 +1885,7 @@ public function getRequestPath()
18751885

18761886
/**
18771887
* Custom function for other modules
1888+
*
18781889
* @return string
18791890
*/
18801891
public function getGiftMessageAvailable()
@@ -1993,6 +2004,8 @@ public function getOptions()
19932004
}
19942005

19952006
/**
2007+
* Set options for product
2008+
*
19962009
* @param \Magento\Catalog\Api\Data\ProductCustomOptionInterface[] $options
19972010
* @return $this
19982011
*/
@@ -2016,10 +2029,10 @@ public function getIsVirtual()
20162029
/**
20172030
* Add custom option information to product
20182031
*
2019-
* @param string $code Option code
2020-
* @param mixed $value Value of the option
2021-
* @param int|Product $product Product ID
2022-
* @return $this
2032+
* @param string $code Option code
2033+
* @param mixed $value Value of the option
2034+
* @param int|Product $product Product ID
2035+
* @return $this
20232036
*/
20242037
public function addCustomOption($code, $value, $product = null)
20252038
{
@@ -2213,6 +2226,7 @@ public function getPreconfiguredValues()
22132226

22142227
/**
22152228
* Prepare product custom options.
2229+
*
22162230
* To be sure that all product custom options does not has ID and has product instance
22172231
*
22182232
* @return \Magento\Catalog\Model\Product
@@ -2547,17 +2561,17 @@ public function setTypeId($typeId)
25472561
}
25482562

25492563
/**
2550-
* {@inheritdoc}
2564+
* Retrieve existing extension attributes object or create a new one.
25512565
*
2552-
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface
2566+
* @return \Magento\Framework\Api\ExtensionAttributesInterface
25532567
*/
25542568
public function getExtensionAttributes()
25552569
{
25562570
return $this->_getExtensionAttributes();
25572571
}
25582572

25592573
/**
2560-
* {@inheritdoc}
2574+
* Set an extension attributes object.
25612575
*
25622576
* @param \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes
25632577
* @return $this
@@ -2570,8 +2584,11 @@ public function setExtensionAttributes(\Magento\Catalog\Api\Data\ProductExtensio
25702584
//@codeCoverageIgnoreEnd
25712585

25722586
/**
2587+
* Convert to media gallery interface
2588+
*
25732589
* @param array $mediaGallery
25742590
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
2591+
* @throws \Magento\Framework\Exception\LocalizedException
25752592
*/
25762593
protected function convertToMediaGalleryInterface(array $mediaGallery)
25772594
{
@@ -2587,7 +2604,10 @@ protected function convertToMediaGalleryInterface(array $mediaGallery)
25872604
}
25882605

25892606
/**
2607+
* Get media gallery entries
2608+
*
25902609
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]|null
2610+
* @throws \Magento\Framework\Exception\LocalizedException
25912611
*/
25922612
public function getMediaGalleryEntries()
25932613
{
@@ -2601,8 +2621,11 @@ public function getMediaGalleryEntries()
26012621
}
26022622

26032623
/**
2624+
* Set media gallery entries
2625+
*
26042626
* @param ProductAttributeMediaGalleryEntryInterface[] $mediaGalleryEntries
26052627
* @return $this
2628+
* @throws \Magento\Framework\Exception\LocalizedException
26062629
*/
26072630
public function setMediaGalleryEntries(array $mediaGalleryEntries = null)
26082631
{
@@ -2643,6 +2666,8 @@ public function setId($value)
26432666
}
26442667

26452668
/**
2669+
* Get link repository
2670+
*
26462671
* @return ProductLinkRepositoryInterface
26472672
*/
26482673
private function getLinkRepository()
@@ -2655,6 +2680,8 @@ private function getLinkRepository()
26552680
}
26562681

26572682
/**
2683+
* Get media gallery processor
2684+
*
26582685
* @return Product\Gallery\Processor
26592686
*/
26602687
private function getMediaGalleryProcessor()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Model\Product\Option\Type\File;
10+
11+
/**
12+
* Validator for existing (already saved) files.
13+
*/
14+
class ExistingValidate extends \Zend_Validate
15+
{
16+
/**
17+
* @inheritDoc
18+
*
19+
* @param string $value File's full path.
20+
* @param string|null $originalName Original file's name (when uploaded).
21+
*/
22+
public function isValid($value, string $originalName = null)
23+
{
24+
$this->_messages = [];
25+
$this->_errors = [];
26+
27+
if (!is_string($value)) {
28+
$this->_messages[] = __('Full file path is expected.')->render();
29+
return false;
30+
}
31+
32+
$result = true;
33+
$fileInfo = null;
34+
if ($originalName) {
35+
$fileInfo = ['name' => $originalName];
36+
}
37+
foreach ($this->_validators as $element) {
38+
$validator = $element['instance'];
39+
if ($validator->isValid($value, $fileInfo)) {
40+
continue;
41+
}
42+
$result = false;
43+
$messages = $validator->getMessages();
44+
$this->_messages = array_merge($this->_messages, $messages);
45+
$this->_errors = array_merge($this->_errors, array_keys($messages));
46+
if ($element['breakChainOnFailure']) {
47+
break;
48+
}
49+
}
50+
return $result;
51+
}
52+
}

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidateFactory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66

77
namespace Magento\Catalog\Model\Product\Option\Type\File;
88

9+
/**
10+
* Class ValidateFactory. Creates Validator with type "ExistingValidate"
11+
*/
912
class ValidateFactory
1013
{
1114
/**
15+
* Main factory method
16+
*
1217
* @return \Zend_Validate
1318
*/
1419
public function create()
1520
{
16-
return new \Zend_Validate();
21+
return new ExistingValidate();
1722
}
1823
}

0 commit comments

Comments
 (0)