Пример #1
0
 public function toArray($amount = null)
 {
     $array = parent::toArray();
     if (!is_null($amount)) {
         $array['costAmount'] = $amount;
     }
     if (!$this->application) {
         $this->application = ActiveRecordModel::getApplication();
     }
     $amountCurrency = Currency::getInstanceById($array['costCurrency']);
     $currencies = $this->application->getCurrencySet();
     // get and format prices
     $prices = $formattedPrices = $taxPrices = $unformattedTaxPrices = array();
     foreach ($currencies as $id => $currency) {
         $prices[$id] = $currency->convertAmount($amountCurrency, $array['costAmount']);
         $formattedPrices[$id] = $currency->getFormattedPrice($prices[$id]);
         $unformattedTaxPrices[$id] = $currency->convertAmount($amountCurrency, $this->amountWithTax);
         $taxPrices[$id] = $currency->getFormattedPrice($unformattedTaxPrices[$id]);
         $withoutTaxPrices[$id] = $currency->convertAmount($amountCurrency, $this->amountWithoutTax);
         $formattedWithoutTaxPrices[$id] = $currency->getFormattedPrice($withoutTaxPrices[$id]);
     }
     $array['price'] = $prices;
     $array['priceWithTax'] = $unformattedTaxPrices;
     $array['formattedPrice'] = $formattedPrices;
     $array['taxPrice'] = $taxPrices;
     $array['priceWithoutTax'] = $withoutTaxPrices;
     $array['formattedPriceWithoutTax'] = $formattedWithoutTaxPrices;
     // shipping service name
     $id = $this->getServiceID();
     if (is_numeric($id)) {
         try {
             $service = ShippingService::getInstanceById($id, ShippingService::LOAD_DATA);
             $array['ShippingService'] = $service->toArray();
         } catch (ARNotFoundException $e) {
             return array();
         }
     } else {
         $array['ShippingService'] = array('name_lang' => $this->getServiceName(), 'provider' => $this->getProviderName());
     }
     return $array;
 }