Skip to content

Commit bcbe680

Browse files
committed
1.59.3 (FINAL RELEASE)
1 parent 54b1c41 commit bcbe680

File tree

12 files changed

+115
-99
lines changed

12 files changed

+115
-99
lines changed

Model/Amazon/Connector/Product/Revise/Responser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected function processSuccessReviseQty()
181181
/** @var \Ess\M2ePro\Model\Amazon\Listing\Product $amazonListingProduct */
182182
$amazonListingProduct = $this->listingProduct->getChildObject();
183183

184-
$handlingTimeFrom = $amazonListingProduct->getOrigData('online_handling_time');
184+
$handlingTimeFrom = (int)$amazonListingProduct->getOrigData('online_handling_time');
185185
$handlingTimeTo = $amazonListingProduct->getOnlineHandlingTime();
186186

187187
if ($handlingTimeFrom != $handlingTimeTo) {

Model/Amazon/Listing/Product.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,7 @@ public function isVariationParentRepricingStateYes()
774774

775775
// ---------------------------------------
776776

777-
/**
778-
* @return int
779-
*/
780-
public function getOnlineHandlingTime()
777+
public function getOnlineHandlingTime(): int
781778
{
782779
return (int)$this->getData('online_handling_time');
783780
}

Model/Amazon/Listing/Product/Action/DataBuilder/Qty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getBuilderData()
5151
$this->cachedData['restock_date'] = $restockDate;
5252
}
5353

54-
if (!empty($this->cachedData['handling_time'])) {
54+
if (isset($this->cachedData['handling_time'])) {
5555
$data['handling_time'] = $this->cachedData['handling_time'];
5656
}
5757

Model/Amazon/Listing/Source.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
<?php
22

3-
/**
4-
* @author M2E Pro Developers Team
5-
* @copyright M2E LTD
6-
* @license Commercial use is forbidden
7-
*/
8-
93
namespace Ess\M2ePro\Model\Amazon\Listing;
104

11-
use Ess\M2ePro\Model\Amazon\Listing;
12-
use Ess\M2ePro\Model\Magento\Product\Image;
13-
14-
/**
15-
* Class \Ess\M2ePro\Model\Amazon\Listing\Source
16-
*/
175
class Source extends \Ess\M2ePro\Model\AbstractModel
186
{
197
/**
@@ -132,10 +120,7 @@ protected function applySkuModification($sku)
132120

133121
//########################################
134122

135-
/**
136-
* @return int|string
137-
*/
138-
public function getHandlingTime()
123+
public function getHandlingTime(): int
139124
{
140125
$result = 0;
141126
$src = $this->getAmazonListing()->getHandlingTimeSource();
@@ -149,8 +134,14 @@ public function getHandlingTime()
149134
}
150135

151136
$result = (int)$result;
152-
$result < 0 && $result = 0;
153-
$result > 30 && $result = 30;
137+
138+
if ($result <= 0) {
139+
return 0;
140+
}
141+
142+
if ($result >= 30) {
143+
return 30;
144+
}
154145

155146
return $result;
156147
}

Model/Magento/Product.php

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Product extends \Ess\M2ePro\Model\AbstractModel
4444
* )
4545
*/
4646

47-
/** @var array */
47+
/** @var array */
4848
public static $statistics = [];
4949

5050
protected $inventoryFactory;
@@ -102,8 +102,11 @@ class Product extends \Ess\M2ePro\Model\AbstractModel
102102

103103
/** @var \Magento\Catalog\Api\ProductRepositoryInterface */
104104
private $productRepository;
105+
/** @var \Ess\M2ePro\Model\Magento\Product\ImageFactory */
106+
private $imageFactory;
105107

106108
public function __construct(
109+
\Ess\M2ePro\Model\Magento\Product\ImageFactory $imageFactory,
107110
Factory $inventoryFactory,
108111
\Magento\Framework\Filesystem\DriverPool $driverPool,
109112
\Magento\Framework\App\ResourceConnection $resourceModel,
@@ -145,6 +148,7 @@ public function __construct(
145148
$this->moduleConfiguration = $moduleConfiguration;
146149
$this->m2eProductFactory = $m2eProductFactory;
147150
$this->productRepository = $productRepository;
151+
$this->imageFactory = $imageFactory;
148152

149153
parent::__construct($helperFactory, $modelFactory);
150154
}
@@ -1498,11 +1502,11 @@ public function getThumbnailImage()
14981502
return null;
14991503
}
15001504

1501-
$thumbnailTempPath = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)
1502-
->getAbsolutePath() . 'catalog/product/' . ltrim($thumbnailTempPath, '/');
1505+
$thumbnailTempPath = $this->filesystem
1506+
->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)
1507+
->getAbsolutePath() . 'catalog/product/' . ltrim($thumbnailTempPath, '/');
15031508

