Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.3-develop Minor Fixes
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #21778: Multishipping checkout agreements now are the same as default checkout agreements (by @samuel27m)
 - #20774: 20434 consider url rewrite when change product visibility attribute 2 3 (by @VitaliyBoyko)
 - #21283: Fixed calculation of 'Total' column under "Last Orders" listing on the admin dashboard (by @rav-redchamps)
 - #19727: Use repository to load order when manually creating an invoice (by @JeroenVanLeusden)
 - #20212: Secure errors directory (by @schmengler)
 - #21899: Trigger contentUpdate on reviews load (by @jahvi)
 - #21621: Updated review text in admin menu (by @gelanivishal)
 - #21880: #21001 - fix unit tests, by passing currency to numbe� (by @kdegorski)
 - #21825: When setting `background` for labels explicitly the labels in admin will (by @TomashKhamlai)


Fixed GitHub Issues:
 - #20434: Product URL duplicate when changing visibility via mass action (reported by @laurentplenet) has been fixed in #20774 by @VitaliyBoyko in 2.3-develop branch
   Related commits:
     1. 24382e3
     2. 4d18c9a
     3. 6a5776c
     4. f2088d9
     5. 4edec38
     6. a8d1dc0
     7. 5687704
     8. c865bdc
     9. 1c608d7
     10. a80943f
     11. a8d9be1

 - #18754: Negative order amount in dashboard latest order when order is cancelled where coupon has been used (reported by @albsa) has been fixed in #21283 by @rav-redchamps in 2.3-develop branch
   Related commits:
     1. d79eb08
     2. d1e71b9
     3. f893a92
     4. 57c4db4

 - #21281: Wrong order amount on dashboard on Last orders listing when order has discount and it is partially refunded (reported by @rav-redchamps) has been fixed in #21283 by @rav-redchamps in 2.3-develop branch
   Related commits:
     1. d79eb08
     2. d1e71b9
     3. f893a92
     4. 57c4db4

 - #20209: errors/local.xml and error page templates are publicly accessible (reported by @schmengler) has been fixed in #20212 by @schmengler in 2.3-develop branch
   Related commits:
     1. a0566ab

 - #21620: Update title of Review content (reported by @sanganinamrata) has been fixed in #21621 by @gelanivishal in 2.3-develop branch
   Related commits:
     1. ae9084d
     2. b622401
     3. 417fda4
     4. 44ddbab

 - #21001: Unit Tests failed (reported by @azngeek) has been fixed in #21880 by @kdegorski in 2.3-develop branch
   Related commits:
     1. b96435f
     2. 8d7b964
     3. 3825545
  • Loading branch information
magento-engcom-team authored Mar 26, 2019
2 parents 0d881fc + 637a6af commit 4f6c78e
Show file tree
Hide file tree
Showing 23 changed files with 635 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Model\Products;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

