Skip to content

Commit 1ab6acd

Browse files
committed
Merge branch 'github-2.3-develop' into MAGETWO-98584
2 parents bba4a24 + 212a533 commit 1ab6acd

File tree

62 files changed

+1920
-658
lines changed

Some content is hidden

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

62 files changed

+1920
-658
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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\CatalogUrlRewrite\Model\Products;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
14+
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
15+
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
16+
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
17+
use Magento\UrlRewrite\Model\UrlPersistInterface;
18+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
19+
20+
/**
21+
* Save/Delete UrlRewrites by Product ID's and visibility
22+
*/
23+
class AdaptUrlRewritesToVisibilityAttribute
24+
{
25+
/**
26+
* @var CollectionFactory
27+
*/
28+
private $productCollectionFactory;
29+
30+
/**
31+
* @var ProductUrlRewriteGenerator
32+
*/
33+
private $urlRewriteGenerator;
34+
35+
/**
36+
* @var UrlPersistInterface
37+
*/
38+
private $urlPersist;
39+
40+
/**
41+
* @var ProductUrlPathGenerator
42+
*/
43+
private $urlPathGenerator;
44+
45+
/**
46+
* @param CollectionFactory $collectionFactory
47+
* @param ProductUrlRewriteGenerator $urlRewriteGenerator
48+
* @param UrlPersistInterface $urlPersist
49+
* @param ProductUrlPathGenerator|null $urlPathGenerator
50+
*/
51+
public function __construct(
52+
CollectionFactory $collectionFactory,
53+
ProductUrlRewriteGenerator $urlRewriteGenerator,
54+
UrlPersistInterface $urlPersist,
55+
ProductUrlPathGenerator $urlPathGenerator
56+
) {
57+
$this->productCollectionFactory = $collectionFactory;
58+
$this->urlRewriteGenerator = $urlRewriteGenerator;
59+
$this->urlPersist = $urlPersist;
60+
$this->urlPathGenerator = $urlPathGenerator;
61+
}
62+
63+
/**
64+
* Process Url Rewrites according to the products visibility attribute
65+
*
66+
* @param array $productIds
67+
* @param int $visibility
68+
* @throws UrlAlreadyExistsException
69+
*/
70+
public function execute(array $productIds, int $visibility): void
71+
{
72+
$products = $this->getProductsByIds($productIds);
73+
74+
/** @var Product $product */
75+
foreach ($products as $product) {
76+
if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) {
77+
$this->urlPersist->deleteByData(
78+
[
79+
UrlRewrite::ENTITY_ID => $product->getId(),
80+
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
81+
]
82+
);
83+
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {
84+
$product->setVisibility($visibility);
85+
$productUrlPath = $this->urlPathGenerator->getUrlPath($product);
86+
$productUrlRewrite = $this->urlRewriteGenerator->generate($product);
87+
$product->unsUrlPath();
88+
$product->setUrlPath($productUrlPath);
89+
90+
try {
91+
$this->urlPersist->replace($productUrlRewrite);
92+
} catch (UrlAlreadyExistsException $e) {
93+
throw new UrlAlreadyExistsException(
94+
__(
95+
'Can not change the visibility of the product with SKU equals "%1". '
96+
. 'URL key "%2" for specified store already exists.',
97+
$product->getSku(),
98+
$product->getUrlKey()
99+
),
100+
$e,
101+
$e->getCode(),
102+
$e->getUrls()
103+
);
104+
}
105+
}
106+
}
107+
}
108+
109+
/**
110+
* Get Product Models by Id's
111+
*
112+
* @param array $productIds
113+
* @return array
114+
*/
115+
private function getProductsByIds(array $productIds): array
116+
{
117+
$productCollection = $this->productCollectionFactory->create();
118+
$productCollection->addAttributeToSelect(ProductInterface::VISIBILITY);
119+
$productCollection->addAttributeToSelect('url_key');
120+
$productCollection->addFieldToFilter(
121+
'entity_id',
122+
['in' => array_unique($productIds)]
123+
);
124+
125+
return $productCollection->getItems();
126+
}
127+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\CatalogUrlRewrite\Observer;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\Event\ObserverInterface;
14+
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
15+
16+
/**
17+
* Consider URL rewrites on change product visibility via mass action
18+
*/
19+
class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface
20+
{
21+
/**
22+
* @var AdaptUrlRewritesToVisibilityAttribute
23+
*/
24+
private $adaptUrlRewritesToVisibility;
25+
26+
/**
27+
* @param AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility
28+
*/
29+
public function __construct(AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility)
30+
{
31+
$this->adaptUrlRewritesToVisibility = $adaptUrlRewritesToVisibility;
32+
}
33+
34+
/**
35+
* Generate urls for UrlRewrites and save it in storage
36+
*
37+
* @param Observer $observer
38+
* @return void
39+
* @throws UrlAlreadyExistsException
40+
*/
41+
public function execute(Observer $observer)
42+
{
43+
$event = $observer->getEvent();
44+
$attrData = $event->getAttributesData();
45+
$productIds = $event->getProductIds();
46+
$visibility = $attrData[ProductInterface::VISIBILITY] ?? 0;
47+
48+
if (!$visibility || !$productIds) {
49+
return;
50+
}
51+
52+
$this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility);
53+
}
54+
}

app/code/Magento/CatalogUrlRewrite/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<event name="catalog_product_save_after">
2828
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver"/>
2929
</event>
30+
<event name="catalog_product_attribute_update_before">
31+
<observer name="process_url_rewrite_on_change_product_visibility" instance="Magento\CatalogUrlRewrite\Observer\ProcessUrlRewriteOnChangeProductVisibilityObserver"/>
32+
</event>
3033
<event name="catalog_category_save_before">
3134
<observer name="category_url_path_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver"/>
3235
</event>

app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceBlock name="checkout_overview">
11-
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::multishipping_agreements.phtml"/>
11+
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/>
1212
</referenceBlock>
1313
</body>
1414
</page>

app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
// @deprecated
78
// @codingStandardsIgnoreFile
89

910
?>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ type Query {
1010
type Currency {
1111
base_currency_code: String
1212
base_currency_symbol: String
13-
default_display_currecy_code: String
14-
default_display_currecy_symbol: String
13+
default_display_currecy_code: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_code`.")
14+
default_display_currency_code: String
15+
default_display_currecy_symbol: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_symbol`.")
16+
default_display_currency_symbol: String
1517
available_currency_codes: [String]
1618
exchange_rates: [ExchangeRate]
1719
}

app/code/Magento/Multishipping/view/frontend/web/js/overview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define([
1515
opacity: 0.5, // CSS opacity for the 'Place Order' button when it's clicked and then disabled.
1616
pleaseWaitLoader: 'span.please-wait', // 'Submitting order information...' Ajax loader.
1717
placeOrderSubmit: 'button[type="submit"]', // The 'Place Order' button.
18-
agreements: '#checkout-agreements' // Container for all of the checkout agreements and terms/conditions
18+
agreements: '.checkout-agreements' // Container for all of the checkout agreements and terms/conditions
1919
},
2020

2121
/**

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public function execute(Quote $cart, array $cartItemData): void
6767
{
6868
$sku = $this->extractSku($cartItemData);
6969
$qty = $this->extractQty($cartItemData);
70+
if ($qty <= 0) {
71+
throw new GraphQlInputException(
72+
__('Please enter a number greater than 0 in this field.')
73+
);
74+
}
7075
$customizableOptions = $this->extractCustomizableOptions($cartItemData);
7176

7277
try {

app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public function __construct(
6060
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6161
{
6262
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
63-
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
63+
throw new GraphQlInputException(__('Required parameter "cart_id" is missing.'));
6464
}
6565
$maskedCartId = $args['input']['cart_id'];
6666

6767
if (!isset($args['input']['payment_method']['code']) || empty($args['input']['payment_method']['code'])) {
68-
throw new GraphQlInputException(__('Required parameter "payment_method" is missing'));
68+
throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.'));
6969
}
7070
$paymentMethodCode = $args['input']['payment_method']['code'];
7171

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,12 @@ public function addOrdersCount()
769769
*/
770770
public function addRevenueToSelect($convertCurrency = false)
771771
{
772-
$expr = $this->getTotalsExpression(
772+
$expr = $this->getTotalsExpressionWithDiscountRefunded(
773773
!$convertCurrency,
774774
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
775775
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
776-
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
776+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
777+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
777778
);
778779
$this->getSelect()->columns(['revenue' => $expr]);
779780

@@ -791,11 +792,12 @@ public function addSumAvgTotals($storeId = 0)
791792
/**
792793
* calculate average and total amount
793794
*/
794-
$expr = $this->getTotalsExpression(
795+
$expr = $this->getTotalsExpressionWithDiscountRefunded(
795796
$storeId,
796797
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
797798
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
798-
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
799+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
800+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
799801
);
800802

801803
$this->getSelect()->columns(
@@ -808,13 +810,15 @@ public function addSumAvgTotals($storeId = 0)
808810
}
809811

810812
/**
811-
* Get SQL expression for totals
813+
* Get SQL expression for totals.
812814
*
813815
* @param int $storeId
814816
* @param string $baseSubtotalRefunded
815817
* @param string $baseSubtotalCanceled
816818
* @param string $baseDiscountCanceled
817819
* @return string
820+
* @deprecated
821+
* @see getTotalsExpressionWithDiscountRefunded
818822
*/
819823
protected function getTotalsExpression(
820824
$storeId,
@@ -825,10 +829,40 @@ protected function getTotalsExpression(
825829
$template = ($storeId != 0)
826830
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)'
827831
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
828-
. ' * main_table.base_to_global_rate)';
832+
. ' * main_table.base_to_global_rate)';
829833
return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled);
830834
}
831835

836+
/**
837+
* Get SQL expression for totals with discount refunded.
838+
*
839+
* @param int $storeId
840+
* @param string $baseSubtotalRefunded
841+
* @param string $baseSubtotalCanceled
842+
* @param string $baseDiscountRefunded
843+
* @param string $baseDiscountCanceled
844+
* @return string
845+
*/
846+
private function getTotalsExpressionWithDiscountRefunded(
847+
$storeId,
848+
$baseSubtotalRefunded,
849+
$baseSubtotalCanceled,
850+
$baseDiscountRefunded,
851+
$baseDiscountCanceled
852+
) {
853+
$template = ($storeId != 0)
854+
? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))'
855+
: '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
856+
. ' * main_table.base_to_global_rate)';
857+
return sprintf(
858+
$template,
859+
$baseSubtotalRefunded,
860+
$baseSubtotalCanceled,
861+
$baseDiscountRefunded,
862+
$baseDiscountCanceled
863+
);
864+
}
865+
832866
/**
833867
* Sort order by total amount
834868
*

0 commit comments

Comments
 (0)