1504-
/** @var Image $image */
1505-
$image = $this->modelFactory->getObject('Magento_Product_Image');
1509+
$image = $this->imageFactory->create();
15061510
$image->setPath($thumbnailTempPath);
15071511
$image->setArea(\Magento\Framework\App\Area::AREA_ADMINHTML);
15081512
$image->setStoreId($this->getStoreId());
@@ -1580,8 +1584,7 @@ public function getImage($attribute = 'image')
15801584
return null;
15811585
}
15821586

1583-
/** @var Image $image */
1584-
$image = $this->modelFactory->getObject('Magento_Product_Image');
1587+
$image = $this->imageFactory->create();
15851588
$image->setUrl($imageUrl);
15861589
$image->setStoreId($this->getStoreId());
15871590

@@ -1601,50 +1604,39 @@ public function getGalleryImages($limitImages = 0)
16011604
return [];
16021605
}
16031606

1604-
$galleryImages = $this->getProduct()->getData('media_gallery');
1607+
$galleryImages = $this->getProduct()->getMediaGalleryEntries();
16051608

1606-
if (!isset($galleryImages['images']) || !is_array($galleryImages['images'])) {
1609+
if (empty($galleryImages)) {
16071610
return [];
16081611
}
16091612

16101613
$i = 0;
16111614
$images = [];
16121615

1613-
foreach ($galleryImages['images'] as $galleryImage) {
1616+
foreach ($galleryImages as $galleryImage) {
16141617
if ($i >= $limitImages) {
16151618
break;
16161619
}
16171620

1618-
if (isset($galleryImage['disabled']) && (bool)$galleryImage['disabled']) {
1619-
continue;
1620-
}
1621-
1622-
if (!isset($galleryImage['file'])) {
1623-
continue;
1624-
}
1625-
1626-
if (
1627-
isset($galleryImage['media_type']) &&
1628-
$galleryImage['media_type'] === ExternalVideoEntryConverter::MEDIA_TYPE_CODE
1629-
) {
1621+
if ($this->isNeedSkipGalleryImage($galleryImage)) {
16301622
continue;
16311623
}
16321624

1633-
$imageUrl = $this->storeFactory->create()
1634-
->load($this->getStoreId())
1635-
->getBaseUrl(
1636-
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA,
1637-
$this->moduleConfiguration->getSecureImageUrlInItemDescriptionMode()
1638-
);
1639-
$imageUrl .= 'catalog/product/' . ltrim($galleryImage['file'], '/');
1625+
$imageUrl = $this->storeFactory
1626+
->create()
1627+
->load($this->getStoreId())
1628+
->getBaseUrl(
1629+
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA,
1630+
$this->moduleConfiguration->getSecureImageUrlInItemDescriptionMode()
1631+
);
1632+
$imageUrl .= 'catalog/product/' . ltrim($galleryImage->getFile(), '/');
16401633
$imageUrl = $this->prepareImageUrl($imageUrl);
16411634

16421635
if (empty($imageUrl)) {
16431636
continue;
16441637
}
16451638

1646-
/** @var Image $image */
1647-
$image = $this->modelFactory->getObject('Magento_Product_Image');
1639+
$image = $this->imageFactory->create();
16481640
$image->setUrl($imageUrl);
16491641
$image->setStoreId($this->getStoreId());
16501642

@@ -1703,8 +1695,7 @@ public function getGalleryImageByPosition($position = 1)
17031695

17041696
$imageUrl = $this->prepareImageUrl($imageUrl);
17051697

1706-
/** @var Image $image */
1707-
$image = $this->modelFactory->getObject('Magento_Product_Image');
1698+
$image = $this->imageFactory->create();
17081699
$image->setUrl($imageUrl);
17091700
$image->setStoreId($this->getStoreId());
17101701

@@ -1795,5 +1786,35 @@ public function clearNotFoundAttributes()
17951786
$this->notFoundAttributes = [];
17961787
}
17971788

1798-
//########################################
1789+
// ----------------------------------------
1790+
1791+
private function isNeedSkipGalleryImage(
1792+
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $galleryImage
1793+
): bool {
1794+
if ($galleryImage->isDisabled()) {
1795+
return true;
1796+
}
1797+
1798+
if (empty($galleryImage->getFile())) {
1799+
return true;
1800+
}
1801+
1802+
if ($galleryImage->getMediaType() === ExternalVideoEntryConverter::MEDIA_TYPE_CODE) {
1803+
return true;
1804+
}
1805+
1806+
if (in_array('image', $galleryImage->getTypes())) {
1807+
return false;
1808+
}
1809+
1810+
if (in_array('small_image', $galleryImage->getTypes())) {
1811+
return true;
1812+
}
1813+
1814+
if (in_array('thumbnail', $galleryImage->getTypes())) {
1815+
return true;
1816+
}
1817+
1818+
return false;
1819+
}
17991820
}

Model/Magento/Product/Image.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
<?php
22

3-
/**
4-
* @author M2E Pro Developers Team
5-
* @copyright M2E LTD
6-
* @license Commercial use is forbidden
7-
*/
8-
93
namespace Ess\M2ePro\Model\Magento\Product;
104

115
use Ess\M2ePro\Model\AbstractModel;
126
use Magento\Framework\App\Area;
137

14-
/**
15-
* Class \Ess\M2ePro\Model\Magento\Product\Image
16-
*/
178
class Image extends AbstractModel
189
{
1910
protected $driverPool;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ess\M2ePro\Model\Magento\Product;
6+
7+
class ImageFactory
8+
{
9+
/** @var \Magento\Framework\ObjectManagerInterface */
10+
private $objectManager;
11+
12+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
13+
{
14+
$this->objectManager = $objectManager;
15+
}
16+
17+
public function create(): Image
18+
{
19+
return $this->objectManager->create(Image::class);
20+
}
21+
}

Model/ResourceModel/MSI/Magento/Product/Collection.php

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
<?php
22

3-
/**
4-
* @author M2E Pro Developers Team
5-
* @copyright M2E LTD
6-
* @license Commercial use is forbidden
7-
*/
8-
93
namespace Ess\M2ePro\Model\ResourceModel\MSI\Magento\Product;
104

11-
use Magento\InventoryReservationsApi\Model\ReservationInterface;
125
use Magento\InventorySalesApi\Model\StockByWebsiteIdResolverInterface;
136
use Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface;
147
use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface;
158

16-
/**
17-
* Class \Ess\M2ePro\Model\ResourceModel\MSI\Magento\Product\Collection
18-
*/
199
class Collection extends \Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection
2010
{
11+
/** @var \Ess\M2ePro\Helper\Magento\Stock */
12+
private $stockHelper;
2113
/** @var StockIndexTableNameResolverInterface */
22-
protected $indexNameResolver;
23-
14+
private $indexNameResolver;
2415
/** @var StockByWebsiteIdResolverInterface */
25-
protected $stockResolver;
26-
16+
private $stockResolver;
2717
/** @var DefaultStockProviderInterface */
28-
protected $defaultStockResolver;
29-
30-
//########################################
18+
private $defaultStockResolver;
3119

3220
public function __construct(
21+
\Ess\M2ePro\Helper\Magento\Stock $stockHelper,
3322
\Ess\M2ePro\Helper\Factory $helperFactory,
3423
\Ess\M2ePro\Model\Factory $modelFactory,
3524
\Ess\M2ePro\Model\ActiveRecord\Factory $activeRecordFactory,
@@ -82,13 +71,12 @@ public function __construct(
8271
$connection
8372
);
8473

74+
$this->stockHelper = $stockHelper;
8575
$this->indexNameResolver = $objectManager->get(StockIndexTableNameResolverInterface::class);
8676
$this->stockResolver = $objectManager->get(StockByWebsiteIdResolverInterface::class);
8777
$this->defaultStockResolver = $objectManager->get(DefaultStockProviderInterface::class);
8878
}
8979

90-
//########################################
91-
9280
public function joinStockItem()
9381
{
9482
$website = $this->getStoreId() === \Magento\Store\Model\Store::DEFAULT_STORE_ID
@@ -114,7 +102,10 @@ public function joinStockItem()
114102
'def_quantity' => 'quantity',
115103
'def_is_in_stock' => 'is_salable',
116104
],
117-
null,
105+
[
106+
'stock_id' => $this->stockHelper->getStockId($this->getStoreId()),
107+
'website_id' => $this->stockHelper->getWebsiteId($this->getStoreId()),
108+
],
118109
'left'
119110
);
120111

@@ -124,8 +115,6 @@ public function joinStockItem()
124115
]);
125116
}
126117

127-
//########################################
128-
129118
public function getCheckSqlForQty()
130119
{
131120
return $this->getConnection()->getCheckSql(
@@ -135,8 +124,6 @@ public function getCheckSqlForQty()
135124
);
136125
}
137126

138-
//########################################
139-
140127
public function getCheckSqlForStock()
141128
{
142129
return $this->getConnection()->getCheckSql(
@@ -146,8 +133,6 @@ public function getCheckSqlForStock()
146133
);
147134
}
148135

149-
//########################################
150-
151136
public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner')
152137
{
153138
if ($attribute == 'is_in_stock') {
@@ -171,8 +156,6 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType =
171156
return parent::addAttributeToFilter($attribute, $condition, $joinType);
172157
}
173158

174-
//########################################
175-
176159
public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
177160
{
178161
if ($attribute == 'qty') {
@@ -181,6 +164,4 @@ public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
181164

182165
return parent::addAttributeToSort($attribute, $dir);
183166
}
184-
185-
//########################################
186167
}

0 commit comments

Comments
 (0)