예제 #1
0
 public function restoreFields($data)
 {
     parent::restoreFields($data);
     if (isset($data['is_variable'])) {
         $this->variable = $data['is_variable'];
     }
 }
예제 #2
0
 /**
  * @param $item Item
  *
  * @return string
  */
 public function getItemValue($item)
 {
     if ($this->value !== '') {
         $value = $this->value;
     } else {
         $value = $item->getMeta($this->attribute->getSlug())->getValue();
     }
     return $this->getAttribute()->getOption($value)->getLabel();
 }
예제 #3
0
파일: Text.php 프로젝트: jigoshop/Jigoshop2
 public function __construct($exists = false)
 {
     parent::__construct($exists);
 }
예제 #4
0
 /**
  * Displays the page.
  */
 public function display()
 {
     Render::output('admin/product_attributes', array('messages' => $this->messages, 'attributes' => $this->productService->findAllAttributes(), 'types' => Attribute::getTypes()));
 }
예제 #5
0
 /**
  * Adds variable options to attribute field.
  *
  * @param Attribute|Attribute\Variable $attribute Attribute.
  */
 public function addVariableAttributeOptions(Attribute $attribute)
 {
     if ($attribute instanceof Attribute\Variable) {
         /** @var $attribute Attribute|Attribute\Variable */
         Forms::checkbox(array('name' => 'product[attributes][' . $attribute->getId() . '][is_variable]', 'id' => 'product_attributes_' . $attribute->getId() . '_variable', 'classes' => array('attribute-options'), 'label' => __('Is for variations?', 'jigoshop'), 'checked' => $attribute->isVariable(), 'size' => 6));
     }
 }
예제 #6
0
 /**
  * Saves attribute to database.
  *
  * @param Attribute $attribute Attribute to save.
  *
  * @return \Jigoshop\Entity\Product\Attribute Saved attribute.
  */
 public function saveAttribute(Attribute $attribute)
 {
     $wpdb = $this->wp->getWPDB();
     $data = array('label' => $attribute->getLabel(), 'slug' => $attribute->getSlug(), 'type' => $attribute->getType(), 'is_local' => $attribute->isLocal());
     if ($attribute->getId()) {
         $wpdb->update($wpdb->prefix . 'jigoshop_attribute', $data, array('id' => $attribute->getId()));
     } else {
         $wpdb->insert($wpdb->prefix . 'jigoshop_attribute', $data);
         $attribute->setId($wpdb->insert_id);
     }
     $this->wp->doAction('jigoshop\\attribute\\save', $attribute);
     $this->removeAllAttributesExcept($attribute->getId(), array_map(function ($item) {
         /** @var $item Attribute\Option */
         return $item->getId();
     }, $attribute->getOptions()));
     foreach ($attribute->getOptions() as $option) {
         /** @var $option Attribute\Option */
         $data = array('attribute_id' => $option->getAttribute()->getId(), 'label' => $option->getLabel(), 'value' => $option->getValue());
         if ($option->getId()) {
             $wpdb->update($wpdb->prefix . 'jigoshop_attribute_option', $data, array('id' => $option->getId()));
         } else {
             $wpdb->insert($wpdb->prefix . 'jigoshop_attribute_option', $data);
             $option->setId($wpdb->insert_id);
         }
     }
     return $attribute;
 }
예제 #7
0
 /**
  * @param Product\Attribute $attribute
  * @param Product           $product
  */
 public function addAttributes($attribute, $product)
 {
     if ($attribute instanceof Product\Attribute\Variable && $product instanceof Product\Variable) {
         /** @var $attribute Product\Attribute|Product\Attribute\Variable */
         /** @var $product Product|Product\Variable */
         if (isset($_POST['options']) && isset($_POST['options']['is_variable'])) {
             $attribute->setVariable($_POST['options']['is_variable'] === 'true');
         }
         if ($attribute->isVariable()) {
             foreach ($product->getVariations() as $variation) {
                 /** @var $variation VariableProduct\Variation */
                 if (!$variation->hasAttribute($attribute->getId())) {
                     $variableAttribute = new VariableProduct\Attribute();
                     $variableAttribute->setAttribute($attribute);
                     $variableAttribute->setVariation($variation);
                     $variation->addAttribute($variableAttribute);
                 }
             }
         }
     }
 }