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')); }
private function getInheritedConfig(ARSet $set) { if ($set->size()) { // category level configuration? $prod = $set->shift(); // fill missing product level settings with category level settings foreach ($set as $cat) { foreach (array('theme', 'isAllVariations', 'isVariationImages', 'listStyle') as $field) { if (!$prod->{$field}->get()) { $prod->{$field}->set($cat->{$field}->get()); } } } return $prod; } }
protected function processSet(ARSet $set) { foreach ($set as $record) { $this->processRecord($record); //echo round(memory_get_usage() / (1024*1024), 1) . "MB \n"; if ('delete' == $this->getAction()) { $this->deleteRecord($record); } else { $this->saveRecord($record); } $record->__destruct(); unset($record); if (connection_aborted()) { $this->cancel(); } } $set->__destruct(); unset($set); ActiveRecord::clearPool(); }
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; }
private function getSelectOptionsFromSet(ARSet $set) { if (!$set->size()) { return array(); } $options = array('' => ''); foreach ($set as $record) { $arr = $record->toArray(); $options[$record->getID()] = $arr['name_lang']; } return $options; }
private function getOrderArray(ARSet $orders) { $orderArray = $orders->toArray(); $ids = array(); foreach ($orderArray as $key => $order) { $ids[$order['ID']] = $key; } ClassLoader::import('application.model.order.OrderNote'); $f = new ARSelectFilter(new INCond(new ARFieldHandle('OrderNote', 'orderID'), empty($ids) ? array(-1) : array_keys($ids))); $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isAdmin'), 1)); $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isRead'), 0)); $f->setGrouping(new ARFieldHandle('OrderNote', 'orderID')); $query = new ARSelectQueryBuilder(); $query->setFilter($f); $query->includeTable('OrderNote'); $query->removeFieldList(); $query->addField('COUNT(*)', null, 'cnt'); $query->addField('orderID'); foreach (ActiveRecordModel::getDataBySQL($query->getPreparedStatement(ActiveRecord::getDBConnection())) as $res) { $orderArray[$ids[$res['orderID']]]['unreadMessageCount'] = $res['cnt']; } return $orderArray; }
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; }
/** * @return ARSet */ public function getRelatedProducts($type = 0) { $relatedProducts = new ARSet(); foreach ($this->getRelationships($type) as $relationship) { $relatedProducts->add($relationship->relatedProduct->get()); } return $relatedProducts; }
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; }
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; }
/** * Merge two record sets * * @param ActiveRecord $record */ public function merge(ARSet $set) { $this->data = array_merge($this->data, $set->getData()); }
private function hasMaskGroupMatch(ARSet $masks, $addressString) { if (!$masks->size()) { return true; } $match = false; foreach ($masks as $mask) { if ($this->isMaskMatch($addressString, $mask->mask->get())) { $match = 2; } } return $match; }
public function getCurrentPage() { $filter = $this->recordSet->getFilter(); return $filter->getOffset() / $filter->getLimit() + 1; }
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; }
private function getDefaultRatingTypeSet() { $set = new ARSet(); $set->add(self::getDefaultRatingType()); return $set; }
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); }
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); }
/** * 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); } }