public function __construct(Product $product, $prices = null, LiveCart $application) { $this->product = $product; $this->application = $application; if (is_null($prices) && $product->getID()) { $prices = $product->getRelatedRecordSet("ProductPrice", new ARSelectFilter()); } if ($prices instanceof ARSet) { foreach ($prices as $price) { $this->setPrice($price); } } else { if (is_array($prices)) { foreach ($prices as $id => $price) { if (array_key_exists('ID', $price)) { $this->prices[$id] = ProductPrice::getInstance($product, Currency::getInstanceById($id)); } else { $this->prices[$id] = ProductPrice::getNewInstance($product, Currency::getInstanceById($id)); } $this->prices[$id]->price->set($price['price']); $this->prices[$id]->listPrice->set($price['listPrice']); $this->prices[$id]->serializedRules->set(serialize($price['serializedRules'])); $this->prices[$id]->resetModifiedStatus(); } } } }
public static function getInstance(Product $product, ProductRatingType $type = null) { $field = new ARFieldHandle(__CLASS__, 'ratingTypeID'); $summary = $product->getRelatedRecordSet(__CLASS__, new ARSelectFilter($type ? new EqualsCond($field, $type->getID()) : new IsNullCond($field))); if ($summary->size()) { return $summary->get(0); } else { return self::getNewInstance($product, $type); } }
private function getVariationTypeByIndex(Product $product, $index) { $f = new ARSelectFilter(); $f->setOrder(new ARFieldHandle('ProductVariationType', 'position')); $f->setLimit(1, $index - 1); if ($product->getID()) { $types = $product->getRelatedRecordSet('ProductVariationType', $f); } if (isset($types) && $types->size()) { return $types->get(0); } else { $type = ProductVariationType::getNewInstance($product); } return $type; }
public static function getProductOptions(Product $product) { $options = $product->getRelatedRecordSet('ProductOption'); self::loadChoicesForRecordSet($options); return $options; }