1: <?php
2: /**
3: * Magento
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.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Paypal
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Paypal Data helper
29: */
30: class Mage_Paypal_Helper_Data extends Mage_Core_Helper_Abstract
31: {
32: /**
33: * Cache for shouldAskToCreateBillingAgreement()
34: *
35: * @var bool
36: */
37: protected static $_shouldAskToCreateBillingAgreement = null;
38:
39: /**
40: * Check whether customer should be asked confirmation whether to sign a billing agreement
41: *
42: * @param Mage_Paypal_Model_Config $config
43: * @param int $customerId
44: * @return bool
45: */
46: public function shouldAskToCreateBillingAgreement(Mage_Paypal_Model_Config $config, $customerId)
47: {
48: if (null === self::$_shouldAskToCreateBillingAgreement) {
49: self::$_shouldAskToCreateBillingAgreement = false;
50: if ($customerId && $config->shouldAskToCreateBillingAgreement()) {
51: if (Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($customerId)) {
52: self::$_shouldAskToCreateBillingAgreement = true;
53: }
54: }
55: }
56: return self::$_shouldAskToCreateBillingAgreement;
57: }
58:
59: /**
60: * Return backend config for element like JSON
61: *
62: * @param Varien_Data_Form_Element_Abstract $element
63: * @return string
64: */
65: public function getElementBackendConfig(Varien_Data_Form_Element_Abstract $element) {
66: $config = $element->getFieldConfig()->backend_congif;
67: if (!$config) {
68: return false;
69: }
70: $config = $config->asCanonicalArray();
71: if (isset($config['enable_for_countries'])) {
72: $config['enable_for_countries'] = explode(',', str_replace(' ', '', $config['enable_for_countries']));
73: }
74: if (isset($config['disable_for_countries'])) {
75: $config['disable_for_countries'] = explode(',', str_replace(' ', '', $config['disable_for_countries']));
76: }
77: return Mage::helper('core')->jsonEncode($config);
78: }
79: }
80: