Completed
Pull Request — develop (#165)
by Robbie
04:15
created

AbstractGiftCardCommand::getGiftcard()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace N98\Magento\Command\GiftCard;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use Magento\GiftCardAccount\Model\Giftcardaccount;
7
8
abstract class AbstractGiftCardCommand extends AbstractMagentoCommand
9
{
10
    /**
11
     * @return bool
12
     */
13
    public function isEnabled()
14
    {
15
        return $this->getApplication()->isMagentoEnterprise();
16
    }
17
18
    /**
19
     * Get the gift card model, optionally loading from an ID
20
     * @param  string|null $code
21
     * @return Giftcardaccount
22
     */
23
    public function getGiftcard($code = null)
24
    {
25
        $giftcard = $this->getObjectManager()->get(Giftcardaccount::class);
26
        if (!is_null($code)) {
27
            $giftcard->loadByCode($code);
28
        }
29
        return $giftcard;
30
    }
31
32
    /**
33
     * Required to avoid "Area code not set" exceptions from Mage framework
34
     */
35
    public function setAdminArea()
36
    {
37
        $appState = $this->getObjectManager()->get('Magento\Framework\App\State');
38
        $appState->setAreaCode('adminhtml');
39
    }
40
}
41