예제 #1
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();
 }
예제 #2
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;
 }