Skip to content

Commit

Permalink
Session quote fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brunogemelli committed Aug 6, 2018
1 parent 5da752a commit 2b78e0f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Cron/Queue/Sales/Order/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function executeIntegration(Schedule $schedule, StoreInterface $store)
$skyhubCode = $this->arrayExtract($orderData, 'code');


/** @var \Magento\Sales\Api\Data\OrderInterface $order */
/** @var \Magento\Sales\Api\Data\OrderInterface $order */
$order = $orderProcessor->createOrder($orderData);
if (!$order || !$order->getEntityId()) {
$message = $schedule->getMessages();
Expand Down
1 change: 1 addition & 0 deletions Integration/Processor/Sales/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function createOrder(array $data)
*/
protected function processOrderCreation(array $data)
{
$order = null;
$code = $this->arrayExtract($data, 'code');
$channel = $this->arrayExtract($data, 'channel');
$orderId = $this->getOrderId($code);
Expand Down
39 changes: 21 additions & 18 deletions Integration/Support/Sales/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public function setCustomer(CustomerInterface $customer)
$data = [
'order' => [
'account' => [
'group_id' => $customer->getGroupId(),
'email' => $customer->getEmail()
'group_id' => $customer->getGroupId(),
'email' => $customer->getEmail(),
]
],
'session' => [
Expand Down Expand Up @@ -422,27 +422,30 @@ public function create()
$order = null;

if (!empty($orderData)) {

$this->getSession()->clear();
$this->initSession($this->arrayExtract($orderData, 'session'));

$this->processQuote($orderData);
$paymentData = $this->arrayExtract($orderData, 'payment');
try {

if (!empty($paymentData)) {
$this->getOrderCreator()
->setPaymentData($paymentData);
$this->processQuote($orderData);
$paymentData = $this->arrayExtract($orderData, 'payment');

$this->getQuote()
->getPayment()
->addData($paymentData);
}
if (!empty($paymentData)) {
$this->getOrderCreator()
->setPaymentData($paymentData);

$this->context->eventManager()->dispatch('bittools_skyhub_order_import_before', [
'order' => $order,
'order_data' => $orderData,
'creator' => $this,
]);
$this->getQuote()
->getPayment()
->addData($paymentData);
}

$this->context->eventManager()->dispatch('bittools_skyhub_order_import_before', [
'order' => $order,
'order_data' => $orderData,
'creator' => $this,
]);

try {
/** @var Order $order */
$order = $this->getOrderCreator()
->importPostData($this->arrayExtract($orderData, 'order'))
Expand All @@ -452,7 +455,7 @@ public function create()
} catch (\Exception $e) {
/** remove quote */
$this->quoteRepository->delete($this->getQuote());
$this->getSession()->clear();
// $this->getSession()->clear();
/** end */

$this->context->helperContext()->logger()->critical($e);
Expand Down
54 changes: 4 additions & 50 deletions Model/Backend/Session/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,16 @@

class Quote extends \Magento\Backend\Model\Session\Quote
{
public function __construct(
\Magento\Framework\App\Request\Http $request,
\Magento\Framework\Session\SidResolverInterface $sidResolver,
\Magento\Framework\Session\Config\ConfigInterface $sessionConfig,
\Magento\Framework\Session\SaveHandlerInterface $saveHandler,
\Magento\Framework\Session\ValidatorInterface $validator,
\Magento\Framework\Session\StorageInterface $storage,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory,
\Magento\Framework\App\State $appState,
CustomerRepositoryInterface $customerRepository,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
GroupManagementInterface $groupManagement,
\Magento\Quote\Model\QuoteFactory $quoteFactory
) {
$this->customerRepository = $customerRepository;
$this->quoteRepository = $quoteRepository;
$this->_orderFactory = $orderFactory;
$this->_storeManager = $storeManager;
$this->groupManagement = $groupManagement;
$this->quoteFactory = $quoteFactory;
parent::__construct(
$request,
$sidResolver,
$sessionConfig,
$saveHandler,
$validator,
$storage,
$cookieManager,
$cookieMetadataFactory,
$appState,
$customerRepository,
$quoteRepository,
$orderFactory,
$storeManager,
$groupManagement,
$quoteFactory
);

$this->clear();
}

/**
* @return $this
*/
public function clear()
{
if ($this->getQuote()->getSkyhubCode()) {
$this->_quote = null;
$this->_order = null;
$this->_store = null;
$this->_quote = null;
$this->_order = null;
$this->_store = null;

$this->clearStorage();
}
$this->clearStorage();

return $this;
}
Expand Down

0 comments on commit 2b78e0f

Please sign in to comment.