Example #1
0
 protected function postProcessData()
 {
     ProductPrice::loadPricesForRecordSetArray($this->data);
     ProductSpecification::loadSpecificationForRecordSetArray($this->data, true);
     Product::loadCategoryPathsForArray($this->data);
     foreach ($this->data as $key => $product) {
         $this->data[$key]['name_lang_utf8'] = $this->getFixedUtf8($product['name_lang']);
         $this->data[$key]['shortDescription_lang_utf8'] = $this->getFixedUtf8($product['shortDescription_lang']);
         $this->data[$key]['name_lang_safe'] = $this->getSafeEncoding($product['name_lang']);
         $this->data[$key]['shortDescription_lang_safe'] = $this->getSafeEncoding($product['shortDescription_lang']);
     }
 }
Example #2
0
 public function process()
 {
     $this->application->getRouter()->removeAutoAppendVariable('currency');
     if (!$this->response instanceof ActionResponse) {
         return;
     }
     $products = $this->response->get('products');
     $parents = $variations = array();
     foreach ($products as $key => $product) {
         if ($product['parentID']) {
             $parents[$product['parentID']] = true;
             $variations[$key] = $product;
         }
     }
     if (!$parents) {
         return;
     }
     $loadedParents = array();
     foreach (ActiveRecordModel::getRecordSetArray('Product', select(in(f('Product.ID'), array_keys($parents))), array('Manufacturer', 'DefaultImage' => 'ProductImage', 'Category')) as $parent) {
         $loadedParents[$parent['ID']] = $parent;
     }
     ProductSpecification::loadSpecificationForRecordSetArray($loadedParents);
     ProductPrice::loadPricesForRecordSetArray($loadedParents);
     foreach ($products as $key => $product) {
         if ($product['parentID']) {
             $parent = $loadedParents[$product['parentID']];
             foreach ($parent as $field => $value) {
                 if (empty($product[$field])) {
                     $product[$field] = $parent[$field];
                 }
             }
             foreach (array('price_USD', 'price_CAD', 'formattedPrice', 'formattedListPrice') as $field) {
                 if (isset($parent[$field])) {
                     $product[$field] = $parent[$field];
                 }
             }
             ///var_dump($parent);exit;
             $products[$key] = $product;
         }
     }
     ProductSet::loadVariationsForProductArray($variations);
     foreach ($variations as $key => $variation) {
         $vars = array();
         foreach ($variation['variationTypes'] as $type) {
             $vars[] = $type['name_lang'];
         }
         if ($vars) {
             $products[$key]['name_lang'] .= ' (' . implode(' / ', $vars) . ')';
         }
     }
     $this->response->set('products', $products);
 }
Example #3
0
 public function upSellBlock()
 {
     // upsell products
     $upsell = $this->getRelatedProducts($this->product, 1);
     foreach ($upsell as $key => $group) {
         foreach ($upsell[$key] as $i => &$prod) {
             $spec[] =& $upsell[$key][$i];
         }
     }
     if (count($upsell)) {
         ProductSpecification::loadSpecificationForRecordSetArray($spec);
     }
     $response = new BlockResponse();
     $response->set('upsell', $upsell);
     return $response;
 }
