protected function save(ActiveRecordModel $listGroup)
 {
     $validator = $this->buildValidator();
     if ($validator->isValid()) {
         $listGroup->loadRequestData($this->request);
         $listGroup->save();
         return new JSONResponse(array('ID' => $listGroup->getID(), 'data' => $listGroup->toArray()), 'success');
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure');
     }
 }
예제 #2
0
파일: User.php 프로젝트: saiber/www
 public function toArray()
 {
     $array = parent::toArray();
     $array['newPassword'] = $this->newPassword;
     $this->setArrayData($array);
     return $array;
 }
예제 #3
0
 public function toArray()
 {
     $array = parent::toArray();
     $currencyID = $array['OrderedItem']['CustomerOrder']['currencyID'];
     $currency = Currency::getInstanceByID($currencyID);
     $array['ProductPrice_setup']['formated_price'][$currencyID] = $currency->getFormattedPrice($array['setupPrice']);
     $array['ProductPrice_period']['formated_price'][$currencyID] = $currency->getFormattedPrice($array['periodPrice']);
     return $array;
 }
예제 #4
0
 public function toArray($amount = null)
 {
     $array = parent::toArray();
     $array['formattedAmount'] = array();
     $amountCurrency = $this->shipment->get()->getCurrency();
     // get and format prices
     $array['formattedAmount'][$amountCurrency->getID()] = $amountCurrency->getFormattedPrice($this->getAmount($amount));
     if (!is_null($amount)) {
         $array['amount'] = $amount;
     }
     return $array;
 }
