예제 #1
0
파일: ProductFeed.php 프로젝트: saiber/www
 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']);
     }
 }
예제 #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);
 }
예제 #3
0
파일: Product.php 프로젝트: saiber/livecart
    public function getProductsPurchasedTogether($limit = null, $enabledOnly = false)
    {
        if (0 === $limit) {
            return array();
        }
        if (is_null($limit)) {
            $limit = 0;
        }
        $sql = 'SELECT
					COUNT(*) AS cnt, COALESCE(ParentProduct.ID, OtherItem.productID) AS ID FROM OrderedItem
				LEFT JOIN
					CustomerOrder ON OrderedItem.customerOrderID=CustomerOrder.ID
				LEFT JOIN
					OrderedItem AS OtherItem ON OtherItem.customerOrderID=CustomerOrder.ID
				LEFT JOIN
					Product ON OtherItem.productID=Product.ID
				LEFT JOIN
					Product AS ParentProduct ON Product.parentID=ParentProduct.ID
				WHERE
					CustomerOrder.isFinalized=1 AND OrderedItem.productID=' . $this->getID() . ' AND OtherItem.productID!=' . $this->getID() . ($enabledOnly ? ' AND Product.isEnabled=1' : '') . '
				GROUP
					BY OtherItem.productID
				ORDER BY
					cnt DESC
				LIMIT ' . (int) $limit;
        $products = ActiveRecord::getDataBySql($sql);
        $ids = array();
        $cnt = array();
        foreach ($products as $key => $prod) {
            $ids[] = $prod['ID'];
            $cnt[$prod['ID']] = empty($cnt[$prod['ID']]) ? $prod['cnt'] : $prod['cnt'] + $cnt[$prod['ID']];
        }
        $products = array();
        if ($ids) {
            $products = ActiveRecord::getRecordSetArray('Product', new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'ID'), $ids)), array('DefaultImage' => 'ProductImage'));
            foreach ($products as &$prod) {
                $prod['count'] = $cnt[$prod['ID']];
            }
            usort($products, array($this, 'togetherStatsSort'));
            ProductPrice::loadPricesForRecordSetArray($products);
        }
        return $products;
    }
예제 #4
0
 public function bestsellingProductsBlock()
 {
     ClassLoader::import('application.model.product.ProductFilter');
     $cache = $this->application->getCache();
     $key = array('bestsellers', $this->getCategory()->getID() . '_' . $days);
     if (!$cache->get($key)) {
         $category = $this->getCategory();
         $filter = new ProductFilter($category, new ARSelectFilter());
         $filter->includeSubcategories();
         $filter->setEnabledOnly();
         $selectFilter = $filter->getSelectFilter();
         $selectFilter->setLimit($this->config->get('BESTSELLING_ITEMS_COUNT'));
         $selectFilter->setOrder(new ARExpressionHandle('cnt'), 'DESC');
         $q = new ARSelectQueryBuilder();
         $q->includeTable('Product');
         $q->joinTable('Category', 'Product', 'ID', 'categoryID');
         $q->addField('Product.ID');
         $q->addField(new ARExpressionHandle('(SELECT SUM(count) FROM OrderedItem LEFT JOIN CustomerOrder ON OrderedItem.customerOrderID=CustomerOrder.ID WHERE productID=Product.ID AND CustomerOrder.isPaid=1 AND CustomerOrder.dateCompleted > "' . ARSerializableDateTime::createFromTimeStamp(strtotime('-' . $this->config->get('BESTSELLING_ITEMS_DAYS') . ' days')) . '")'), null, 'cnt');
         $q->setFilter($selectFilter);
         $cache->set($key, ActiveRecord::getDataByQuery($q));
     }
     $products = $cache->get($key);
     if (!$products) {
         return;
     }
     $ids = array();
     foreach ($products as $id) {
         $ids[] = $id['ID'];
     }
     $products = ActiveRecord::getRecordSetArray('Product', select(IN('Product.ID', $ids)), array('DefaultImage' => 'ProductImage'));
     ProductPrice::loadPricesForRecordSetArray($products);
     if ($products) {
         return new BlockResponse('products', $products);
     }
 }
예제 #5
0
 private function getRelatedProducts(Product $product, $type = 0)
 {
     // get related products
     $related = $product->getRelatedProductsWithGroupsArray($type);
     $rel = array();
     foreach ($related as $r) {
         if (!isset($r['RelatedProduct'])) {
             continue;
         }
         $p = $r['RelatedProduct'];
         // @todo: make ActiveRecord automatically recognize the correct parent object
         $p['DefaultImage'] = $r['DefaultImage'];
         if (isset($r['ProductRelationshipGroup'])) {
             $p['ProductRelationshipGroup'] = $r['ProductRelationshipGroup'];
         }
         $rel[] = $p;
     }
     ProductPrice::loadPricesForRecordSetArray($rel);
     // sort related products into groups
     $byGroup = array();
     foreach ($rel as $r) {
         $groupID = isset($r['ProductRelationshipGroup']) ? $r['ProductRelationshipGroup']['ID'] : 0;
         $byGroup[$groupID][] = $r;
     }
     return $byGroup;
 }
예제 #6
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;
 }
예제 #7
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;
 }
예제 #8
0
 private function getFeaturedMainCategoryProducts(&$categories)
 {
     $cache = $this->application->getCache();
     $namespace = 'category_featured';
     $products = array();
     foreach ((array) $categories as $category) {
         $key = array($namespace, $category['ID']);
         if ($product = $cache->get($key)) {
             $products[] = $product;
             continue;
         }
         $cat = Category::getInstanceByID($category['ID'], Category::LOAD_DATA);
         $pf = new ProductFilter($cat, new ARSelectFilter());
         $pf->includeSubcategories();
         $f = $cat->getProductsFilter($pf);
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'isFeatured'), true));
         $f->setLimit(1);
         $f->setOrder(new ARExpressionHandle('RAND()'));
         $product = array_pop(ActiveRecordModel::getRecordSetArray('Product', $f, array('ProductImage', 'Category', 'Manufacturer')));
         if (!$product) {
             $product = array('ID' => 0);
         }
         $cache->set($key, $product, 1800);
         $products[] = $product;
     }
     ProductPrice::loadPricesForRecordSetArray($products);
     foreach ($products as $key => $product) {
         $categories[$key]['featuredProduct'] = $product;
     }
 }
예제 #9
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;
 }
예제 #10
0
 public function get()
 {
     $request = $this->getApplication()->getRequest();
     $product = Product::getInstanceBySku($request->get('SKU'));
     if ($product == null) {
         throw new Exception('Product not found');
     }
     $products = array($product->toArray());
     ProductPrice::loadPricesForRecordSetArray($products);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     foreach ($products as $product) {
         $this->fillSimpleXmlResponseItem($response, $product);
     }
     return new SimpleXMLResponse($response);
 }
예제 #11
0
 public static function loadChildrenForProductArray(&$array)
 {
     $index = self::getProductIndex($array);
     $f = new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'parentID'), array_keys($index)));
     $products = ActiveRecordModel::getRecordSetArray('Product', $f, array('ProductImage'));
     self::loadVariationsForProductArray($products);
     ProductPrice::loadPricesForRecordSetArray($products);
     foreach ($products as $product) {
         $parent =& $index[$product['parentID']];
         $product['Parent'] =& $parent;
         $parent['children'][] = $product;
     }
 }