Passed
Pull Request — master (#49)
by Mage
02:28
created

Success::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 18
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 35
rs 9.6666
1
<?php
2
3
/**
4
 * MagePrince
5
 * Copyright (C) 2020 Mageprince <[email protected]>
6
 *
7
 * @package Mageprince_BuyNow
8
 * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
9
 * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
10
 * @author MagePrince <[email protected]>
11
 */
12
13
namespace Mageprince\BuyNow\Controller\Onepage;
14
15
/**
16
 * Onepage checkout success controller class
17
 */
18
class Success extends \Magento\Checkout\Controller\Onepage\Success
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Controller\Onepage\Success was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
{
20
    /**
21
     * Order success action
22
     *
23
     * @return \Magento\Framework\Controller\ResultInterface
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\ResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     */
25
    public function execute()
26
    {
27
        $session = $this->getOnepage()->getCheckout();
28
        if (!$this->_objectManager->get(\Magento\Checkout\Model\Session\SuccessValidator::class)->isValid()) {
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Model\Session\SuccessValidator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
            return $this->resultRedirectFactory->create()->setPath('checkout/cart');
30
        }
31
        $session->clearQuote();
32
        //@todo: Refactor it to match CQRS
33
        $resultPage = $this->resultPageFactory->create();
34
        $this->_eventManager->dispatch(
35
            'checkout_onepage_controller_success_action',
36
            [
37
                'order_ids' => [$session->getLastOrderId()],
38
                'order' => $session->getLastRealOrder(),
39
            ]
40
        );
41
42
        /* Restore Product into Cart */
43
        $this->_eventManager->dispatch(
44
            'checkout_product_merge_custom',
45
            [
46
                'order' => $session->getLastRealOrder(),
47
                'update_data' => 0,
48
            ]
49
        );
50
51
        $this->_eventManager->dispatch(
52
            'checkout_product_merge_custom',
53
            [
54
                'order' => $session->getLastRealOrder(),
55
                'update_data' => 1,
56
            ]
57
        );
58
59
        return $resultPage;
60
    }
61
}
62