예제 #5
0
 /**
  *  Creates an array representation of the shopping cart
  */
 public function toArray($options = array())
 {
     $currency = $this->getCurrency();
     $id = $currency->getID();
     if (is_array($this->orderedItems)) {
         foreach ($this->orderedItems as $item) {
             if (!$item->getProduct()->isPricingLoaded()) {
                 if (!isset($products)) {
                     $products = new ARSet();
                 }
                 $products->unshift($item->getProduct());
             }
         }
     }
     $array = parent::toArray();
     $array['cartItems'] = array();
     $array['wishListItems'] = array();
     if (is_array($this->orderedItems)) {
         foreach ($this->orderedItems as $item) {
             if ($item->isSavedForLater->get()) {
                 $array['wishListItems'][] = $item->toArray();
             } else {
                 $array['cartItems'][] = $item->toArray();
             }
         }
     }
     $array['basketCount'] = $this->getShoppingCartItemCount();
     $array['wishListCount'] = $this->getWishListItemCount();
     // shipments
     $array['shipments'] = array();
     if ($this->shipments) {
         foreach ($this->shipments as $shipment) {
             if (count($shipment->getItems())) {
                 $array['shipments'][] = $shipment->toArray();
             }
         }
     }
     // total for all currencies
     $total = array();
     $total[$id] = $this->getTotal();
     // taxes
     $array['taxes'] = $taxAmount = array();
     $taxAmount[$id] = 0;
     $array['taxes'][$id] = array();
     foreach ($this->taxes as $taxId => $amount) {
         if ($amount > 0) {
             $taxAmount[$id] += $amount;
             $tax = Tax::getInstanceById($taxId)->toArray();
             $tax['amount'] = $amount;
             $tax['formattedAmount'] = $currency->getFormattedPrice($amount);
             $array['taxes'][$id][] = $tax;
         }
     }
     $array['taxAmount'] = $taxAmount[$id];
     foreach ($this->taxDetails as &$taxRate) {
         $taxRate['formattedAmount'] = $currency->getFormattedPrice($taxRate['amount']);
     }
     $array['taxDetails'] = $this->taxDetails;
     $array['total'] = $total;
     $array['formattedTotal'] = $array['formattedTotalBeforeTax'] = array();
     if (is_array($array['total'])) {
         foreach ($array['total'] as $id => $amount) {
             if (!isset($taxAmount[$id])) {
                 $taxAmount[$id] = 0;
             }
             $array['formattedTotalBeforeTax'][$id] = $currency->getFormattedPrice($amount - $taxAmount[$id]);
             $array['formattedTotal'][$id] = $currency->getFormattedPrice($amount);
         }
     }
     // order type
     $array['isShippingRequired'] = (int) $this->isShippingRequired();
     // status
     $array['isReturned'] = (int) $this->isReturned();
     $array['isShipped'] = (int) $this->isShipped();
     $array['isAwaitingShipment'] = (int) $this->isAwaitingShipment();
     $array['isProcessing'] = (int) $this->isProcessing();
     // payments
     if (isset($options['payments'])) {
         $array['amountPaid'] = $this->getPaidAmount();
         $array['amountNotCaptured'] = $array['amountPaid'] - $array['capturedAmount'];
         if ($array['amountNotCaptured'] < 0) {
             $array['amountNotCaptured'] = 0;
         }
         $array['amountDue'] = $array['totalAmount'] - $array['amountPaid'];
         if ($array['amountDue'] < 0) {
             $array['amountDue'] = 0;
         }
     }
     // items subtotal
     $array['itemSubtotal'] = $array['itemDisplayPriceTotal'] = $array['itemSubtotalWithoutTax'] = 0;
     foreach ($this->getOrderedItems() as $item) {
         $array['itemSubtotal'] += $item->getSubtotal(true);
         $array['itemSubtotalWithoutTax'] += $item->getSubtotal(false);
         $array['itemDisplayPriceTotal'] += $item->getDisplayPrice($currency) * $item->count->get();
     }
     $array['itemDiscount'] = $array['itemDisplayPriceTotal'] - $array['itemSubtotal'];
     $array['itemDiscountReverse'] = $array['itemDiscount'] * -1;
     // shipping subtotal
     $array['shippingSubtotal'] = null;
     $array['shippingSubtotalWithoutTax'] = null;
     if ($this->shipments) {
         foreach ($this->shipments as $shipment) {
             $shipmentShipping = $shipment->getShippingTotalWithTax();
             if (!is_null($shipmentShipping)) {
                 $array['shippingSubtotal'] += $shipment->getShippingTotalWithTax();
                 $array['shippingSubtotalWithoutTax'] += $shipment->getShippingTotalBeforeTax();
             }
         }
     }
     $array['subtotalBeforeTaxes'] = $array['itemSubtotalWithoutTax'] + $array['shippingSubtotalWithoutTax'];
     foreach (array('amountPaid', 'amountNotCaptured', 'amountDue', 'itemSubtotal', 'shippingSubtotal', 'shippingSubtotalWithoutTax', 'subtotalBeforeTaxes', 'totalAmount', 'itemDiscountReverse', 'itemDiscount', 'itemSubtotalWithoutTax') as $key) {
         if (isset($array[$key])) {
             $array['formatted_' . $key] = $currency->getFormattedPrice($array[$key]);
         }
     }
     // discounts
     $array['discountAmount'] = 0;
     foreach (array_merge($this->fixedDiscounts, $this->orderDiscounts) as $key => $discount) {
         $array['discounts'][$discount->getID() ? $discount->getID() : $key] = $discount->toArray();
         $array['discountAmount'] -= $discount->amount->get();
     }
     // percentage discount applied to finalized order
     if (!$array['discountAmount'] && $array['isFinalized'] && $array['subtotalBeforeTaxes'] > $array['totalAmount']) {
         $array['discountAmount'] = $array['totalAmount'] - $array['subtotalBeforeTaxes'] - $array['taxAmount'];
     }
     $array['formatted_discountAmount'] = $this->getCurrency()->getFormattedPrice($array['discountAmount']);
     // coupons
     if (!is_null($this->coupons)) {
         $array['coupons'] = $this->coupons->toArray();
     }
     if (!$array['isFinalized']) {
         //$this->isRulesProcessed = false;
         $isOrderable = $this->isOrderable();
         if ($isOrderable instanceof OrderException) {
             $array['error'] = $isOrderable->toArray();
         }
         $array['isOrderable'] = !$isOrderable instanceof OrderException && $isOrderable;
         $array['isShippingSelected'] = $this->isShippingSelected();
         $array['isAddressSelected'] = $this->shippingAddress->get() && $this->billingAddress->get();
     }
     // otherwise left empty on payment page for some reason...
     if ($this->billingAddress->get()) {
         $array['BillingAddress'] = $this->billingAddress->get()->toArray();
     }
     $array['paymentMethod'] = $this->paymentMethod;
     if ($array['paymentMethod']) {
         $array['paymentMethodName'] = substr($array['paymentMethod'], 0, 7) == 'OFFLINE' ? OfflineTransactionHandler::getMethodName($array['paymentMethod']) : ActiveRecordModel::getApplication()->translate($array['paymentMethod']);
     }
     $this->setArrayData($array);
     return $array;
 }
예제 #6
0
파일: Transaction.php 프로젝트: saiber/www
 public function toArray()
 {
     $array = parent::toArray();
     $array['isVoidable'] = $this->isVoidable();
     $array['isCapturable'] = $this->isCapturable();
     $array['isMultiCapture'] = $this->isMultiCapture();
     $array['hasFullNumber'] = strlen(self::decrypt($this->ccLastDigits->get())) > self::LAST_DIGIT_COUNT;
     return $array;
 }
예제 #7
0
 public function exportInstance(ActiveRecordModel $instance)
 {
     return $this->exportArray($instance->toArray());
 }