/**
* Save/Delete UrlRewrites by Product ID's and visibility
*/
class AdaptUrlRewritesToVisibilityAttribute
{
/**
* @var CollectionFactory
*/
private $productCollectionFactory;

/**
* @var ProductUrlRewriteGenerator
*/
private $urlRewriteGenerator;

/**
* @var UrlPersistInterface
*/
private $urlPersist;

/**
* @var ProductUrlPathGenerator
*/
private $urlPathGenerator;

/**
* @param CollectionFactory $collectionFactory
* @param ProductUrlRewriteGenerator $urlRewriteGenerator
* @param UrlPersistInterface $urlPersist
* @param ProductUrlPathGenerator|null $urlPathGenerator
*/
public function __construct(
CollectionFactory $collectionFactory,
ProductUrlRewriteGenerator $urlRewriteGenerator,
UrlPersistInterface $urlPersist,
ProductUrlPathGenerator $urlPathGenerator
) {
$this->productCollectionFactory = $collectionFactory;
$this->urlRewriteGenerator = $urlRewriteGenerator;
$this->urlPersist = $urlPersist;
$this->urlPathGenerator = $urlPathGenerator;
}

/**
* Process Url Rewrites according to the products visibility attribute
*
* @param array $productIds
* @param int $visibility
* @throws UrlAlreadyExistsException
*/
public function execute(array $productIds, int $visibility): void
{
$products = $this->getProductsByIds($productIds);

/** @var Product $product */
foreach ($products as $product) {
if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) {
$this->urlPersist->deleteByData(
[
UrlRewrite::ENTITY_ID => $product->getId(),
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
]
);
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {
$product->setVisibility($visibility);
$productUrlPath = $this->urlPathGenerator->getUrlPath($product);
$productUrlRewrite = $this->urlRewriteGenerator->generate($product);
$product->unsUrlPath();
$product->setUrlPath($productUrlPath);

try {
$this->urlPersist->replace($productUrlRewrite);
} catch (UrlAlreadyExistsException $e) {
throw new UrlAlreadyExistsException(
__(
'Can not change the visibility of the product with SKU equals "%1". '
. 'URL key "%2" for specified store already exists.',
$product->getSku(),
$product->getUrlKey()
),
$e,
$e->getCode(),
$e->getUrls()
);
}
}
}
}

/**
* Get Product Models by Id's
*
* @param array $productIds
* @return array
*/
private function getProductsByIds(array $productIds): array
{
$productCollection = $this->productCollectionFactory->create();
$productCollection->addAttributeToSelect(ProductInterface::VISIBILITY);
$productCollection->addAttributeToSelect('url_key');
$productCollection->addFieldToFilter(
'entity_id',
['in' => array_unique($productIds)]
);

return $productCollection->getItems();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Observer;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;

/**
* Consider URL rewrites on change product visibility via mass action
*/
class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface
{
/**
* @var AdaptUrlRewritesToVisibilityAttribute
*/
private $adaptUrlRewritesToVisibility;

/**
* @param AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility
*/
public function __construct(AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility)
{
$this->adaptUrlRewritesToVisibility = $adaptUrlRewritesToVisibility;
}

/**
* Generate urls for UrlRewrites and save it in storage
*
* @param Observer $observer
* @return void
* @throws UrlAlreadyExistsException
*/
public function execute(Observer $observer)
{
$event = $observer->getEvent();
$attrData = $event->getAttributesData();
$productIds = $event->getProductIds();
$visibility = $attrData[ProductInterface::VISIBILITY] ?? 0;

if (!$visibility || !$productIds) {
return;
}

$this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility);
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<event name="catalog_product_save_after">
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver"/>
</event>
<event name="catalog_product_attribute_update_before">
<observer name="process_url_rewrite_on_change_product_visibility" instance="Magento\CatalogUrlRewrite\Observer\ProcessUrlRewriteOnChangeProductVisibilityObserver"/>
</event>
<event name="catalog_category_save_before">
<observer name="category_url_path_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver"/>
</event>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout_overview">
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::multishipping_agreements.phtml"/>
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See COPYING.txt for license details.
*/

// @deprecated
// @codingStandardsIgnoreFile

?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define([
opacity: 0.5, // CSS opacity for the 'Place Order' button when it's clicked and then disabled.
pleaseWaitLoader: 'span.please-wait', // 'Submitting order information...' Ajax loader.
placeOrderSubmit: 'button[type="submit"]', // The 'Place Order' button.
agreements: '#checkout-agreements' // Container for all of the checkout agreements and terms/conditions
agreements: '.checkout-agreements' // Container for all of the checkout agreements and terms/conditions
},

/**
Expand Down
46 changes: 40 additions & 6 deletions app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,12 @@ public function addOrdersCount()
*/
public function addRevenueToSelect($convertCurrency = false)
{
$expr = $this->getTotalsExpression(
$expr = $this->getTotalsExpressionWithDiscountRefunded(
!$convertCurrency,
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
);
$this->getSelect()->columns(['revenue' => $expr]);

Expand All @@ -791,11 +792,12 @@ public function addSumAvgTotals($storeId = 0)
/**
* calculate average and total amount
*/
$expr = $this->getTotalsExpression(
$expr = $this->getTotalsExpressionWithDiscountRefunded(
$storeId,
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
);

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

/**
* Get SQL expression for totals
* Get SQL expression for totals.
*
* @param int $storeId
* @param string $baseSubtotalRefunded
* @param string $baseSubtotalCanceled
* @param string $baseDiscountCanceled
* @return string
* @deprecated
* @see getTotalsExpressionWithDiscountRefunded
*/
protected function getTotalsExpression(
$storeId,
Expand All @@ -825,10 +829,40 @@ protected function getTotalsExpression(
$template = ($storeId != 0)
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)'
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
. ' * main_table.base_to_global_rate)';
. ' * main_table.base_to_global_rate)';
return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled);
}

/**
* Get SQL expression for totals with discount refunded.
*
* @param int $storeId
* @param string $baseSubtotalRefunded
* @param string $baseSubtotalCanceled
* @param string $baseDiscountRefunded
* @param string $baseDiscountCanceled
* @return string
*/
private function getTotalsExpressionWithDiscountRefunded(
$storeId,
$baseSubtotalRefunded,
$baseSubtotalCanceled,
$baseDiscountRefunded,
$baseDiscountCanceled
) {
$template = ($storeId != 0)
? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))'
: '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
. ' * main_table.base_to_global_rate)';
return sprintf(
$template,
$baseSubtotalRefunded,
$baseSubtotalCanceled,
$baseDiscountRefunded,
$baseDiscountCanceled
);
}

/**
* Sort order by total amount
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Review/etc/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</resource>
<resource id="Magento_Backend::marketing">
<resource id="Magento_Backend::marketing_user_content">
<resource id="Magento_Review::reviews_all" title="Reviews" translate="title" sortOrder="10"/>
<resource id="Magento_Review::pending" title="Pending Reviews" translate="title" sortOrder="20"/>
<resource id="Magento_Review::reviews_all" title="All Reviews" translate="title" sortOrder="10"/>
</resource>
</resource>
</resource>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Review/etc/adminhtml/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Magento_Review::catalog_reviews_ratings_ratings" title="Rating" translate="title" module="Magento_Review" sortOrder="60" parent="Magento_Backend::stores_attributes" action="review/rating/" resource="Magento_Review::ratings"/>
<add id="Magento_Review::catalog_reviews_ratings_reviews_all" title="Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="10" action="review/product/index" resource="Magento_Review::reviews_all"/>
<add id="Magento_Review::catalog_reviews_ratings_pending" title="Pending Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="20" action="review/product/pending" resource="Magento_Review::pending"/>
<add id="Magento_Review::catalog_reviews_ratings_reviews_all" title="All Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="10" action="review/product/index" resource="Magento_Review::reviews_all"/>
<add id="Magento_Review::report_review" title="Reviews" translate="title" module="Magento_Reports" sortOrder="20" parent="Magento_Reports::report" resource="Magento_Reports::review"/>
<add id="Magento_Review::report_review_customer" title="By Customers" translate="title" sortOrder="10" module="Magento_Review" parent="Magento_Review::report_review" action="reports/report_review/customer" resource="Magento_Reports::review_customer"/>
<add id="Magento_Review::report_review_product" title="By Products" translate="title" sortOrder="20" module="Magento_Review" parent="Magento_Review::report_review" action="reports/report_review/product" resource="Magento_Reports::review_product"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ define([
showLoader: false,
loaderContext: $('.product.data.items')
}).done(function (data) {
$('#product-review-container').html(data);
$('#product-review-container').html(data).trigger('contentUpdated');
$('[data-role="product-review"] .pages a').each(function (index, element) {
$(element).click(function (event) { //eslint-disable-line max-nested-callbacks
processReviews($(element).attr('href'), true);
Expand Down
Loading

0 comments on commit 4f6c78e

Please sign in to comment.