Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 6fd18bf

Browse files
committed
Merge remote-tracking branch 'mainline/2.3-develop' into 2.3.0-release-merge
# Conflicts: # app/code/Magento/Sales/view/frontend/layout/sales_order_print.xml
2 parents 8934234 + 20f1162 commit 6fd18bf

File tree

64 files changed

+1807
-275
lines changed

Some content is hidden

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

64 files changed

+1807
-275
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
7272

7373
const CACHE_TAG = 'cat_c';
7474

75+
/**
76+
* Category Store Id
77+
*/
78+
const STORE_ID = 'store_id';
79+
7580
/**#@-*/
7681
protected $_eventPrefix = 'catalog_category';
7782

@@ -564,12 +569,12 @@ public function getStoreIds()
564569
*
565570
* If store id is underfined for category return current active store id
566571
*
567-
* @return integer
572+
* @return int
568573
*/
569574
public function getStoreId()
570575
{
571-
if ($this->hasData('store_id')) {
572-
return (int)$this->_getData('store_id');
576+
if ($this->hasData(self::STORE_ID)) {
577+
return (int)$this->_getData(self::STORE_ID);
573578
}
574579
return (int)$this->_storeManager->getStore()->getId();
575580
}
@@ -585,7 +590,7 @@ public function setStoreId($storeId)
585590
if (!is_numeric($storeId)) {
586591
$storeId = $this->_storeManager->getStore($storeId)->getId();
587592
}
588-
$this->setData('store_id', $storeId);
593+
$this->setData(self::STORE_ID, $storeId);
589594
$this->getResource()->setStoreId($storeId);
590595
return $this;
591596
}

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

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,9 @@ 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
*/
@@ -526,9 +527,9 @@ protected function getCustomAttributesCodes()
526527
public function getStoreId()
527528
{
528529
if ($this->hasData(self::STORE_ID)) {
529-
return $this->getData(self::STORE_ID);
530+
return (int)$this->getData(self::STORE_ID);
530531
}
531-
return $this->_storeManager->getStore()->getId();
532+
return (int)$this->_storeManager->getStore()->getId();
532533
}
533534

534535
/**
@@ -584,8 +585,9 @@ public function getPrice()
584585
}
585586

586587
/**
587-
* @codeCoverageIgnoreStart
588588
* Get visibility status
589+
*
590+
* @codeCoverageIgnoreStart
589591
* @see \Magento\Catalog\Model\Product\Visibility
590592
*
591593
* @return int
@@ -662,6 +664,7 @@ public function getStatus()
662664

663665
/**
664666
* Retrieve type instance of the product.
667+
*
665668
* Type instance implements product type depended logic and is a singleton shared by all products of the same type.
666669
*
667670
* @return \Magento\Catalog\Model\Product\Type\AbstractType
@@ -822,9 +825,10 @@ public function getStoreIds()
822825

823826
/**
824827
* Retrieve product attributes
825-
* if $groupId is null - retrieve all product attributes
826828
*
827-
* @param int $groupId Retrieve attributes of the specified group
829+
* If $groupId is null - retrieve all product attributes
830+
*
831+
* @param int $groupId Retrieve attributes of the specified group
828832
* @param bool $skipSuper Not used
829833
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
830834
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -916,6 +920,7 @@ public function beforeSave()
916920

917921
/**
918922
* Check/set if options can be affected when saving product
923+
*
919924
* If value specified, it will be set.
920925
*
921926
* @param bool $value
@@ -976,7 +981,7 @@ public function setQty($qty)
976981
*/
977982
public function getQty()
978983
{
979-
return $this->getData('qty');
984+
return (float)$this->getData('qty');
980985
}
981986

982987
/**
@@ -1036,6 +1041,7 @@ public function reindex()
10361041

10371042
/**
10381043
* Clear cache related with product and protect delete from not admin
1044+
*
10391045
* Register indexing event before delete product
10401046
*
10411047
* @return \Magento\Catalog\Model\Product
@@ -1545,11 +1551,11 @@ public function hasGalleryAttribute()
15451551
/**
15461552
* Add image to media gallery
15471553
*
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
1554+
* @param string $file file path of image in file system
1555+
* @param string|array $mediaAttribute code of attribute with type 'media_image',
1556+
* leave blank if image should be only in gallery
1557+
* @param bool $move if true, it will move source file
1558+
* @param bool $exclude mark image as disabled in product page view
15531559
* @return \Magento\Catalog\Model\Product
15541560
*/
15551561
public function addImageToMediaGallery($file, $mediaAttribute = null, $move = false, $exclude = true)
@@ -1711,6 +1717,7 @@ public function getIsSalable()
17111717

17121718
/**
17131719
* Check is a virtual product
1720+
*
17141721
* Data helper wrapper
17151722
*
17161723
* @return bool
@@ -1803,9 +1810,9 @@ public function formatUrlKey($str)
18031810
/**
18041811
* Save current attribute with code $code and assign new value
18051812
*
1806-
* @param string $code Attribute code
1807-
* @param mixed $value New attribute value
1808-
* @param int $store Store ID
1813+
* @param string $code Attribute code
1814+
* @param mixed $value New attribute value
1815+
* @param int $store Store ID
18091816
* @return void
18101817
*/
18111818
public function addAttributeUpdate($code, $value, $store)
@@ -1875,6 +1882,7 @@ public function getRequestPath()
18751882

