/** * Gets the sources registered with the system * * @return unknown */ public static function sources() { $sources = (array) \Base::instance()->get('dsc.search.sources'); $sources = \Dsc\ArrayHelper::sortArrays($sources, 'priority'); // TODO Put the default up top return $sources; }
public function __construct($source = array(), $options = array()) { parent::__construct($source, $options); foreach ($this->attributes as $key => $attribute) { $this->attributes[$key] = (new \Shop\Models\Prefabs\Attribute($attribute))->cast(); foreach ($this->attributes[$key]['options'] as $ao_key => $ao_value) { $this->attributes[$key]['options'][$ao_key] = (new \Shop\Models\Prefabs\AttributeOption($ao_value))->cast(); } } foreach ($this->variants as $key => $variant) { if (empty($this->variants[$key]['id'])) { $this->variants[$key]['id'] = (string) new \MongoId(); } foreach ($this->attributes as $a_key => $attribute) { foreach ($this->attributes[$a_key]['options'] as $ao_key => $ao_value) { if ($this->attributes[$a_key]['options'][$ao_key]['value'] == $variant['price']) { $this->variants[$key]['key'] = $this->attributes[$a_key]['options'][$ao_key]['id']; break 2; } } } } $this->set('shipping.enabled', false); $this->set('policies.track_inventory', false); $this->set('policies.variant_pricing.enabled', true); $this->variants = \Dsc\ArrayHelper::sortArrays(array_values($this->variants), 'ordering'); }
protected function createVariants() { if (!empty($this->variants) && is_array($this->variants)) { $variants = $this->rebuildVariants(); $prev = array_values(array_filter($this->variants)); array_walk($variants, function (&$item, $key) use($prev) { // find the previous version of this variant, if possible foreach ($prev as $p) { if ($p['key'] == $key) { $item = array_merge($item, $p); break; } } }); unset($prev); $this->variants = \Dsc\ArrayHelper::sortArrays(array_values($variants), 'attribute_title'); } if (empty($this->attributes)) { // build the variants array for just the single variant $mongo_id = (string) new \MongoId(); $variant = new \Shop\Models\Prefabs\Variant(array('id' => $mongo_id, 'key' => $mongo_id, 'quantity' => (int) $this->{'quantities.manual'})); $this->variants = array($variant->cast()); } }