|
| 1 | +<?php |
| 2 | + function perch_shop_form_handler($SubmittedForm) |
| 3 | + { |
| 4 | + if ($SubmittedForm->validate()) { |
| 5 | + |
| 6 | + $API = new PerchAPI(1.0, 'perch_shop'); |
| 7 | + $ShopRuntime = PerchShop_Runtime::fetch(); |
| 8 | + |
| 9 | + switch($SubmittedForm->formID) { |
| 10 | + case 'cart': |
| 11 | + $ShopRuntime->update_cart_from_form($SubmittedForm); |
| 12 | + break; |
| 13 | + |
| 14 | + case 'discount_code': |
| 15 | + $ShopRuntime->set_discount_code_from_form($SubmittedForm); |
| 16 | + break; |
| 17 | + |
| 18 | + case 'location': |
| 19 | + $ShopRuntime->set_location_from_form($SubmittedForm); |
| 20 | + break; |
| 21 | + |
| 22 | + case 'currency': |
| 23 | + $ShopRuntime->set_currency_from_form($SubmittedForm); |
| 24 | + break; |
| 25 | + |
| 26 | + case 'shipping_method': |
| 27 | + $ShopRuntime->set_shipping_method_from_form($SubmittedForm); |
| 28 | + break; |
| 29 | + |
| 30 | + case 'add_to_cart': |
| 31 | + $ShopRuntime->add_to_cart_from_form($SubmittedForm); |
| 32 | + break; |
| 33 | + |
| 34 | + case 'order_address': |
| 35 | + $ShopRuntime->set_addresses_from_form($SubmittedForm); |
| 36 | + break; |
| 37 | + |
| 38 | + case 'address': |
| 39 | + $ShopRuntime->edit_address_from_form($SubmittedForm); |
| 40 | + break; |
| 41 | + |
| 42 | + case 'register': |
| 43 | + $ShopRuntime->register_customer_from_form($SubmittedForm); |
| 44 | + break; |
| 45 | + |
| 46 | + case 'profile': |
| 47 | + $ShopRuntime->update_customer_from_form($SubmittedForm); |
| 48 | + break; |
| 49 | + } |
| 50 | + |
| 51 | + // For all forms |
| 52 | + $ShopRuntime->set_cart_properties_from_form($SubmittedForm); |
| 53 | + |
| 54 | + $Tag = $SubmittedForm->get_form_attributes(); |
| 55 | + if ($Tag && $Tag->next()) { |
| 56 | + $Perch = Perch::fetch(); |
| 57 | + if (!$Perch->get_form_errors($SubmittedForm->formID)) { |
| 58 | + PerchUtil::redirect($Tag->next()); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + $Perch = Perch::fetch(); |
| 64 | + $errors = $Perch->get_form_errors($SubmittedForm->formID); |
| 65 | + if ($errors) PerchUtil::debug($errors); |
| 66 | + } |
| 67 | + |
| 68 | + function perch_shop_form($template, $return=false) |
| 69 | + { |
| 70 | + $API = new PerchAPI(1.0, 'perch_shop'); |
| 71 | + $Template = $API->get('Template'); |
| 72 | + $Template->set('shop'.DIRECTORY_SEPARATOR.$template, 'shop'); |
| 73 | + $html = $Template->render(array()); |
| 74 | + $html = $Template->apply_runtime_post_processing($html); |
| 75 | + |
| 76 | + if ($return) return $html; |
| 77 | + echo $html; |
| 78 | + } |
| 79 | + |
| 80 | + function perch_shop_location_form($opts=array(), $return=false) |
| 81 | + { |
| 82 | + $API = new PerchAPI(1.0, 'perch_shop'); |
| 83 | + |
| 84 | + $defaults = []; |
| 85 | + $defaults['template'] = 'tax/location_form.html'; |
| 86 | + |
| 87 | + if (is_array($opts)) { |
| 88 | + $opts = array_merge($defaults, $opts); |
| 89 | + }else{ |
| 90 | + $opts = $defaults; |
| 91 | + } |
| 92 | + |
| 93 | + PerchSystem::set_var('locations_list', PerchShop_TaxLocations::get_list_options()); |
| 94 | + |
| 95 | + $Template = $API->get('Template'); |
| 96 | + $Template->set('shop/'.$opts['template'], 'shop'); |
| 97 | + $html = $Template->render(array()); |
| 98 | + $html = $Template->apply_runtime_post_processing($html); |
| 99 | + |
| 100 | + if ($return) return $html; |
| 101 | + echo $html; |
| 102 | + } |
| 103 | + |
| 104 | + function perch_shop_currency_form($opts=array(), $return=false) |
| 105 | + { |
| 106 | + $API = new PerchAPI(1.0, 'perch_shop'); |
| 107 | + |
| 108 | + $defaults = []; |
| 109 | + $defaults['template'] = 'currencies/currency_form.html'; |
| 110 | + |
| 111 | + if (is_array($opts)) { |
| 112 | + $opts = array_merge($defaults, $opts); |
| 113 | + }else{ |
| 114 | + $opts = $defaults; |
| 115 | + } |
| 116 | + |
| 117 | + PerchSystem::set_var('currency_list', PerchShop_Currencies::get_list_options()); |
| 118 | + |
| 119 | + $Template = $API->get('Template'); |
| 120 | + $Template->set('shop/'.$opts['template'], 'shop'); |
| 121 | + $html = $Template->render(array()); |
| 122 | + $html = $Template->apply_runtime_post_processing($html); |
| 123 | + |
| 124 | + if ($return) return $html; |
| 125 | + echo $html; |
| 126 | + } |
| 127 | + |
| 128 | + function perch_shop_shipping_method_form($opts=array(), $return=false) |
| 129 | + { |
| 130 | + $API = new PerchAPI(1.0, 'perch_shop'); |
| 131 | + |
| 132 | + $defaults = []; |
| 133 | + $defaults['template'] = 'shippings/method_form.html'; |
| 134 | + |
| 135 | + if (is_array($opts)) { |
| 136 | + $opts = array_merge($defaults, $opts); |
| 137 | + }else{ |
| 138 | + $opts = $defaults; |
| 139 | + } |
| 140 | + |
| 141 | + $ShopRuntime = PerchShop_Runtime::fetch(); |
| 142 | + |
| 143 | + PerchSystem::set_var('shippings_list', $ShopRuntime->get_shipping_list_options()); |
| 144 | + |
| 145 | + $Template = $API->get('Template'); |
| 146 | + $Template->set('shop/'.$opts['template'], 'shop'); |
| 147 | + $html = $Template->render(array()); |
| 148 | + $html = $Template->apply_runtime_post_processing($html); |
| 149 | + |
| 150 | + if ($return) return $html; |
| 151 | + echo $html; |
| 152 | + } |
| 153 | + |
0 commit comments