Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

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:
 - magento/magento2#21921: Correct spelling (by @ravi-chandra3197)
 - magento/magento2#21919: Fix gallery full-screen triggers (by @iGerchak)
 - magento/magento2#19871: Added custom_options file upload directory to .gitignore. (by @erfanimani)
 - magento/magento2#21776: #21734 Error in JS validation rule (by @kisroman)
 - magento/magento2#21822: Refactor \Order\Shipment\AddTrack Controller to use ResultInterface (by @JeroenVanLeusden)
 - magento/magento2#21697: Root exception not logged on QuoteManagement::submitQuote (by @david-fuehr)


Fixed GitHub Issues:
 - magento/magento2#21734: Error in JS validation rule (reported by @avgust1111) has been fixed in magento/magento2#21776 by @kisroman in 2.3-develop branch
   Related commits:
     1. c8ed1e8
     2. b030da0

 - magento/magento2#14926: "Rolled back transaction has not been completed correctly" on Magento 2.2.3 (reported by @Poonika) has been fixed in magento/magento2#21697 by @david-fuehr in 2.3-develop branch
   Related commits:
     1. 9480e2a
     2. 04f60d5
     3. 6b0ebf4
     4. 59771c4

 - magento/magento2#18752: Rolled back transaction has not been completed correctly" on Magento 2.1.15 (reported by @adammprost) has been fixed in magento/magento2#21697 by @david-fuehr in 2.3-develop branch
   Related commits:
     1. 9480e2a
     2. 04f60d5
     3. 6b0ebf4
     4. 59771c4
  • Loading branch information
