Example #1
0
 /**
  * Get product URL
  *
  * @param \XLite\Model\Product $product    Product object
  * @param integer              $categoryId Category ID
  *
  * @return string
  */
 protected function getProductURL(\XLite\Model\Product $product, $categoryId = null)
 {
     $params = array();
     $params['product_id'] = $product->getProductId();
     if ($categoryId) {
         $found = false;
         $firstId = null;
         $productCategories = $product->getCategories();
         if ($productCategories && (1 < count($productCategories) || LC_USE_CLEAN_URLS && !(bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'use_canonical_urls_only')))) {
             foreach ($productCategories as $category) {
                 if (!isset($firstId)) {
                     $firstId = $category->getCategoryId();
                 }
                 if ($category->getCategoryId() == $categoryId) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $categoryId = $firstId;
             }
         } else {
             $categoryId = null;
         }
         if ($categoryId) {
             $params['category_id'] = $categoryId;
         }
     }
     return \XLite\Core\Converter::buildURL('product', '', $params);
 }
Example #2
0
 /**
  * Export categories 
  * 
  * @param \XLite\Model\Product $product Product
  *  
  * @return string
  */
 protected function exportCategories(\XLite\Model\Product $product)
 {
     $paths = array();
     foreach ($product->getCategories() as $category) {
         $paths[] = $category->getStringPath();
     }
     return implode(';', $paths);
 }
 /**
  * {@inheritDoc}
  */
 public function getCategories()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCategories', array());
     return parent::getCategories();
 }
Example #4
0
 /**
  * Is coupon valid for product
  *
  * @param \XLite\Model\Product $product Product
  *
  * @return boolean
  */
 public function isValidForProduct(\XLite\Model\Product $product)
 {
     $result = true;
     if (0 < count($this->getProductClasses())) {
         // Check product class
         $result = $product->getProductClass() && $this->getProductClasses()->contains($product->getProductClass());
     }
     if ($result && 0 < count($this->getCategories())) {
         // Check categories
         $result = false;
         foreach ($product->getCategories() as $category) {
             if ($this->getCategories()->contains($category)) {
                 $result = true;
                 break;
             }
         }
     }
     return $result;
 }
 /**
  * Return true if specified product assigned to multiple categories
  * (when cleanURL is enabled, URL for products should be built with category path)
  *
  * @param \XLite\Model\Product $product Product
  *
  * @return boolean
  */
 protected function isProductHasMultipleCategories($product)
 {
     $result = LC_USE_CLEAN_URLS && !(bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'use_canonical_urls_only'));
     if (!$result) {
         $categories = $product->getCategories();
         $result = 1 < count($categories);
     }
     return $result;
 }