예제 #8
0
 public function toArray()
 {
     $array = parent::toArray();
     $currency = $this->getCurrency();
     $id = $currency->getID();
     // ordered items
     $items = array();
     foreach ($this->items as $item) {
         $items[] = $item->toArray();
     }
     $array['items'] = $items;
     // subtotal
     $currencies = self::getApplication()->getCurrencySet();
     $array['subTotal'][$id] = $this->getSubTotal();
     // total amount
     $array['totalAmount'] = $this->getTotal();
     $array['formatted_totalAmount'] = $this->order->get()->currency->get()->getFormattedPrice($array['totalAmount']);
     $array['formatted_amount'] = $this->order->get()->currency->get()->getFormattedPrice($array['amount']);
     // formatted subtotal
     $array['formattedSubTotal'] = $array['formattedSubTotalBeforeTax'] = array();
     $array['formattedSubTotal'][$id] = $currency->getFormattedPrice($array['subTotal'][$id]);
     $array['formattedSubTotalBeforeTax'][$id] = $currency->getFormattedPrice($array['subTotal'][$id] - $this->getTaxAmount());
     // selected shipping rate
     if ($selected = $this->getSelectedRate()) {
         $array['selectedRate'] = $selected->toArray($this->applyTaxesToShippingAmount($selected->getCostAmount()));
         if (!$array['selectedRate']) {
             unset($array['selectedRate']);
         } else {
             $array['ShippingService'] = $array['selectedRate']['ShippingService'];
         }
     }
     // shipping rate for a saved shipment
     if (!isset($array['selectedRate']) && isset($array['shippingAmount'])) {
         $array['shippingAmountWithoutTax'] = $array['shippingAmount'];
         $array['shippingAmount'] = $this->applyTaxesToShippingAmount($array['shippingAmount']);
         $orderCurrency = $this->order->get()->currency->get();
         $array['selectedRate']['formattedPrice'] = array();
         foreach ($currencies as $id => $currency) {
             $rate = $currency->convertAmount($orderCurrency, $array['shippingAmount']);
             $array['selectedRate']['formattedPrice'][$id] = Currency::getInstanceById($id)->getFormattedPrice($rate);
             $array['selectedRate']['formattedPriceWithoutTax'][$id] = Currency::getInstanceById($id)->getFormattedPrice($array['shippingAmountWithoutTax']);
         }
     }
     // taxes
     $taxes = array();
     foreach ($this->getTaxes() as $tax) {
         if ($tax->taxRate->get()) {
             $taxes[$tax->taxRate->get()->tax->get()->getID()][] = $tax;
         }
     }
     foreach ($taxes as $taxType) {
         $amount = 0;
         foreach ($taxType as $tax) {
             $amount += $tax->amount->get();
         }
         if ($amount > 0) {
             $array['taxes'][] = $tax->toArray($amount);
         }
     }
     // consists of downloadable files only?
     $array['isShippable'] = $this->isShippable();
     // Statuses
     $array['isReturned'] = (int) $this->isReturned();
     $array['isShipped'] = (int) $this->isShipped();
     $array['isAwaitingShipment'] = (int) $this->isAwaitingShipment();
     $array['isProcessing'] = (int) $this->isProcessing();
     $array['isDelivered'] = (int) $this->isDelivered();
     $array['isLost'] = (int) $this->isLost();
     $array['AmountCurrency'] =& $array['Order']['Currency'];
     return $array;
 }
예제 #9
0
 /**
  * Creates an array representation of this node
  *
  * @return array
  */
 public function toArray()
 {
     $data = parent::toArray();
     foreach ($this->data as $name => $field) {
         if ($name == self::PARENT_NODE_FIELD_NAME && $field->get() != null) {
             $data['parent'] = $field->get()->getID();
         }
     }
     $data["childrenCount"] = ($data[self::RIGHT_NODE_FIELD_NAME] - $data[self::LEFT_NODE_FIELD_NAME] - 1) / 2;
     $childArray = array();
     if ($this->childList != null) {
         foreach ($this->childList as $child) {
             $childArray[] = $child->toArray();
         }
         $data['children'] = $childArray;
     }
     return $data;
 }
예제 #10
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['formatted_amount'] = $this->order->get()->currency->get()->getFormattedPrice($array['amount'] * -1);
     return $array;
 }
예제 #11
0
 public function toArray()
 {
     $array = parent::toArray();
     $info = self::getApplication()->getLocale()->info();
     $array['name'] = $info->getLanguageName($array['ID']);
     $array['originalName'] = $info->getOriginalLanguageName($array['ID']);
     if (file_exists(ClassLoader::getRealPath('public.image.localeflag') . '/' . $array['ID'] . '.png')) {
         $array['image'] = 'image/localeflag/' . $array['ID'] . '.png';
     }
     return $array;
 }