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(); } } } }
private function save(RecurringProductPeriod $rpp) { $request = $this->getRequest(); $validator = $this->createFormValidator($rpp->toArray()); if ($validator->isValid()) { $rpp->loadRequestData($this->request); // null value is not set by loadRequestData().. $rebillCount = $this->request->get('rebillCount'); $rebillCount = floor($rebillCount); $rpp->rebillCount->set(is_numeric($rebillCount) && $rebillCount <= 0 ? $rebillCount : NULL); $rpp->save(); $product = $rpp->product->get(); $currencies = array(); foreach ($this->application->getCurrencyArray(true) as $currency) { if (array_key_exists($currency, $currencies) == false) { $currencies[$currency] = Currency::getInstanceByID($currency); } foreach (array(ProductPrice::TYPE_SETUP_PRICE => $request->get('ProductPrice_setup_price_' . $currency), ProductPrice::TYPE_PERIOD_PRICE => $request->get('ProductPrice_period_price_' . $currency)) as $type => $value) { $price = ProductPrice::getInstance($product, $currencies[$currency], $rpp, $type); if (strlen($value) == 0 && $price->isExistingRecord()) { $price->delete(); } else { $price->price->set($value); $price->save(); } } } return new JSONResponse(array('rpp' => $rpp->toArray()), 'success'); } else { return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_not_save_recurring_product_period_entry')); } }