1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
class EbayEnterprise_GiftCard_Helper_Data extends Mage_Core_Helper_Abstract implements EbayEnterprise_Eb2cCore_Helper_Interface |
17
|
|
|
{ |
18
|
|
|
const ZERO_BALANCE_CARD_MESSAGE = 'EbayEnterprise_GiftCard_Zero_Balance_Card'; |
19
|
|
|
const GIFT_CARD_ADD_SUCCESS = 'EbayEnterprise_GiftCard_Cart_Add_Success'; |
20
|
|
|
const GIFT_CARD_REMOVE_SUCCESS = 'EbayEnterprise_GiftCard_Cart_Remove_Success'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Type checks for self::__construct $initParams |
24
|
|
|
* @param EbayEnterprise_GiftCard_Model_IContainer $checkoutSession |
|
|
|
|
25
|
|
|
* @param EbayEnterprise_MageLog_Helper_Data $logger |
|
|
|
|
26
|
|
|
* @return mixed[] |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
protected function _checkTypes( |
29
|
|
|
EbayEnterprise_GiftCard_Model_IContainer $container |
30
|
|
|
) { |
31
|
|
|
return array($container); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Return the value at field in array if it exists. Otherwise, use the |
36
|
|
|
* default value. |
37
|
|
|
* @param array $arr |
38
|
|
|
* @param string|int $field Valid array key |
39
|
|
|
* @param mixed $default |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
protected function _nullCoalesce(array $arr, $field, $default) |
43
|
|
|
{ |
44
|
|
|
return isset($arr[$field]) ? $arr[$field] : $default; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @see EbayEnterprise_Eb2cCore_Helper_Interface::getConfigModel |
49
|
|
|
* @param mixed $store |
50
|
|
|
* @return EbayEnterprise_Eb2cCore_Model_Config_Registry |
51
|
|
|
*/ |
52
|
|
|
public function getConfigModel($store = null) |
53
|
|
|
{ |
54
|
|
|
return Mage::getModel('eb2ccore/config_registry') |
55
|
|
|
->setStore($store) |
56
|
|
|
->addConfigModel(Mage::getSingleton('ebayenterprise_giftcard/config')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Add a gift card to the container. Will make the gift card balance check |
61
|
|
|
* and make sure card can be applied to the order. |
62
|
|
|
* @param EbayEnterprise_GiftCard_Model_IGiftcard $card |
63
|
|
|
* @return self |
64
|
|
|
* @throws EbayEnterprise_GiftCard_Exception If gift card could not be added to the order. |
65
|
|
|
*/ |
66
|
|
|
public function addGiftCardToOrder( |
67
|
|
|
EbayEnterprise_GiftCard_Model_IGiftcard $card, |
68
|
|
|
EbayEnterprise_GiftCard_Model_IContainer $giftCardContainer |
69
|
|
|
) { |
70
|
|
|
$card->checkBalance(); |
71
|
|
|
// Treat 0 balance gift cards as invalid. |
72
|
|
|
if ($card->getBalanceAmount() <= 0) { |
73
|
|
|
throw Mage::exception('EbayEnterprise_GiftCard', $this->__(self::ZERO_BALANCE_CARD_MESSAGE, $card->getCardNumber())); |
74
|
|
|
} |
75
|
|
|
$giftCardContainer->updateGiftCard($card); |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.