PAYONE-GmbH /
magento-2
| 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
|
|||
| 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(); |
||
| 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 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths