Esempio n. 1
0
File: ARSet.php Progetto: saiber/www
 public static function buildFromArray($array)
 {
     $set = new ARSet();
     foreach ($array as $record) {
         $set->add($record);
     }
     return $set;
 }
Esempio n. 2
0
 public function loadAll()
 {
     $set = new ARSet();
     $set->add($this);
     $subConditions = self::loadSubConditions($set);
     $subConditions->add($this);
     self::loadConditionRecords($subConditions, 'DiscountConditionRecord');
     //self::loadConditionRecords($subConditions, array('Category' => array('DiscountConditionRecord'), 'Product', 'Manufacturer', 'User', 'UserGroup', 'DeliveryZone'));
 }
Esempio n. 3
0
 /**
  * @return ARSet
  */
 public function getRelatedProducts($type = 0)
 {
     $relatedProducts = new ARSet();
     foreach ($this->getRelationships($type) as $relationship) {
         $relatedProducts->add($relationship->relatedProduct->get());
     }
     return $relatedProducts;
 }
Esempio n. 4
0
 private function getDefaultRatingTypeSet()
 {
     $set = new ARSet();
     $set->add(self::getDefaultRatingType());
     return $set;
 }
Esempio n. 5
0
 public static function getTotalBundlePrice(Product $product, Currency $currency)
 {
     $products = new ARSet();
     $bundle = self::getBundledProductSet($product);
     foreach ($bundle as $item) {
         $products->add($item->relatedProduct->get());
     }
     ProductPrice::loadPricesForRecordSet($products);
     $total = 0;
     foreach ($bundle as $item) {
         $itemTotal = $item->relatedProduct->get()->getPrice($currency) * $item->getCount();
         $total += $itemTotal;
     }
     return $total;
 }
Esempio n. 6
0
 public function unserialize($serialized)
 {
     parent::unserialize($serialized);
     // load products
     $productIds = array();
     foreach ($this->orderedItems as $item) {
         $productIds[] = $item->getProduct()->getID();
     }
     $products = ActiveRecordModel::getInstanceArray('Product', $productIds, Product::LOAD_REFERENCES);
     // load product prices
     $set = new ARSet();
     foreach ($products as $product) {
         $set->add($product);
     }
     ProductPrice::loadPricesForRecordSet($set);
 }
Esempio n. 7
0
 public function create()
 {
     $request = $this->getRequest();
     $query = $request->get('query');
     if (strlen($query)) {
         $products = $this->getProductsFromSearchQuery($query);
     } else {
         $products = new ARSet();
         $products->add(Product::getInstanceById((int) $this->request->get('productID'), true));
     }
     $saveResponse = array('errors' => array(), 'items' => array());
     $composite = new CompositeJSONResponse();
     $order = CustomerOrder::getInstanceByID((int) $this->request->get('orderID'), true);
     $order->loadAll();
     foreach ($products as $product) {
         if ($product->isDownloadable()) {
             $shipment = $order->getDownloadShipment();
         } else {
             if ((int) $this->request->get('shipmentID')) {
                 $shipment = Shipment::getInstanceById('Shipment', (int) $this->request->get('shipmentID'), true, array('Order' => 'CustomerOrder', 'ShippingService', 'ShippingAddress' => 'UserAddress', 'Currency'));
             }
         }
         if (empty($shipment)) {
             $shipment = $order->getShipments()->get(0);
         }
         if (!$shipment) {
             $shipment = Shipment::getNewInstance($order);
         }
         if (!$shipment->order->get()) {
             $shipment->order->set($order);
         }
         $history = new OrderHistory($order, $this->user);
         $existingItem = false;
         foreach ($shipment->getItems() as $item) {
             if ($item->getProduct() === $product) {
                 if (!$product->getOptions(true)) {
                     $existingItem = $item;
                 }
                 break;
             }
         }
         if ($existingItem) {
             $item = $existingItem;
             if ($product->isDownloadable()) {
                 return new JSONResponse(false, 'failure', $this->translate('_downloadable_item_already_exists_in_this_order'));
             } else {
                 $item->count->set($item->count->get() + 1);
             }
         } else {
             $currency = $shipment->getCurrency();
             $item = OrderedItem::getNewInstance($order, $product);
             $item->count->set(1);
             $item->price->set($currency->round($item->reduceBaseTaxes($product->getPrice($currency->getID()))));
             $order->addItem($item);
             $shipment->addItem($item);
             $shipment->save();
         }
         $resp = $this->save($item, $shipment, $existingItem ? true : false);
         if (array_key_exists('errors', $resp)) {
             $saveResponse['errors'] = array_merge($saveResponse['errors'], $resp['errors']);
         } else {
             if (array_key_exists('item', $resp)) {
                 $saveResponse['items'][] = $resp['item'];
             }
         }
     }
     // for each product
     if (count($saveResponse['errors']) == 0) {
         unset($saveResponse['errors']);
     }
     if (isset($saveResponse['errors'])) {
         $response = new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_unable_to_update_items_quantity'));
     } else {
         $response = new JSONResponse($saveResponse, 'success', $this->translate('_item_has_been_successfuly_saved'));
     }
     $composite->addResponse('data', $response, $this, 'create');
     $ids = array();
     foreach ($saveResponse['items'] as $item) {
         $ids[] = $item['ID'];
     }
     $composite->addAction('html', 'backend.orderedItem', 'items');
     $this->request->set('item_ids', implode(',', $ids));
     $history->saveLog();
     return $composite;
 }
Esempio n. 8
0
 public function getRolesRecordSet(ARSelectFilter $filter = null, $loadReferencedRecords = false)
 {
     if (!$filter) {
         $filter = new ARSelectFilter();
     }
     $rolesRecordSet = new ARSet();
     foreach (AccessControlAssociation::getRecordSetByUserGroup($this, $filter) as $association) {
         $rolesRecordSet->add($association->role->get());
     }
     return $rolesRecordSet;
 }