Issues (1092)

Helper/AmastyGiftcard.php (3 issues)

1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2020 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Helper;
28
29
use Magento\Sales\Model\Order;
0 ignored issues
show
The type Magento\Sales\Model\Order 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...
This use statement conflicts with another class in this namespace, Payone\Core\Helper\Order. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
30
31
/**
32
 * Helper class for Amasty giftcards
33
 */
34
class AmastyGiftcard extends \Payone\Core\Helper\Base
35
{
36
    /**
37
     * Array of amasty giftcards
38
     *
39
     * @var array
40
     */
41
    protected $aAmastyGiftcard = null;
42
43
    /**
44
     * Checks if Amasty Giftcard class is existing and returns the used giftcards for this order
45
     *
46
     * We are aware that the ObjectManager should not be called like this,
47
     * but since most shops won't have this module installed we can't load it with the dependency injection in the constructor.
48
     *
49
     * If there is a better way to solve this optional injection/soft dependancy feel free to tell us.
50
     *
51
     * @param  string $sQuoteId
52
     * @param  Order $oOrder
53
     * @return array
54
     */
55
    public function getAmastyGiftCards($sQuoteId, $oOrder)
56
    {
57
        if ($this->aAmastyGiftcard === null) {
58
            $this->aAmastyGiftcard = [];
59
            if (class_exists('\Amasty\GiftCard\Model\ResourceModel\Quote\Collection')) { // old Amasty module version
60
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
0 ignored issues
show
The type Magento\Framework\App\ObjectManager 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...
61
62
                $giftCardsCollection = $objectManager->create('Amasty\GiftCard\Model\ResourceModel\Quote\CollectionFactory');
63
                $this->aAmastyGiftcard = $giftCardsCollection->create()->getGiftCardsWithAccount($sQuoteId)->getData();
64
            }
65
66
            if ($oOrder && $oOrder->getExtensionAttributes() && is_callable([$oOrder->getExtensionAttributes(), 'getAmGiftcardOrder']) && $oOrder->getExtensionAttributes()->getAmGiftcardOrder()) { // new Amasty module version
67
                $giftCards = $oOrder->getExtensionAttributes()->getAmGiftcardOrder()->getGiftCards();
68
                foreach ($giftCards as $giftCard) {
69
                    // copy fields to fit old format
70
                    $giftCard['gift_amount'] = $giftCard['amount'];
71
                    $giftCard['base_gift_amount'] = $giftCard['b_amount'];
72
                    $this->aAmastyGiftcard[] = $giftCard;
73
                }
74
            }
75
        }
76
        return $this->aAmastyGiftcard;
77
    }
78
79
    /**
80
     * Determine if order has used amasty giftcards
81
     *
82
     * @param  string $sQuoteId
83
     * @param  Order $oOrder
84
     * @return bool
85
     */
86
    public function hasAmastyGiftcards($sQuoteId, $oOrder)
87
    {
88
        $aGiftCards = $this->getAmastyGiftCards($sQuoteId, $oOrder);
89
        if (!empty($aGiftCards)) {
90
            return true;
91
        }
92
        return false;
93
    }
94
}
95