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'));
     }
 }