Skip to content

Commit d68a1ba

Browse files
ENGCOM-4332: Applied PHP-CS-Fixer for code cleanup. #21347
- Merge Pull Request #21347 from yogeshsuhagiya/magento2:2.3-develop-PR-yogesh-7 - Merged commits: 1. 974152f 2. 238dc43 3. e1b23a1
2 parents 16cbf72 + e1b23a1 commit d68a1ba

File tree

29 files changed

+1445
-277
lines changed

29 files changed

+1445
-277
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage/Url.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\ImageFactory;
12+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image\Placeholder as PlaceholderProvider;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
1415
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -23,14 +24,21 @@ class Url implements ResolverInterface
2324
* @var ImageFactory
2425
*/
2526
private $productImageFactory;
27+
/**
28+
* @var PlaceholderProvider
29+
*/
30+
private $placeholderProvider;
2631

2732
/**
2833
* @param ImageFactory $productImageFactory
34+
* @param PlaceholderProvider $placeholderProvider
2935
*/
3036
public function __construct(
31-
ImageFactory $productImageFactory
37+
ImageFactory $productImageFactory,
38+
PlaceholderProvider $placeholderProvider
3239
) {
3340
$this->productImageFactory = $productImageFactory;
41+
$this->placeholderProvider = $placeholderProvider;
3442
}
3543

