Beispiel #1
0
 /**
  * Define additional buttons
  *
  * @return array
  */
 protected function defineAdditionalButtons()
 {
     foreach (\XLite\Model\Attribute::getTypes() as $type => $name) {
         $list[] = $this->getWidget(array('label' => $name, 'jsCode' => 'addAttribute(\'' . $type . '\',' . $this->getParam(static::PARAM_LIST_ID) . ')'), 'XLite\\View\\Button\\Regular');
     }
     return $list;
 }
Beispiel #2
0
 /**
  * Get default attributes widgets
  *
  * @return array
  */
 protected function getDefaultWidgets()
 {
     $list = array();
     foreach (\XLite\Model\Attribute::getTypes() as $type => $name) {
         $list[] = $this->getWidget(array(), \XLite\Model\Attribute::getWidgetClass($type));
     }
     return $list;
 }
Beispiel #3
0
 /**
  * Return field class
  *
  * @param \XLite\Model\Attribute $attribute Attribute
  * @param string                 $value     Value
  *
  * @return string
  */
 protected function getFieldClass(\XLite\Model\Attribute $attribute, $value)
 {
     $class = str_replace(' ', '-', strtolower($attribute->getTypes($attribute->getType())));
     if (\XLite\Model\Attribute::TYPE_CHECKBOX == $attribute->getType()) {
         $class .= ' ' . (static::t('Yes') == $value ? 'checked' : 'no-checked');
     }
     return $class;
 }
Beispiel #4
0
 /**
  * Get alll attributes
  *
  * @return array
  */
 public function getAllAttributes()
 {
     $result = array();
     foreach (Attribute::getTypes() as $type => $name) {
         $class = Attribute::getAttributeValueClass($type);
         $result = array_merge($result, Database::getRepo($class)->findAllAttributes($this));
     }
     return $result;
 }
Beispiel #5
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');
         }
     }
 }
Beispiel #6
0
 /**
  * Get default options
  *
  * @return array
  */
 protected function getDefaultOptions()
 {
     return \XLite\Model\Attribute::getTypes();
 }
 /**
  * Get product modifier types
  *
  * @return array
  */
 protected function getProductModifierTypes()
 {
     if (!isset($this->productModifierTypes)) {
         foreach (\XLite\Model\Attribute::getTypes() as $type => $name) {
             $class = \XLite\Model\Attribute::getAttributeValueClass($type);
             if (is_subclass_of($class, 'XLite\\Model\\AttributeValue\\Multiple')) {
                 $modifierTypes = \XLite\Core\Database::getRepo($class)->getModifierTypesByProduct($this->getProduct());
                 foreach ($modifierTypes as $k => $v) {
                     if (!isset($this->productModifierTypes[$k])) {
                         $this->productModifierTypes[$k] = $v;
                     } else {
                         $this->productModifierTypes[$k] = $this->productModifierTypes[$k] || $v;
                     }
                 }
             }
         }
     }
     return $this->productModifierTypes;
 }
Beispiel #8
0
 /**
  * Apply attribute values changes
  *
  * @param array $oldValues Old values
  * @param array $newValues New values
  *
  * @return void
  */
 protected function applyAttributeValuesChanges(array $oldValues, array $newValues)
 {
     $diff = array();
     foreach (\XLite\Model\Attribute::getTypes() as $type => $name) {
         $class = \XLite\Model\Attribute::getAttributeValueClass($type);
         $diff += $class::getDiff($oldValues[$type], $newValues[$type]);
     }
     if ($diff) {
         $i = 0;
         do {
             $processed = 0;
             foreach (\XLite\Core\Database::getRepo('XLite\\Model\\Product')->findFrame($i, static::CHUNK_LENGTH) as $product) {
                 foreach ($diff as $attributeId => $changes) {
                     $attribute = \XLite\Core\Database::getRepo('XLite\\Model\\Attribute')->find($attributeId);
                     $attribute->applyChanges($product, $changes);
                 }
                 $processed++;
             }
             if (0 < $processed) {
                 \XLite\Core\Database::getEM()->flush();
                 \XLite\Core\Database::getEM()->clear();
             }
             $i += $processed;
         } while (0 < $processed);
     }
 }
Beispiel #9
0
 /**
  * Get multiple attributes
  *
  * @return array
  */
 public function getMultipleAttributes()
 {
     $result = array();
     foreach (\XLite\Model\Attribute::getTypes() as $type => $name) {
         $class = \XLite\Model\Attribute::getAttributeValueClass($type);
         if (is_subclass_of($class, 'XLite\\Model\\AttributeValue\\Multiple')) {
             $result = array_merge($result, \XLite\Core\Database::getRepo($class)->findMultipleAttributes($this));
         }
     }
     if ($result) {
         foreach ($result as $k => $v) {
             $result[$k] = $v[0];
         }
     }
     return $result;
 }
Beispiel #10
0
 /**
  * Verify 'type' value
  *
  * @param mixed $value  Value
  * @param array $column Column info
  *
  * @return void
  */
 protected function verifyType($value, array $column)
 {
     if ($this->verifyValueAsEmpty($value) || !\XLite\Model\Attribute::getTypes($value)) {
         $this->addError('ATTR-TYPE-FMT', array('column' => $column, 'value' => $value));
     }
 }