Beispiel #1
0
 private function updateRatings(ARUpdateFilter $f)
 {
     $this->product->get()->updateRecord(clone $f);
     $summary = ProductRatingSummary::getInstance($this->product->get(), $this->ratingType->get());
     if ($summary->getID()) {
         $summary->updateRecord(clone $f);
     }
     if ($this->review->get() && !$this->review->get()->isDeleted()) {
         $this->review->get()->updateRecord(clone $f);
     }
 }
Beispiel #2
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;
 }
Beispiel #3
0
 public function testDelete()
 {
     $type = ProductRatingType::getNewInstance(Category::getRootNode());
     $type->save();
     $type2 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type2->save();
     for ($k = 0; $k <= 1; $k++) {
         $review = ProductReview::getNewInstance($this->product, $this->user);
         $review->save();
         $rating = ProductRating::getNewInstance($this->product, $type);
         $rating->rating->set(6 + $k);
         $rating->review->set($review);
         $rating->save();
         $rating = ProductRating::getNewInstance($this->product, $type2);
         $rating->rating->set(4 + $k);
         $rating->review->set($review);
         $rating->save();
     }
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 4);
     $this->assertEqual($this->product->ratingSum->get(), 22);
     $this->assertEqual($this->product->rating->get(), 5.5);
     // delete last review
     $review->delete();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 2);
     $this->assertEqual($this->product->ratingSum->get(), 10);
     $this->assertEqual($this->product->rating->get(), 5);
     // check rating summaries
     $summary = ProductRatingSummary::getInstance($this->product, $type2);
     $this->assertEqual($summary->rating->get(), 4);
 }
Beispiel #4
0
 public function testRatingTypes()
 {
     $type = ProductRatingType::getNewInstance(Category::getRootNode());
     $type->save();
     $rating = ProductRating::getNewInstance($this->product, $type);
     $rating->rating->set(6);
     $rating->save();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 1);
     $this->assertEqual($this->product->ratingSum->get(), 6);
     $this->assertEqual($this->product->rating->get(), 6);
     ActiveRecord::clearPool();
     $summary = ProductRatingSummary::getInstance($this->product, $type);
     $summary->reload();
     $this->assertEqual($summary->ratingCount->get(), 1);
     $this->assertEqual($summary->ratingSum->get(), 6);
     $this->assertEqual($summary->rating->get(), 6);
     $type2 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type2->save();
     $rating = ProductRating::getNewInstance($this->product, $type2);
     $rating->rating->set(4);
     $rating->save();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 2);
     $this->assertEqual($this->product->ratingSum->get(), 10);
     $this->assertEqual($this->product->rating->get(), 5);
     ActiveRecord::clearPool();
     $summary = ProductRatingSummary::getInstance($this->product, $type2);
     $summary->reload();
     $this->assertEqual($summary->ratingCount->get(), 1);
     $this->assertEqual($summary->ratingSum->get(), 4);
     $this->assertEqual($summary->rating->get(), 4);
 }