Esempio n. 1
0
 public static function getStateIDByName($countryCode, $name)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('State', 'countryID'), $countryCode));
     $nameCond = new EqualsCond(new ARFieldHandle('State', 'name'), $name);
     $nameCond->addOr(new EqualsCond(new ARFieldHandle('State', 'code'), $name));
     $f->mergeCondition($nameCond);
     $f->setOrder(new ARFieldHandle('State', 'name'));
     $f->setLimit(1);
     $stateArray = ActiveRecordModel::getRecordSetArray('State', $f);
     if ($stateArray) {
         return $stateArray[0]['ID'];
     } else {
         return null;
     }
 }
Esempio n. 2
0
 public function getProductCondition($includeSubcategories = false)
 {
     if ($includeSubcategories) {
         if (!$this->isRoot()) {
             $cond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $this->lft->get());
             $cond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $this->rgt->get()));
             if ($this->hasProductsAsSecondaryCategory()) {
                 $cond->addOr(new INCond(new ARFieldHandle('Product', 'ID'), 'SELECT ProductCategory.productID FROM ProductCategory LEFT JOIN Category ON ProductCategory.categoryID=Category.ID WHERE Category.lft>=' . $this->lft->get() . ' AND Category.rgt<=' . $this->rgt->get()));
             }
         } else {
             $cond = new IsNotNullCond(new ARFieldHandle('Product', 'categoryID'));
         }
     } else {
         $cond = new EqualsCond(new ARFieldHandle('Product', 'categoryID'), $this->getID());
         if ($this->hasProductsAsSecondaryCategory()) {
             $cond->addOr(new INCond(new ARFieldHandle('Product', 'ID'), 'SELECT ProductCategory.productID FROM ProductCategory WHERE ProductCategory.categoryID=' . $this->getID()));
         }
     }
     return $cond;
 }