3644
/**
@@ -55,23 +63,27 @@ public function resolve(
5563
$product = $value['model'];
5664
$imagePath = $product->getData($value['image_type']);
5765

58-
$imageUrl = $this->getImageUrl($value['image_type'], $imagePath);
59-
return $imageUrl;
66+
return $this->getImageUrl($value['image_type'], $imagePath);
6067
}
6168

6269
/**
63-
* Get image url
70+
* Get image URL
6471
*
6572
* @param string $imageType
66-
* @param string|null $imagePath Null if image is not set
73+
* @param string|null $imagePath
6774
* @return string
75+
* @throws \Exception
6876
*/
6977
private function getImageUrl(string $imageType, ?string $imagePath): string
7078
{
7179
$image = $this->productImageFactory->create();
7280
$image->setDestinationSubdir($imageType)
7381
->setBaseFile($imagePath);
74-
$imageUrl = $image->getUrl();
75-
return $imageUrl;
82+
83+
if ($image->isBaseFilePlaceholder()) {
84+
return $this->placeholderProvider->getPlaceholder($imageType);
85+
}
86+
87+
return $image->getUrl();
7688
}
7789
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Resolver\Products\DataProvider\Image;
9+
10+
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
11+
use Magento\Framework\View\Asset\Repository as AssetRepository;
12+
13+
/**
14+
* Image Placeholder provider
15+
*/
16+
class Placeholder
17+
{
18+
/**
19+
* @var PlaceholderFactory
20+
*/
21+
private $placeholderFactory;
22+
23+
/**
24+
* @var AssetRepository
25+
*/
26+
private $assetRepository;
27+
28+
/**
29+
* @param PlaceholderFactory $placeholderFactory
30+
* @param AssetRepository $assetRepository
31+
*/
32+
public function __construct(
33+
PlaceholderFactory $placeholderFactory,
34+
AssetRepository $assetRepository
35+
) {
36+
$this->placeholderFactory = $placeholderFactory;
37+
$this->assetRepository = $assetRepository;
38+
}
39+
40+
/**
41+
* Get placeholder
42+
*
43+
* @param string $imageType
44+
* @return string
45+
*/
46+
public function getPlaceholder(string $imageType): string
47+
{
48+
$imageAsset = $this->placeholderFactory->create(['type' => $imageType]);
49+
50+
// check if placeholder defined in config
51+
if ($imageAsset->getFilePath()) {
52+
return $imageAsset->getUrl();
53+
}
54+
55+
return $this->assetRepository->getUrl(
56+
"Magento_Catalog::images/product/placeholder/{$imageType}.jpg"
57+
);
58+
}
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\Resolver\Products\DataProvider\Image\Placeholder;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
14+
/**
15+
* Theme provider
16+
*/
17+
class Theme
18+
{
19+
/**
20+
* @var ScopeConfigInterface
21+
*/
22+
private $scopeConfig;
23+
24+
/**
25+
* @var StoreManagerInterface
26+
*/
27+
private $storeManager;
28+
29+
/**
30+
* @var ThemeProviderInterface
31+
*/
32+
private $themeProvider;
33+
34+
/**
35+
* @param ScopeConfigInterface $scopeConfig
36+
* @param StoreManagerInterface $storeManager
37+
* @param ThemeProviderInterface $themeProvider
38+
*/
39+
public function __construct(
40+
ScopeConfigInterface $scopeConfig,
41+
StoreManagerInterface $storeManager,
42+
ThemeProviderInterface $themeProvider
43+
) {
44+
$this->scopeConfig = $scopeConfig;
45+
$this->storeManager = $storeManager;
46+
$this->themeProvider = $themeProvider;
47+
}
48+
49+
/**
50+
* Get theme model
51+
*
52+
* @return array
53+
* @throws \Magento\Framework\Exception\NoSuchEntityException
54+
*/
55+
public function getThemeData(): array
56+
{
57+
$themeId = $this->scopeConfig->getValue(
58+
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
59+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
60+
$this->storeManager->getStore()->getId()
61+
);
62+
63+
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
64+
$theme = $this->themeProvider->getThemeById($themeId);
65+
66+
$data = $theme->getData();
67+
$data['themeModel'] = $theme;
68+
69+
return $data;
70+
}
71+
}

app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type AddConfigurableProductsToCartOutput {
4949
}
5050

5151
input ConfigurableProductCartItemInput {
52-
data: CartItemDetailsInput!
52+
data: CartItemInput!
5353
variant_sku: String!
5454
customizable_options:[CustomizableOptionInput!]
5555
}

app/code/Magento/Cron/Model/Schedule.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Exception\CronException;
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
12+
use Magento\Framework\Intl\DateTimeFactory;
1213

1314
/**
1415
* Crontab schedule model
@@ -50,24 +51,32 @@ class Schedule extends \Magento\Framework\Model\AbstractModel
5051
*/
5152
private $timezoneConverter;
5253

54+
/**
55+
* @var DateTimeFactory
56+
*/
57+
private $dateTimeFactory;
58+
5359
/**
5460
* @param \Magento\Framework\Model\Context $context
5561
* @param \Magento\Framework\Registry $registry
5662
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
5763
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
5864
* @param array $data
59-
* @param TimezoneInterface $timezoneConverter
65+
* @param TimezoneInterface|null $timezoneConverter
66+
* @param DateTimeFactory|null $dateTimeFactory
6067
*/
6168
public function __construct(
6269
\Magento\Framework\Model\Context $context,
6370
\Magento\Framework\Registry $registry,
6471
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
6572
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
6673
array $data = [],
67-
TimezoneInterface $timezoneConverter = null
74+
TimezoneInterface $timezoneConverter = null,
75+
DateTimeFactory $dateTimeFactory = null
6876
) {
6977
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
7078
$this->timezoneConverter = $timezoneConverter ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
79+
$this->dateTimeFactory = $dateTimeFactory ?: ObjectManager::getInstance()->get(DateTimeFactory::class);
7180
}
7281

7382
/**
@@ -111,17 +120,20 @@ public function trySchedule()
111120
if (!$e || !$time) {
112121
return false;
113122
}
123+
$configTimeZone = $this->timezoneConverter->getConfigTimezone();
124+
$storeDateTime = $this->dateTimeFactory->create(null, new \DateTimeZone($configTimeZone));
114125
if (!is_numeric($time)) {
115126
//convert time from UTC to admin store timezone
116127
//we assume that all schedules in configuration (crontab.xml and DB tables) are in admin store timezone
117-
$time = $this->timezoneConverter->date($time)->format('Y-m-d H:i');
118-
$time = strtotime($time);
128+
$dateTimeUtc = $this->dateTimeFactory->create($time);
129+
$time = $dateTimeUtc->getTimestamp();
119130
}
120-
$match = $this->matchCronExpression($e[0], strftime('%M', $time))
121-
&& $this->matchCronExpression($e[1], strftime('%H', $time))
122-
&& $this->matchCronExpression($e[2], strftime('%d', $time))
123-
&& $this->matchCronExpression($e[3], strftime('%m', $time))
124-
&& $this->matchCronExpression($e[4], strftime('%w', $time));
131+
$time = $storeDateTime->setTimestamp($time);
132+
$match = $this->matchCronExpression($e[0], $time->format('i'))
133+
&& $this->matchCronExpression($e[1], $time->format('H'))
134+
&& $this->matchCronExpression($e[2], $time->format('d'))
135+
&& $this->matchCronExpression($e[3], $time->format('m'))
136+
&& $this->matchCronExpression($e[4], $time->format('w'));
125137

126138
return $match;
127139
}

0 commit comments

Comments
 (0)