Example #1
0
 /**
  * Assign attribute condition
  *
  * @param \XLite\Model\Attribute $attribute Attribute
  * @param mixed                  $value     Value
  *
  * @return void
  */
 public function assignAttributeCondition(\XLite\Model\Attribute $attribute, $value)
 {
     $result = null;
     $alias = 'av' . $attribute->getId();
     $getConditionFunc = 'getCondition' . $attribute->getTypes($attribute->getType(), true);
     $where = $this->{$getConditionFunc}($attribute, $value, $alias);
     if ($where) {
         if (is_array($where)) {
             foreach ($where as $w) {
                 $this->andWhere($w);
             }
         } else {
             $this->andWhere($where);
         }
         $attr = 'attribute' . $attribute->getId();
         $this->leftJoin('p.attributeValue' . $attribute->getType(), $alias, 'WITH', $alias . '.attribute = :' . $attr);
         $this->setParameter($attr, $attribute);
         if ($attribute::TYPE_SELECT == $attribute->getType()) {
             $this->leftJoin($alias . '.attribute_option', $alias . 'o');
         }
     }
 }
Example #2
0
 /**
  * Get attribute value
  *
  * @param \XLite\Model\Attribute $attribute Attribute
  *
  * @return mixed
  */
 public function getAttributeValue(\XLite\Model\Attribute $attribute)
 {
     $result = null;
     foreach ($this->getValues() as $v) {
         if ($v->getAttribute()->getId() == $attribute->getId()) {
             $result = $v;
             break;
         }
     }
     return $result;
 }
Example #3
0
 /**
  * Get attribute column data
  *
  * @param \XLite\Model\Attribute $attribute Attribute object
  *
  * @return array
  */
 protected function getAttributeColumn($attribute)
 {
     return array(static::COLUMN_GETTER => 'getAttributeColumnValue', 'attributeId' => $attribute->getId(), 'attributeName' => $attribute->getName(), 'attributeGroup' => $attribute->getAttributeGroup() ? $attribute->getAttributeGroup()->getName() : '', 'attributeIsProduct' => (bool) $attribute->getProduct(), 'attributeIsClass' => (bool) $attribute->getProductClass());
 }
Example #4
0
 /**
  * Return attribute options by category
  *
  * @param \XLite\Model\Attribute $attribute Attribute
  *
  * @return array
  */
 public function getAttributeOptionsByAttribute(\XLite\Model\Attribute $attribute)
 {
     $config = \XLite\Core\Config::getInstance()->XC->ProductFilter;
     if ($config->attributes_filter_by_category) {
         $list = null;
         $languageCode = $this->getTranslationCode();
         if ($config->attributes_filter_cache_mode) {
             $data = $this->getAttributeOptionsFromCache();
             if (empty($data) || !is_array($data)) {
                 $data = array($languageCode => array());
             } elseif (!isset($data[$languageCode])) {
                 $data[$languageCode] = array();
             }
             if (isset($data[$languageCode][$attribute->getId()])) {
                 $list = $data[$languageCode][$attribute->getId()];
             }
         }
         if (null === $list) {
             $list = array();
             $options = \XLite\Core\Database::getRepo('XLite\\Model\\AttributeValue\\AttributeValueSelect')->createQueryBuilder('av')->linkInner('av.product')->linkInner('product.categoryProducts')->andWhere('categoryProducts.category = :category AND av.attribute = :attribute')->setParameter('category', $this)->setParameter('attribute', $attribute)->groupBy('av.attribute_option')->getResult();
             foreach ($options as $option) {
                 $list[$option->getAttributeOption()->getId()] = $option->getAttributeOption()->getName();
             }
             if ($config->attributes_filter_cache_mode) {
                 $data[$languageCode][$attribute->getId()] = $list;
                 $this->saveAttributeOptionsInCache($data);
             }
         }
     } else {
         $list = array();
         foreach ($attribute->getAttributeOptions() as $option) {
             $list[$option->getId()] = $option->getName();
         }
     }
     return $list;
 }
Example #5
0
 /**
  * Attribute is checked flag
  *
  * @param \XLite\Model\Attribute $attribute Attribute
  *
  * @return boolean
  */
 protected function isChecked(\XLite\Model\Attribute $attribute)
 {
     return in_array($attribute->getId(), $this->getVariantsAttributeIds());
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }