private function getProductEntry($row, $params) { $row['name'] = unserialize($row['name']); $row = MultilingualObject::transformArray($row, ActiveRecord::getSchemaInstance('Product')); return array('loc' => $this->router->createFullUrl(createProductUrl(array('product' => $row), $this->application))); }
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; }
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; }
/** * Generates product page URL * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_productUrl($params, LiveCartSmarty $smarty) { return createProductUrl($params, $smarty->getApplication()); }
private function setupBreadcrumb($productArray) { include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php'; $nodeArray = $this->addCategoriesToBreadCrumb($this->product->category->get()->getPathNodeArray()); $this->addFiltersToBreadCrumb($nodeArray); $this->addBreadCrumb($productArray['name_lang'], createProductUrl(array('product' => $productArray), $this->application)); }
/** * Generates product page URL * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_productUrl($params, Smarty_Internal_Template $smarty) { return createProductUrl($params, $smarty->getApplication()); }