magento-engcom-team authored Mar 29, 2019
2 parents 08fbdf1 + 4f5aa1c commit 70bf7c6
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 96 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ atlassian*
/pub/media/import/*
!/pub/media/import/.htaccess
/pub/media/logo/*
/pub/media/custom_options/*
!/pub/media/custom_options/.htaccess
/pub/media/theme/*
/pub/media/theme_customization/*
!/pub/media/theme_customization/.htaccess
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<field id="grid_per_page_values" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page on Grid Allowed Values</label>
<comment>Comma-separated.</comment>
<validate>validate-per-page-value-list</validate>
<validate>validate-per-page-value-list required-entry</validate>
</field>
<field id="grid_per_page" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page on Grid Default Value</label>
Expand All @@ -69,7 +69,7 @@
<field id="list_per_page_values" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page on List Allowed Values</label>
<comment>Comma-separated.</comment>
<validate>validate-per-page-value-list</validate>
<validate>validate-per-page-value-list required-entry</validate>
</field>
<field id="list_per_page" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page on List Default Value</label>
Expand Down
51 changes: 38 additions & 13 deletions app/code/Magento/Quote/Model/QuoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,19 +532,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
);
$this->quoteRepository->save($quote);
} catch (\Exception $e) {
if (!empty($this->addressesToSync)) {
foreach ($this->addressesToSync as $addressId) {
$this->addressRepository->deleteById($addressId);
}
}
$this->eventManager->dispatch(
'sales_model_service_quote_submit_failure',
[
'order' => $order,
'quote' => $quote,
'exception' => $e
]
);
$this->rollbackAddresses($quote, $order, $e);
throw $e;
}
return $order;
Expand Down Expand Up @@ -611,4 +599,41 @@ protected function _prepareCustomerQuote($quote)
$shipping->setIsDefaultBilling(true);
}
}

/**
* Remove related to order and quote addresses and submit exception to further processing.
*
* @param Quote $quote
* @param \Magento\Sales\Api\Data\OrderInterface $order
* @param \Exception $e
* @throws \Exception
*/
private function rollbackAddresses(
QuoteEntity $quote,
\Magento\Sales\Api\Data\OrderInterface $order,
\Exception $e
): void {
try {
if (!empty($this->addressesToSync)) {
foreach ($this->addressesToSync as $addressId) {
$this->addressRepository->deleteById($addressId);
}
}
$this->eventManager->dispatch(
'sales_model_service_quote_submit_failure',
[
'order' => $order,
'quote' => $quote,
'exception' => $e,
]
);
} catch (\Exception $consecutiveException) {
$message = sprintf(
"An exception occurred on 'sales_model_service_quote_submit_failure' event: %s",
$consecutiveException->getMessage()
);

throw new \Exception($message, 0, $e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;

use Magento\Backend\App\Action;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Sales\Api\Data\ShipmentTrackInterfaceFactory;
use Magento\Sales\Api\ShipmentRepositoryInterface;
use Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader;

class AddTrack extends \Magento\Backend\App\Action
/**
* Add new tracking number to shipment controller.
*/
class AddTrack extends Action implements HttpPostActionInterface
{
/**
* Authorization level of a basic admin session
Expand All @@ -18,56 +31,84 @@ class AddTrack extends \Magento\Backend\App\Action
const ADMIN_RESOURCE = 'Magento_Sales::shipment';

/**
* @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader
* @var ShipmentLoader
*/
protected $shipmentLoader;

/**
* @var ShipmentRepositoryInterface
*/
private $shipmentRepository;

/**
* @var ShipmentTrackInterfaceFactory
*/
private $trackFactory;

/**
* @var SerializerInterface
*/
private $serializer;

/**
* @param Action\Context $context
* @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
* @param ShipmentLoader $shipmentLoader
* @param ShipmentRepositoryInterface|null $shipmentRepository
* @param ShipmentTrackInterfaceFactory|null $trackFactory
* @param SerializerInterface|null $serializer
*/
public function __construct(
Action\Context $context,
\Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
ShipmentLoader $shipmentLoader,
ShipmentRepositoryInterface $shipmentRepository = null,
ShipmentTrackInterfaceFactory $trackFactory = null,
SerializerInterface $serializer = null
) {
$this->shipmentLoader = $shipmentLoader;
parent::__construct($context);

$this->shipmentLoader = $shipmentLoader;
$this->shipmentRepository = $shipmentRepository ?: ObjectManager::getInstance()
->get(ShipmentRepositoryInterface::class);
$this->trackFactory = $trackFactory ?: ObjectManager::getInstance()
->get(ShipmentTrackInterfaceFactory::class);
$this->serializer = $serializer ?: ObjectManager::getInstance()
->get(SerializerInterface::class);
}

/**
* Add new tracking number action
* Add new tracking number action.
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
* @return ResultInterface
*/
public function execute()
{
try {
$carrier = $this->getRequest()->getPost('carrier');
$number = $this->getRequest()->getPost('number');
$title = $this->getRequest()->getPost('title');

if (empty($carrier)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a carrier.'));
throw new LocalizedException(__('Please specify a carrier.'));
}
if (empty($number)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a tracking number.'));
throw new LocalizedException(__('Please enter a tracking number.'));
}

$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
$this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
$this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
$shipment = $this->shipmentLoader->load();
if ($shipment) {
$track = $this->_objectManager->create(
\Magento\Sales\Model\Order\Shipment\Track::class
)->setNumber(
$track = $this->trackFactory->create()->setNumber(
$number
)->setCarrierCode(
$carrier
)->setTitle(
$title
);
$shipment->addTrack($track)->save();
$shipment->addTrack($track);
$this->shipmentRepository->save($shipment);

$this->_view->loadLayout();
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
Expand All @@ -78,16 +119,18 @@ public function execute()
'message' => __('We can\'t initialize shipment for adding tracking number.'),
];
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
} catch (LocalizedException $e) {
$response = ['error' => true, 'message' => $e->getMessage()];
} catch (\Exception $e) {
$response = ['error' => true, 'message' => __('Cannot add tracking number.')];
}
if (is_array($response)) {
$response = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($response);
$this->getResponse()->representJson($response);
} else {
$this->getResponse()->setBody($response);

if (\is_array($response)) {
$response = $this->serializer->serialize($response);

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setJsonData($response);
}

return $this->resultFactory->create(ResultFactory::TYPE_RAW)->setContents($response);
}
}
Loading

0 comments on commit 70bf7c6

Please sign in to comment.