Source of file OrderRewardForm.php
Size: 2,323 Bytes - Last Modified: 2021-12-23T10:41:13+00:00
/var/www/docs.ssmods.com/process/src/code/forms/OrderRewardForm.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | <?php class OrderRewardsForm extends Form { public function __construct($controller) { $fields = new FieldSet(); $actions = new FieldSet( new FormAction('submit', 'Get It!') ); parent::__construct($controller, 'OrderRewardsForm', $fields, $actions); } public function forTemplate() { return $this->renderWith(array( $this->class, 'Form' )); } public function RewardItems() { return $this->controller->RewardItems(); } public function RewardsTotalPoints() { return $this->controller->RewardsTotalPoints(); } //called on save and skip public function submit($data, $form) { // if rewards added and get it button clicked then validate and save to order object if (isset($data['action_submit']) && isset($data['Quantity'])) { Session::clear($this->controller->RewardsSessionKey()); foreach ($data['Quantity'] as $ProductID => $quantity) { $item = $this->controller->newReward($ProductID, $quantity); Session::set($this->controller->RewardsSessionKey($ProductID), serialize($item)); } if ($this->controller->RewardsTotalPoints()>Page_Controller::MemberPointsBalance()) { $this->sessionMessage('You do not have enough points to purchase these rewards.', 'error'); Director::redirectBack(); return; } $new_items = $this->controller->RewardItems(); } //delete all existing reward items for this order $order_items = $this->controller->Order()->RewardItems(); foreach ($order_items as $o_item) { $o_item->delete(); } // then flush rewards from session Session::clear($this->controller->RewardsSessionKey()); //then link the reward items to the order if (isset($new_items)) { foreach ($new_items as $item) { $item->write(); } } // then redirect to next step Director::redirect($this->controller->Link().'checkoutstep/orderconfirmationandpayment/'); } public function CheckoutLink() { return CheckoutPage::find_link(); } } |