public function index()
 {
     $product = Product::getInstanceById($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category'));
     $product->category->get()->getPathNodeSet();
     $additional = $product->getAdditionalCategories();
     foreach ($additional as $category) {
         $category->getPathNodeSet();
     }
     $response = new ActionResponse('product', $product->toArray());
     if ($additional) {
         $response->set('categories', ARSet::buildFromArray($additional)->toArray());
     }
     return $response;
 }
 public function index()
 {
     $category = Category::getInstanceById($this->request->get('id'), ActiveRecord::LOAD_DATA);
     $f = select();
     $f->setOrder(f('CategoryRelationship.position'));
     $additional = $category->getRelatedRecordSet('CategoryRelationship', $f, array('Category_RelatedCategory'));
     $categories = array();
     foreach ($additional as $cat) {
         $categories[] = $cat;
         $cat->relatedCategory->get()->load();
         $cat->relatedCategory->get()->getPathNodeSet();
     }
     $response = new ActionResponse('category', $category->toArray());
     $response->set('categories', ARSet::buildFromArray($categories)->toArray());
     return $response;
 }
Esempio n. 3
0
 private function getItemOptions()
 {
     // load product options
     $products = array();
     foreach ($this->order->getOrderedItems() as $item) {
         $products[$item->getProduct()->getID()] = $item->getProduct();
     }
     $options = ProductOption::loadOptionsForProductSet(ARSet::buildFromArray($products));
     $moreOptions = $optionsArray = array();
     foreach ($this->order->getOrderedItems() as $item) {
         $productID = $item->getProduct()->getID();
         if (isset($options[$productID])) {
             $optionsArray[$item->getID()] = $this->getOptionsArray($options[$productID], $item, 'isDisplayedInCart');
             $moreOptions[$item->getID()] = $this->getOptionsArray($options[$productID], $item, 'isDisplayed');
         }
     }
     // are there any options that are available for customer to set, but not displayed right away?
     foreach ($moreOptions as &$options) {
         foreach ($options as $key => $option) {
             if ($option['isDisplayedInCart']) {
                 unset($options[$key]);
             }
         }
     }
     return array('visible' => $optionsArray, 'more' => $moreOptions);
 }
 private function shipmentInfo($response)
 {
     $order = CustomerOrder::getInstanceById($this->request->get('id'), true, true);
     $order->loadAll();
     $order->getCoupons();
     $products = ARSet::buildFromArray($order->getOrderedItems())->extractReferencedItemSet('product', 'ProductSet');
     $variations = $products->getVariationMatrix();
     $form = $this->createShipmentForm();
     $form->setData(array('orderID' => $order->getID()));
     $shipments = $order->getShipments();
     $zone = $order->getDeliveryZone();
     $taxZone = $order->getTaxZone();
     $statuses = array(Shipment::STATUS_NEW => $this->translate('_shipping_status_new'), Shipment::STATUS_PROCESSING => $this->translate('_shipping_status_pending'), Shipment::STATUS_AWAITING => $this->translate('_shipping_status_awaiting'), Shipment::STATUS_SHIPPED => $this->translate('_shipping_status_shipped'), Shipment::STATUS_RETURNED => $this->translate('_shipping_status_returned'));
     $subtotalAmount = 0;
     $shippingAmount = 0;
     $taxAmount = 0;
     $itemIDs = $shipmentsArray = array();
     $shipableShipmentsCount = 0;
     foreach ($shipments as $shipment) {
         $subtotalAmount += $shipment->amount->get();
         $shippingAmount += $shipment->shippingAmount->get();
         $taxAmount += $shipment->taxAmount->get();
         $shipmentsArray[$shipment->getID()] = $shipment->toArray();
         $rate = unserialize($shipment->shippingServiceData->get());
         if (is_object($rate)) {
             $rate->setApplication($this->application);
             $shipmentsArray[$shipment->getID()] = array_merge($shipmentsArray[$shipment->getID()], $rate->toArray());
             if (isset($shipmentsArray[$shipment->getID()]['serviceID'])) {
                 $shipmentsArray[$shipment->getID()]['ShippingService']['ID'] = $shipmentsArray[$shipment->getID()]['serviceID'];
             }
         } else {
             if ($shipment->shippingService->get()) {
                 $shipmentsArray[$shipment->getID()]['ShippingService']['name_lang'] = $shipmentsArray[$shipment->getID()]['ShippingService']['name'];
             } else {
                 $shipmentsArray[$shipment->getID()]['ShippingService']['name_lang'] = $this->translate('_shipping_service_is_not_selected');
             }
         }
         if ($shipment->status->get() != Shipment::STATUS_SHIPPED && $shipment->isShippable()) {
             $shipableShipmentsCount++;
         }
         foreach ($shipment->getItems() as $item) {
             $itemIDs[] = $item->getID();
         }
     }
     $totalAmount = $subtotalAmount + $shippingAmount + $taxAmount;
     // $response = new ActionResponse();
     $response->set('orderID', $this->request->get('id'));
     $response->set('order', $order->toArray());
     $response->set('shippingServiceIsNotSelected', $this->translate('_shipping_service_is_not_selected'));
     $response->set('shipments', $shipmentsArray);
     $response->set('subtotalAmount', $subtotalAmount);
     $response->set('shippingAmount', $shippingAmount);
     $response->set('variations', $variations);
     if ($downloadable = $order->getDownloadShipment(false)) {
         $response->set('downloadableShipment', $downloadable->toArray());
     }
     $response->set('taxAmount', $taxAmount);
     $response->set('totalAmount', $totalAmount);
     $response->set('shipableShipmentsCount', $shipableShipmentsCount);
     $response->set('statuses', $statuses + array(-1 => $this->translate('_delete')));
     unset($statuses[3]);
     $response->set('statusesWithoutShipped', $statuses);
     $response->set('newShipmentForm', $form);
     $response->set('downloadCount', $this->getDownloadCounts($itemIDs));
     // load product options
     $response->set('allOptions', ProductOption::loadOptionsForProductSet($products));
     return $response;
 }
Esempio n. 5
0
 /**
  * Load product pricing data for a whole array of products at once
  */
 public static function loadPricesForRecordSet(ARSet $products)
 {
     $set = ARSet::buildFromArray($products->getData());
     foreach ($products as $key => $product) {
         if ($product->parent->get()) {
             $set->add($product->parent->get());
         }
     }
     $ids = array();
     foreach ($set as $key => $product) {
         $ids[$product->getID()] = $key;
     }
     $priceArray = self::fetchPriceData(array_flip($ids));
     $pricing = array();
     foreach ($priceArray as $price) {
         $pricing[$price['productID']][$price['currencyID']] = $price;
     }
     foreach ($pricing as $productID => $productPricing) {
         $product = $set->get($ids[$productID]);
         $product->loadPricing($productPricing);
     }
 }
Esempio n. 6
0
 public function loadItems()
 {
     if (!$this->isExistingRecord()) {
         return false;
     }
     $this->event('before-load');
     $itemSet = $this->getRelatedRecordSet('OrderedItem', new ARSelectFilter(), array('Product', 'Category', 'DefaultImage' => 'ProductImage'));
     $this->orderedItems = $itemSet->getData();
     $products = $itemSet->extractReferencedItemSet('product');
     ProductPrice::loadPricesForRecordSet($products);
     $parentIDs = $products->extractReferencedItemSet('parent')->getRecordIDs();
     if ($parentIDs) {
         ActiveRecordModel::getRecordSet('Product', new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'ID'), $parentIDs)), array('Category', 'ProductImage'));
     }
     if ($this->orderedItems) {
         if (!$this->shipments || !$this->shipments->size()) {
             $this->shipments = $this->getRelatedRecordSet('Shipment', new ARSelectFilter(), array('UserAddress', 'ShippingService'));
             // @todo: should be loaded automatically
             foreach ($this->shipments as $shipment) {
                 if ($shipment->shippingAddress->get()) {
                     $shipment->shippingAddress->get()->load();
                 }
             }
         }
         if (!$this->shipments->size() && !$this->isFinalized->get()) {
             $this->shipments = unserialize($this->shipping->get());
         }
         OrderedItemOption::loadOptionsForItemSet(ARSet::buildFromArray($this->orderedItems));
         ARSet::buildFromArray($this->orderedItems)->extractReferencedItemSet('product', 'ProductSet')->loadVariations();
         foreach ($this->orderedItems as $key => $item) {
             if ($item->parent->get()) {
                 $item->parent->get()->registerSubItem($item);
                 unset($this->orderedItems[$key]);
             }
         }
         Product::loadAdditionalCategoriesForSet(ARSet::buildFromArray($this->orderedItems)->extractReferencedItemSet('product'));
     }
     if (!$this->isFinalized->get() && $this->orderedItems) {
         return $this->updateToStock();
     }
     $this->event('after-load');
 }