Example #1
0
 public function index()
 {
     $this->loadLanguageFile('Category');
     $product = Product::getInstanceByID($this->request->get('id'), Product::LOAD_DATA, array('ProductImage', 'Manufacturer', 'Category'));
     $this->product = $product;
     if (!$product->isEnabled->get() || $product->parent->get()) {
         throw new ARNotFoundException('Product', $product->getID());
     }
     $product->loadPricing();
     $this->category = $product->getCategory();
     $this->categoryID = $product->getCategory()->getID();
     // get category path for breadcrumb
     $path = $product->category->get()->getPathNodeArray();
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php';
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php';
     foreach ($path as $nodeArray) {
         $url = createCategoryUrl(array('data' => $nodeArray), $this->application);
         if ($nodeArray['isEnabled']) {
             $this->addBreadCrumb($nodeArray['name_lang'], $url);
         }
     }
     // add filters to breadcrumb
     CategoryController::getAppliedFilters();
     // for root category products
     if (!isset($nodeArray)) {
         $nodeArray = array();
     }
     $params = array('data' => $nodeArray, 'filters' => array());
     foreach ($this->filters as $filter) {
         $f = $filter->toArray();
         $params['filters'][] = $f;
         $url = createCategoryUrl($params, $this->application);
         $this->addBreadCrumb($f['name_lang'], $url);
     }
     $productArray = $product->toArray();
     $handle = empty($productArray['URL']) ? $productArray['name_lang'] : $productArray['URL'];
     $this->redirect301($this->request->get('producthandle'), createHandleString($handle));
     //ProductSpecification::loadSpecificationForProductArray($productArray);
     // filter empty attributes
     foreach ($productArray['attributes'] as $key => $attr) {
         if (empty($attr['value']) && empty($attr['values']) && empty($attr['value_lang'])) {
             unset($productArray['attributes'][$key]);
         }
     }
     // attribute summary
     $productArray['listAttributes'] = array();
     foreach ($productArray['attributes'] as $key => $attr) {
         if ($attr['SpecField']['isDisplayedInList']) {
             $productArray['listAttributes'][] = $attr;
         }
         if (!$attr['SpecField']['isDisplayed']) {
             unset($productArray['attributes'][$key]);
         }
     }
     // add product title to breacrumb
     $this->addBreadCrumb($productArray['name_lang'], createProductUrl(array('product' => $productArray), $this->application));
     // manufacturer filter
     if ($product->manufacturer->get()) {
         $manFilter = new ManufacturerFilter($product->manufacturer->get()->getID(), $product->manufacturer->get()->name->get());
     }
     // get category page route
     end($this->breadCrumb);
     $last = prev($this->breadCrumb);
     $catRoute = $this->router->getRouteFromUrl($last['url']);
     $response = new ActionResponse();
     $response->set('product', $productArray);
     $response->set('category', $productArray['Category']);
     $response->set('quantity', $this->getQuantities($product));
     $response->set('currency', $this->request->get('currency', $this->application->getDefaultCurrencyCode()));
     $response->set('catRoute', $catRoute);
     // ratings
     if ($this->config->get('ENABLE_RATINGS')) {
         if ($product->ratingCount->get() > 0) {
             // rating summaries
             ClassLoader::import('application.model.product.ProductRatingSummary');
             $response->set('rating', ProductRatingSummary::getProductRatingsArray($product));
         }
         ClassLoader::import('application.model.category.ProductRatingType');
         $ratingTypes = ProductRatingType::getProductRatingTypeArray($product);
         $response->set('ratingTypes', $ratingTypes);
         $response->set('ratingForm', $this->buildRatingForm($ratingTypes, $product));
         $response->set('isRated', $this->isRated($product));
         $response->set('isLoginRequiredToRate', $this->isLoginRequiredToRate());
         $response->set('isPurchaseRequiredToRate', $this->isPurchaseRequiredToRate($product));
     }
     // add to cart form
     $response->set('cartForm', $this->buildAddToCartForm($this->getOptions(), $this->getVariations()));
     // related products
     $related = $this->getRelatedProducts($product);
     // items purchased together
     $together = $product->getProductsPurchasedTogether($this->config->get('NUM_PURCHASED_TOGETHER'), true);
     $spec = array();
     foreach ($related as $key => $group) {
         foreach ($related[$key] as $i => &$prod) {
             $spec[] =& $related[$key][$i];
         }
     }
     foreach ($together as &$prod) {
         $spec[] =& $prod;
     }
     ProductSpecification::loadSpecificationForRecordSetArray($spec);
     $response->set('related', $related);
     $response->set('together', $together);
     if (isset($manFilter)) {
         $response->set('manufacturerFilter', $manFilter);
     }
     $response->set('variations', $this->getVariations());
     // reviews
     if ($this->config->get('ENABLE_REVIEWS') && $product->reviewCount->get() && ($numReviews = $this->config->get('NUM_REVIEWS_IN_PRODUCT_PAGE'))) {
         $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ProductReview', 'isEnabled'), true));
         $f->setLimit($numReviews);
         $reviews = $product->getRelatedRecordSetArray('ProductReview', $f);
         $this->pullRatingDetailsForReviewArray($reviews);
         $response->set('reviews', $reviews);
     }
     // bundled products
     if ($product->isBundle()) {
         $bundleData = ProductBundle::getBundledProductArray($product);
         $bundledProducts = array();
         foreach ($bundleData as &$bundled) {
             $bundledProducts[] =& $bundled['RelatedProduct'];
         }
         ProductPrice::loadPricesForRecordSetArray($bundledProducts);
         $response->set('bundleData', $bundleData);
         $currency = Currency::getInstanceByID($this->getRequestCurrency());
         $total = ProductBundle::getTotalBundlePrice($product, $currency);
         $response->set('bundleTotal', $currency->getFormattedPrice($total));
         $saving = $total - $product->getPrice($currency);
         $response->set('bundleSavingTotal', $currency->getFormattedPrice($saving));
         $response->set('bundleSavingPercent', $total ? round($saving / $total * 100) : 0);
     }
     // contact form
     if ($this->config->get('PRODUCT_INQUIRY_FORM')) {
         $response->set('contactForm', $this->buildContactForm());
     }
     // display theme
     if ($theme = CategoryPresentation::getThemeByProduct($product)) {
         if ($theme->getTheme()) {
             $this->application->setTheme($theme->getTheme());
         }
         $response->set('presentation', $theme->toFlatArray());
     }
     // product images
     $images = $product->getImageArray();
     if ($theme && $theme->isVariationImages->get()) {
         if ($variations = $this->getVariations()) {
             foreach ($variations['products'] as $prod) {
                 if (!empty($prod['DefaultImage']['ID'])) {
                     $images[] = $prod['DefaultImage'];
                 }
             }
         }
     }
     $response->set('images', $images);
     // discounted pricing
     $response->set('quantityPricing', $product->getPricingHandler()->getDiscountPrices($this->user, $this->getRequestCurrency()));
     $response->set('files', $this->getPublicFiles());
     // additional categories
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('Category', 'lft'));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true));
     $pathC = new OrChainCondition();
     $pathF = new ARSelectFilter($pathC);
     $categories = array();
     foreach ($product->getRelatedRecordSetArray('ProductCategory', $f, array('Category')) as $cat) {
         $categories[] = array($cat['Category']);
         $cond = new OperatorCond(new ARFieldHandle('Category', 'lft'), $cat['Category']['lft'], "<");
         $cond->addAND(new OperatorCond(new ARFieldHandle('Category', 'rgt'), $cat['Category']['rgt'], ">"));
         $pathC->addAnd($cond);
     }
     if ($categories) {
         $pathF->setOrder(new ARFieldHandle('Category', 'lft'), 'DESC');
         $pathF->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true));
         foreach (ActiveRecordModel::getRecordSetArray('Category', $pathF, array('Category')) as $parent) {
             if (!$parent['isEnabled']) {
                 continue;
             }
             foreach ($categories as &$cat) {
                 if ($cat[0]['lft'] > $parent['lft'] && $cat[0]['rgt'] < $parent['rgt'] && $parent['ID'] > Category::ROOT_ID) {
                     $cat[] = $parent;
                 }
             }
         }
         foreach ($categories as &$cat) {
             $cat = array_reverse($cat);
         }
         $response->set('additionalCategories', $categories);
     }
     $response->set('enlargeProductThumbnailOnMouseOver', $this->config->get('_ENLARGE_PRODUCT_THUMBNAILS_ON') == 'P_THUMB_ENLARGE_MOUSEOVER');
     return $response;
 }
Example #2
0
 public function getPathNodeCondition()
 {
     $className = get_class($this);
     $leftValue = $this->getFieldValue(self::LEFT_NODE_FIELD_NAME);
     $rightValue = $this->getFieldValue(self::RIGHT_NODE_FIELD_NAME);
     $cond = new OperatorCond(new ARFieldHandle($className, self::LEFT_NODE_FIELD_NAME), $leftValue, "<=");
     $cond->addAND(new OperatorCond(new ARFieldHandle($className, self::RIGHT_NODE_FIELD_NAME), $rightValue, ">="));
     return $cond;
 }