Example #4
0
 protected function processDataArray($productArray, $displayedColumns)
 {
     // load price data
     ProductPrice::loadPricesForRecordSetArray($productArray, false);
     // load child products
     //		if (isset($displayedColumns['Product.parentID']))
     //{
     ProductSet::loadVariationTypesForProductArray($productArray);
     ProductSet::loadChildrenForProductArray($productArray);
     //}
     ProductSpecification::loadSpecificationForRecordSetArray($productArray, true);
     foreach ($productArray as &$product) {
         if (!empty($product['children'])) {
             foreach ($product['children'] as &$child) {
                 if (!empty($product['attributes'])) {
                     $child['attributes'] = $product['attributes'];
                 }
                 if (!empty($product['Manufacturer'])) {
                     $child['Manufacturer'] = $product['Manufacturer'];
                 }
                 foreach (array('definedPrices', 'definedListPrices', 'price_USD', 'price_CAD', 'listPrice_USD', 'listPrice_CAD') as $key) {
                     if (!empty($product[$key])) {
                         $child[$key] = $product[$key];
                     }
                 }
                 foreach ($child as $key => $value) {
                     if (empty($value) && !empty($product[$key])) {
                         $child[$key] = $product[$key];
                     }
                 }
                 $variation = null;
                 if (!empty($child['variationValues'])) {
                     $variation = array_shift($child['variationValues']);
                 }
                 $name = $child['name'];
                 $child['URL'] = $product['URL'];
                 $child['name_lang'] = $name . ' ' . $child['sku'];
                 $child['xParent'] = $child['Parent'];
                 unset($child['Parent']);
                 $child['URL'] = $this->router->createFullUrl(createProductUrl(array('product' => $child), $this->application));
                 $child['Parent'] = $child['xParent'];
                 $child['name'] = $name;
                 if ($variation) {
                     $child['name'] .= ' (' . $variation . ')';
                     $child['name_lang'] = $child['name'];
                 }
                 $child['id'] = $child['ID'];
             }
             $product['URL'] = $this->router->createFullUrl(createProductUrl(array('product' => $product), $this->application));
             if (empty($product['ProductImage']['ID'])) {
                 if (!empty($product['children'][0]['ProductImage'])) {
                     $product['ProductImage'] = $product['children'][0]['ProductImage'];
                     $product['DefaultImage'] = $product['children'][0]['DefaultImage'];
                 }
             }
         }
         $product['id'] = $product['ID'];
     }
     $defCurrency = $this->application->getDefaultCurrencyCode();
     foreach ($productArray as &$product) {
         foreach ($this->getUserGroups() as $groupID => $groupName) {
             if (isset($product['priceRules'][$defCurrency][1][$groupID])) {
                 $product['GroupPrice'][$groupID] = $product['priceRules'][$defCurrency][1][$groupID];
             }
         }
     }
     return $productArray;
 }
Example #5
0
 protected function processDataArray($productArray, $displayedColumns)
 {
     // load specification data
     foreach ($displayedColumns as $column => $type) {
         list($class, $field) = explode('.', $column, 2);
         if ('specField' == $class) {
             ProductSpecification::loadSpecificationForRecordSetArray($productArray, true);
             break;
         }
     }
     // load price data
     ProductPrice::loadPricesForRecordSetArray($productArray, false);
     // load child products
     if (isset($displayedColumns['Product.parentID'])) {
         ProductSet::loadVariationTypesForProductArray($productArray);
         ProductSet::loadChildrenForProductArray($productArray);
     }
     $defCurrency = $this->application->getDefaultCurrencyCode();
     foreach ($productArray as &$product) {
         foreach ($this->getUserGroups() as $groupID => $groupName) {
             if (isset($product['priceRules'][$defCurrency][1][$groupID])) {
                 $product['GroupPrice'][$groupID] = $product['priceRules'][$defCurrency][1][$groupID];
             }
         }
     }
     return $productArray;
 }
Example #6
0
 protected function productListBlock()
 {
     // get list items
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ProductList', 'categoryID'), $this->getCategory()->getID()));
     $f->setOrder(new ARFieldHandle('ProductList', 'position'));
     $f->setOrder(new ARFieldHandle('ProductListItem', 'productListID'));
     $f->setOrder(new ARFieldHandle('ProductListItem', 'position'));
     $items = array();
     foreach (ActiveRecordModel::getRecordSetArray('ProductListItem', $f, array('ProductList', 'Product', 'ProductImage')) as $item) {
         $entry =& $item['Product'];
         $entry['ProductList'] =& $item['ProductList'];
         $items[] =& $entry;
     }
     ProductSpecification::loadSpecificationForRecordSetArray($items);
     ProductPrice::loadPricesForRecordSetArray($items);
     // sort by lists
     $lists = array();
     foreach ($items as &$item) {
         $lists[$item['ProductList']['ID']][] =& $item;
     }
     $response = new BlockResponse();
     $response->set('lists', $lists);
     return $response;
 }
Example #7
0
 private function getComparedProducts()
 {
     $filter = Category::getRootNode()->getProductFilter(select(IN('Product.ID', $this->getComparedProductIDs())));
     $products = ActiveRecord::getRecordSetArray('Product', $filter, array('Category', 'ProductImage'));
     ProductSpecification::loadSpecificationForRecordSetArray($products, true);
     ProductPrice::loadPricesForRecordSetArray($products);
     return $products;
 }