Skip to content

Commit 9a78a3d

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 4c02757 + 3495a05 commit 9a78a3d

File tree

21 files changed

+229
-146
lines changed

21 files changed

+229
-146
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @SuppressWarnings(PHPMD.TooManyFields)
3939
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
4040
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
41+
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
4142
* @since 100.0.2
4243
*/
4344
class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
@@ -1508,6 +1509,7 @@ public function getImagesFromRow(array $rowData)
15081509
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
15091510
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
15101511
* @throws LocalizedException
1512+
* phpcs:disable Generic.Metrics.NestingLevel
15111513
*/
15121514
protected function _saveProducts()
15131515
{
@@ -2487,6 +2489,12 @@ public function validateRow(array $rowData, $rowNum)
24872489
*/
24882490
private function isNeedToValidateUrlKey($rowData)
24892491
{
2492+
if (!empty($rowData[self::COL_SKU]) && empty($rowData[self::URL_KEY])
2493+
&& $this->getBehavior() === Import::BEHAVIOR_APPEND
2494+
&& $this->isSkuExist($rowData[self::COL_SKU])) {
2495+
return false;
2496+
}
2497+
24902498
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
24912499
&& (empty($rowData[self::COL_VISIBILITY])
24922500
|| $rowData[self::COL_VISIBILITY]
@@ -2810,7 +2818,8 @@ protected function getUrlKey($rowData)
28102818
return trim(strtolower($urlKey));
28112819
}
28122820

2813-
if (!empty($rowData[self::COL_NAME])) {
2821+
if (!empty($rowData[self::COL_NAME])
2822+
&& (array_key_exists(self::URL_KEY, $rowData) || !$this->isSkuExist($rowData[self::COL_SKU]))) {
28142823
return $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
28152824
}
28162825

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,8 @@ public function execute(Observer $observer)
255255
protected function _populateForUrlGeneration($rowData)
256256
{
257257
$newSku = $this->import->getNewSku($rowData[ImportProduct::COL_SKU]);
258-
if (empty($newSku) || !isset($newSku['entity_id'])) {
259-
return null;
260-
}
261-
if ($this->import->getRowScope($rowData) == ImportProduct::SCOPE_STORE
262-
&& empty($rowData[self::URL_KEY_ATTRIBUTE_CODE])) {
258+
$oldSku = $this->import->getOldSku();
259+
if (!$this->isNeedToPopulateForUrlGeneration($rowData, $newSku, $oldSku)) {
263260
return null;
264261
}
265262
$rowData['entity_id'] = $newSku['entity_id'];
@@ -292,6 +289,27 @@ protected function _populateForUrlGeneration($rowData)
292289
return $this;
293290
}
294291

292+
/**
293+
* Check is need to populate data for url generation
294+
*
295+
* @param array $rowData
296+
* @param array $newSku
297+
* @param array $oldSku
298+
* @return bool
299+
*/
300+
private function isNeedToPopulateForUrlGeneration($rowData, $newSku, $oldSku): bool
301+
{
302+
if ((empty($newSku) || !isset($newSku['entity_id']))
303+
|| ($this->import->getRowScope($rowData) == ImportProduct::SCOPE_STORE
304+
&& empty($rowData[self::URL_KEY_ATTRIBUTE_CODE]))
305+
|| (array_key_exists($rowData[ImportProduct::COL_SKU], $oldSku)
306+
&& !isset($rowData[self::URL_KEY_ATTRIBUTE_CODE])
307+
&& $this->import->getBehavior() === ImportExport::BEHAVIOR_APPEND)) {
308+
return false;
309+
}
310+
return true;
311+
}
312+
295313
/**
296314
* Add store id to product data.
297315
*

app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private function generateChangedProductUrls(
297297
/* @var Collection $collection */
298298
$collection = $this->productCollectionFactory->create()
299299
->setStoreId($categoryStoreId)
300-
->addIdFilter($category->getAffectedProductIds())
300+
->addIdFilter($category->getChangedProductIds())
301301
->addAttributeToSelect('visibility')
302302
->addAttributeToSelect('name')
303303
->addAttributeToSelect('url_key')

app/code/Magento/SalesRule/Api/Data/CouponInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function setUsagePerCustomer($usagePerCustomer);
9999
public function getTimesUsed();
100100

101101
/**
102+
* Set time used.
103+
*
102104
* @param int $timesUsed
103105
* @return $this
104106
*/
@@ -108,6 +110,7 @@ public function setTimesUsed($timesUsed);
108110
* Get expiration date
109111
*
110112
* @return string|null
113+
* @deprecated Coupon expiration must follow sales rule expiration date.
111114
*/
112115
public function getExpirationDate();
113116

@@ -116,6 +119,7 @@ public function getExpirationDate();
116119
*
117120
* @param string $expirationDate
118121
* @return $this
122+
* @deprecated Coupon expiration must follow sales rule expiration date.
119123
*/
120124
public function setExpirationDate($expirationDate);
121125

@@ -158,6 +162,8 @@ public function setCreatedAt($createdAt);
158162
public function getType();
159163

160164
/**
165+
* Set type of coupon.
166+
*
161167
* @param int $type
162168
* @return $this
163169
*/

app/code/Magento/SalesRule/Model/Coupon.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Coupon extends \Magento\Framework\Model\AbstractExtensibleModel implements
2020
const KEY_USAGE_LIMIT = 'usage_limit';
2121
const KEY_USAGE_PER_CUSTOMER = 'usage_per_customer';
2222
const KEY_TIMES_USED = 'times_used';
23+
/**
24+
* @deprecated Coupon expiration must follow sales rule expiration date.
25+
*/
2326
const KEY_EXPIRATION_DATE = 'expiration_date';
2427
const KEY_IS_PRIMARY = 'is_primary';
2528
const KEY_CREATED_AT = 'created_at';
@@ -204,6 +207,7 @@ public function setTimesUsed($timesUsed)
204207
* Get expiration date
205208
*
206209
* @return string|null
210+
* @deprecated Coupon expiration must follow sales rule expiration date.
207211
*/
208212
public function getExpirationDate()
209213
{
@@ -215,6 +219,7 @@ public function getExpirationDate()
215219
*
216220
* @param string $expirationDate
217221
* @return $this
222+
* @deprecated Coupon expiration must follow sales rule expiration date.
218223
*/
219224
public function setExpirationDate($expirationDate)
220225
{

app/code/Magento/SalesRule/Model/Coupon/Massgenerator.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,10 @@ public function generatePool()
168168
++$attempt;
169169
} while ($this->getResource()->exists($code));
170170

171-
$expirationDate = $this->getToDate();
172-
if ($expirationDate instanceof \DateTimeInterface) {
173-
$expirationDate = $expirationDate->format('Y-m-d H:i:s');
174-
}
175-
176171
$coupon->setId(null)
177172
->setRuleId($this->getRuleId())
178173
->setUsageLimit($this->getUsesPerCoupon())
179174
->setUsagePerCustomer($this->getUsagePerCustomer())
180-
->setExpirationDate($expirationDate)
181175
->setCreatedAt($nowTimestamp)
182176
->setType(\Magento\SalesRule\Helper\Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED)
183177
->setCode($code)

app/code/Magento/SalesRule/Model/CouponRepository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public function save(\Magento\SalesRule\Api\Data\CouponInterface $coupon)
118118
__('Specified rule does not allow auto generated coupons')
119119
);
120120
}
121-
$coupon->setExpirationDate($rule->getToDate());
122121
$coupon->setUsageLimit($rule->getUsesPerCoupon());
123122
$coupon->setUsagePerCustomer($rule->getUsesPerCustomer());
124123
} catch (\Exception $e) {

app/code/Magento/SalesRule/Model/ResourceModel/Coupon.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ protected function _construct()
3434
*/
3535
public function _beforeSave(AbstractModel $object)
3636
{
37-
if (!$object->getExpirationDate()) {
38-
$object->setExpirationDate(null);
39-
} elseif ($object->getExpirationDate() instanceof \DateTimeInterface) {
40-
$object->setExpirationDate(
41-
$object->getExpirationDate()->format('Y-m-d H:i:s')
42-
);
43-
}
44-
4537
// maintain single primary coupon per rule
4638
$object->setIsPrimary($object->getIsPrimary() ? 1 : null);
4739

@@ -51,10 +43,10 @@ public function _beforeSave(AbstractModel $object)
5143
/**
5244
* Load primary coupon (is_primary = 1) for specified rule
5345
*
54-
*
5546
* @param \Magento\SalesRule\Model\Coupon $object
5647
* @param \Magento\SalesRule\Model\Rule|int $rule
5748
* @return bool
49+
* @throws \Magento\Framework\Exception\LocalizedException
5850
*/
5951
public function loadPrimaryByRule(\Magento\SalesRule\Model\Coupon $object, $rule)
6052
{
@@ -126,13 +118,6 @@ public function updateSpecificCoupons(\Magento\SalesRule\Model\Rule $rule)
126118
$updateArray['usage_per_customer'] = $rule->getUsesPerCustomer();
127119
}
128120

129-
$ruleNewDate = new \DateTime($rule->getToDate());
130-
$ruleOldDate = new \DateTime($rule->getOrigData('to_date'));
131-
132-
if ($ruleNewDate != $ruleOldDate) {
133-
$updateArray['expiration_date'] = $rule->getToDate();
134-
}
135-
136121
if (!empty($updateArray)) {
137122
$this->getConnection()->update(
138123
$this->getTable('salesrule_coupon'),

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ private function getCouponCodeSelect($couponCode)
231231

232232
$this->joinCouponTable($couponCode, $couponSelect);
233233

234-
$notExpired = $this->getConnection()->quoteInto(
235-
'(rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= ?)',
236-
$this->_date->date()->format('Y-m-d')
237-
);
238-
239234
$isAutogenerated =
240235
$this->getConnection()->quoteInto('main_table.coupon_type = ?', Rule::COUPON_TYPE_AUTO)
241236
. ' AND ' .
@@ -250,7 +245,7 @@ private function getCouponCodeSelect($couponCode)
250245
. ')';
251246

252247
$couponSelect->where(
253-
"$notExpired AND ($isAutogenerated OR $isValidSpecific)",
248+
"$isAutogenerated OR $isValidSpecific",
254249
null,
255250
Select::TYPE_CONDITION
256251
);

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ public function afterSave()
296296
$this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null
297297
)->setUsagePerCustomer(
298298
$this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null
299-
)->setExpirationDate(
300-
$this->getToDate()
301299
)->save();
302300
} else {
303301
$this->getPrimaryCoupon()->delete();
@@ -498,8 +496,6 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10)
498496
$this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null
499497
)->setUsagePerCustomer(
500498
$this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null
501-
)->setExpirationDate(
502-
$this->getToDate()
503499
)->setType(
504500
\Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
505501
);

0 commit comments

Comments
 (0)