Exemple #1
0
 public function getOptions($includeInheritedOptions = false)
 {
     ClassLoader::import('application.model.product.ProductOption');
     $f = new ARSelectFilter();
     if ($includeInheritedOptions) {
         $ids = array();
         foreach (array_reverse($this->getPathNodeArray(true)) as $cat) {
             $ids[] = $cat['ID'];
             $f->setOrder(new ARExpressionHandle('ProductOption.categoryID=' . $cat['ID']), 'DESC');
         }
         $f->setCondition(new INCond(new ARFieldHandle('ProductOption', 'categoryID'), $ids));
     } else {
         $f->setCondition(new EqualsCond(new ARFieldHandle('ProductOption', 'categoryID'), $this->getID()));
     }
     $f->setOrder(new ARFieldHandle('ProductOption', 'position'), 'ASC');
     return ProductOption::getRecordSet($f, array('ProductOptionChoice'));
 }
Exemple #2
0
 public static function loadOptionsForProductSet(ARSet $products)
 {
     // load category options
     $f = new ARSelectFilter();
     $categories = $productIDs = array();
     foreach ($products as $product) {
         foreach ($product->getAllCategories() as $cat) {
             $categories[$cat->getID()] = $cat;
         }
         $productIDs[] = $product->getID();
         if ($product->parent->get()) {
             $productIDs[] = $product->parent->get()->getID();
         }
     }
     foreach ($categories as $category) {
         if ($category->isLoaded() == false) {
             $category->load();
         }
         $c = new EqualsOrLessCond(new ARFieldHandle('Category', 'lft'), $category->lft->get());
         $c->addAND(new EqualsOrMoreCond(new ARFieldHandle('Category', 'rgt'), $category->rgt->get()));
         if (!isset($categoryCond)) {
             $categoryCond = $c;
         } else {
             $categoryCond->addOR($c);
         }
     }
     // product options
     $productCond = new INCond(new ARFieldHandle('ProductOption', 'productID'), $productIDs);
     if (!isset($categoryCond)) {
         $categoryCond = $productCond;
     } else {
         $categoryCond->addOR($productCond);
     }
     $f->setCondition($categoryCond);
     // ordering
     $f->setOrder(new ARFieldHandle('ProductOption', 'productID'), 'DESC');
     $f->setOrder(new ARFieldHandle('Category', 'lft'), 'DESC');
     $f->setOrder(new ARFieldHandle('ProductOption', 'position'), 'DESC');
     $options = ProductOption::getRecordSet($f, array('DefaultChoice' => 'ProductOptionChoice', 'Category'));
     self::loadChoicesForRecordSet($options);
     // sort by products
     $sorted = array();
     foreach ($products as $product) {
         foreach ($options as $index => $option) {
             if ($option->product->get() && ($option->product->get()->getID() == $product->getID() || $product->parent->get() && $option->product->get()->getID() == $product->parent->get()->getID())) {
                 $sorted[$product->getID()][] = $option;
             }
             if ($option->category->get()) {
                 $option->category->get()->load();
                 foreach ($product->getAllCategories() as $category) {
                     if ($option->category->get()->isAncestorOf($category)) {
                         $sorted[$product->getID()][] = $option;
                         break;
                     }
                 }
             }
         }
     }
     return $sorted;
 }