18761883
/**
18771884
* Custom function for other modules
1885+
*
18781886
* @return string
18791887
*/
18801888
public function getGiftMessageAvailable()
@@ -1993,6 +2001,8 @@ public function getOptions()
19932001
}
19942002

19952003
/**
2004+
* Set product options
2005+
*
19962006
* @param \Magento\Catalog\Api\Data\ProductCustomOptionInterface[] $options
19972007
* @return $this
19982008
*/
@@ -2016,10 +2026,10 @@ public function getIsVirtual()
20162026
/**
20172027
* Add custom option information to product
20182028
*
2019-
* @param string $code Option code
2020-
* @param mixed $value Value of the option
2021-
* @param int|Product $product Product ID
2022-
* @return $this
2029+
* @param string $code Option code
2030+
* @param mixed $value Value of the option
2031+
* @param int|Product $product Product ID
2032+
* @return $this
20232033
*/
20242034
public function addCustomOption($code, $value, $product = null)
20252035
{
@@ -2213,6 +2223,7 @@ public function getPreconfiguredValues()
22132223

22142224
/**
22152225
* Prepare product custom options.
2226+
*
22162227
* To be sure that all product custom options does not has ID and has product instance
22172228
*
22182229
* @return \Magento\Catalog\Model\Product
@@ -2547,7 +2558,7 @@ public function setTypeId($typeId)
25472558
}
25482559

25492560
/**
2550-
* {@inheritdoc}
2561+
* @inheritdoc
25512562
*
25522563
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface
25532564
*/
@@ -2557,7 +2568,7 @@ public function getExtensionAttributes()
25572568
}
25582569

25592570
/**
2560-
* {@inheritdoc}
2571+
* @inheritdoc
25612572
*
25622573
* @param \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes
25632574
* @return $this
@@ -2570,6 +2581,8 @@ public function setExtensionAttributes(\Magento\Catalog\Api\Data\ProductExtensio
25702581
//@codeCoverageIgnoreEnd
25712582

25722583
/**
2584+
* Convert array to media gallery interface
2585+
*
25732586
* @param array $mediaGallery
25742587
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
25752588
*/
@@ -2587,6 +2600,8 @@ protected function convertToMediaGalleryInterface(array $mediaGallery)
25872600
}
25882601

25892602
/**
2603+
* Returns media gallery entries
2604+
*
25902605
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]|null
25912606
*/
25922607
public function getMediaGalleryEntries()
@@ -2601,6 +2616,8 @@ public function getMediaGalleryEntries()
26012616
}
26022617

26032618
/**
2619+
* Set media gallery entries
2620+
*
26042621
* @param ProductAttributeMediaGalleryEntryInterface[] $mediaGalleryEntries
26052622
* @return $this
26062623
*/
@@ -2643,6 +2660,8 @@ public function setId($value)
26432660
}
26442661

26452662
/**
2663+
* Returns link repository instance
2664+
*
26462665
* @return ProductLinkRepositoryInterface
26472666
*/
26482667
private function getLinkRepository()
@@ -2655,6 +2674,8 @@ private function getLinkRepository()
26552674
}
26562675

26572676
/**
2677+
* Returns media gallery processor instance
2678+
*
26582679
* @return Product\Gallery\Processor
26592680
*/
26602681
private function getMediaGalleryProcessor()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Product\Option;
9+
10+
use Magento\Catalog\Model\Product\Option\Type\Date as ProductDateOptionType;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Stdlib\DateTime;
13+
14+
/**
15+
* @inheritdoc
16+
*/
17+
class DateType extends ProductDateOptionType
18+
{
19+
/**
20+
* Make valid string as a value of date option type for GraphQl queries
21+
*
22+
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
23+
* @return ProductDateOptionType
24+
*/
25+
public function validateUserValue($values)
26+
{
27+
if ($this->_dateExists() || $this->_timeExists()) {
28+
return parent::validateUserValue($this->formatValues($values));
29+
}
30+
31+
return $this;
32+
}
33+
34+
/**
35+
* Format date value from string to date array
36+
*
37+
* @param [] $values
38+
* @return []
39+
* @throws LocalizedException
40+
*/
41+
private function formatValues($values)
42+
{
43+
if (isset($values[$this->getOption()->getId()])) {
44+
$value = $values[$this->getOption()->getId()];
45+
$dateTime = \DateTime::createFromFormat(DateTime::DATETIME_PHP_FORMAT, $value);
46+
$values[$this->getOption()->getId()] = [
47+
'date' => $value,
48+
'year' => $dateTime->format('Y'),
49+
'month' => $dateTime->format('m'),
50+
'day' => $dateTime->format('d'),
51+
'hour' => $dateTime->format('H'),
52+
'minute' => $dateTime->format('i'),
53+
'day_part' => $dateTime->format('a'),
54+
];
55+
}
56+
57+
return $values;
58+
}
59+
60+
/**
61+
* @inheritdoc
62+
*/
63+
public function useCalendar()
64+
{
65+
return false;
66+
}
67+
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Categories.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
}
8080

8181
/**
82-
* {@inheritdoc}
82+
* @inheritdoc
8383
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8484
*/
8585
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
@@ -114,6 +114,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
114114
$categories[$item->getId()] = $this->customAttributesFlattener
115115
->flatten($categories[$item->getId()]);
116116
$categories[$item->getId()]['product_count'] = $item->getProductCount();
117+
$categories[$item->getId()]['model'] = $item;
117118
}
118119
}
119120

0 commit comments

Comments
 (0)