/** * Get paymentplans that are valid for a cost * * The arrays in the result has the following keys: * * - pricePerMonth: Price per month including notificationFee * - contractLength: Number of months the contract will run for * - campaignCode: The campaign code * - isCampaign: If this is a campaign * - description: Translated free text description * - paymentPlan: Svea_Model_PaymentPlan * - notificationFee: Notification fee * - initialFee: Initial fee * * @param $cost The cost in current currency. The value used will be the ciel:ed value of $cost. * @param $storeId The store id * * @returns array List of arrays. */ public function getPaymentPlansForCost($cost, $storeId = null) { if ($storeId === null) { $storeId = Mage::app()->getStore()->getId(); } $latestTimestamp = $this->getLatestUpdateOfPaymentPlanParams($storeId); $paymentPlans = array(); $paymentPlansAsObjects = new stdClass(); $paymentPlansAsObjects->campaignCodes = array(); foreach (Mage::getModel('svea_webpay/paymentplan')->getCollection()->addFieldToFilter('timestamp', $latestTimestamp) as $paymentPlan) { // XXX: it _is_ called 'campaincode' without 'g' in the database $campaignCode = $paymentPlan->getData('campaincode'); $paymentPlans[$campaignCode] = $paymentPlan; $paymentPlansAsObjects->campaignCodes[$campaignCode] = $paymentPlan->asSveaResponse(); } $validPaymentPlans = array(); foreach (WebPay::paymentPlanPricePerMonth($cost, $paymentPlansAsObjects)->values as $validCampaign) { $campaignCode = $validCampaign['campaignCode']; $paymentPlan = $paymentPlans[$campaignCode]; $validCampaign['paymentPlan'] = $paymentPlan; $validCampaign['contractLength'] = $paymentPlan->contractlength; $validCampaign['notificationFee'] = $paymentPlan->notificationfee; $validCampaign['initialFee'] = $paymentPlan->initialfee; // XXX: This rounding was present in previous code, however, I don't // know _how_ it should be rounded(UP, DOWN etc). $validCampaign['pricePerMonth'] = round($validCampaign['pricePerMonth']); $validCampaign['isCampaign'] = $paymentPlan->paymentfreemonths && $paymentPlan->interestfreemonths == $paymentPlan->paymentfreemonths; $validPaymentPlans[] = $validCampaign; } return $validPaymentPlans; }