1 | <?php |
||
20 | class PaymentCurrencies extends Base |
||
21 | { |
||
22 | /** |
||
23 | * Export paymentCurrencies. |
||
24 | * |
||
25 | * @param PaymentCurrencyModel[] $paymentCurrencies |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | 2 | public function export(array $paymentCurrencies = []) |
|
30 | { |
||
31 | 2 | if (!count($paymentCurrencies)) { |
|
32 | $paymentCurrencies = Craft::app()->commerce_paymentCurrencies->getAllPaymentCurrencies(); |
||
33 | } |
||
34 | |||
35 | 2 | Craft::log(Craft::t('Exporting Commerce Payment Currencies')); |
|
36 | |||
37 | 2 | $paymentCurrencyDefinitions = []; |
|
38 | |||
39 | 2 | foreach ($paymentCurrencies as $paymentCurrency) { |
|
40 | 2 | $paymentCurrencyDefinitions[$paymentCurrency->iso] = $this->getPaymentCurrencyDefinition($paymentCurrency); |
|
41 | 2 | } |
|
42 | |||
43 | 2 | return $paymentCurrencyDefinitions; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get payment currencies definition. |
||
48 | * |
||
49 | * @param Commerce_PaymentCurrencyModel $paymentCurrency |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | 2 | private function getPaymentCurrencyDefinition(Commerce_PaymentCurrencyModel $paymentCurrency) |
|
54 | { |
||
55 | return [ |
||
56 | 2 | 'iso' => $paymentCurrency->iso, |
|
57 | 2 | 'primary' => $paymentCurrency->primary, |
|
58 | 2 | 'rate' => $paymentCurrency->rate, |
|
59 | 2 | ]; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Attempt to import payment currencies. |
||
64 | * |
||
65 | * @param array $paymentCurrencyDefinitions |
||
66 | * @param bool $force If set to true payment currencies not included in the import will be deleted |
||
67 | * |
||
68 | * @return Result |
||
69 | */ |
||
70 | 4 | public function import(array $paymentCurrencyDefinitions, $force = false) |
|
105 | |||
106 | /** |
||
107 | * Populate paymentCurrency. |
||
108 | * |
||
109 | * @param Commerce_PaymentCurrencyModel $paymentCurrency |
||
110 | * @param array $paymentCurrencyDefinition |
||
111 | * @param string $paymentCurrencyHandle |
||
112 | */ |
||
113 | 2 | private function populatePaymentCurrency(Commerce_PaymentCurrencyModel $paymentCurrency, array $paymentCurrencyDefinition, $paymentCurrencyHandle) |
|
121 | |||
122 | /** |
||
123 | * Reset service cache using reflection. |
||
124 | */ |
||
125 | 4 | private function resetCraftPaymentCurrenciesServiceCache() |
|
135 | } |
||
136 |