public function __construct($attrs = null, $product_id = null) { if ($attrs == null) { return; } $this->product_id = $product_id; if (is_string($attrs['value'])) { $attrs['value'] = array_map('trim', explode('|', $attrs['value'])); } if (intval($attrs['is_taxonomy']) == 1 && $this->product_id) { $cat = new Category(); $cattrs = woocommerce_get_product_terms($this->product_id, $attrs['name'], 'all'); $attrs['value'] = array(); foreach ($cattrs as $catt) { $cat->fromDatabaseResult(Helpers::std2a($catt)); $attrs['value'][] = $cat->asApiArray(); } } $attrs['is_visible'] = $this->toWPBool($attrs['is_visible']); $attrs['is_variation'] = $this->toWPBool($attrs['is_variation']); $attrs['is_taxonomy'] = $this->toWPBool($attrs['is_taxonomy']); $this->attrs = $attrs; Helpers::debug("ProductAttribute::__construct" . var_export($attrs, true)); }
public function getProductAttributes($desc) { $name = "attributes"; // if ( isset($this->_meta_attributes[$name])) { // return $this->_meta_attributes[$name]; // } else { $attrs = maybe_unserialize(get_post_meta($this->_actual_model_id, '_product_attributes', true)); if (is_string($attrs)) { $attrs = explode("|", $attrs); } if (!is_array($attrs)) { return array('error', __('Your attributes could not be decoded by the API')); } foreach ($attrs as &$attr) { if (!$attr) { continue; } if (intval($attr['is_taxonomy']) == 1) { $cat = new Category(); $cattrs = woocommerce_get_product_terms($this->_actual_model_id, $attr['name'], 'all'); $attr['value'] = array(); foreach ($cattrs as $catt) { $cat->fromDatabaseResult(Helpers::std2a($catt)); $attr['value'][] = $cat->asApiArray(); } } foreach (array('is_visible', 'is_variation', 'is_taxonomy') as $key) { if (isset($attr[$key])) { $attr[$key] = Helpers::toWPBool($attr[$key]); } } if (isset($attr['value']) && is_string($attr['value'])) { $attr['value'] = explode("|", $attr['value']); } } $this->_meta_attributes['attributes'] = $attrs; return $this->_meta_attributes['attributes']; //} }