function update($StoreItemID) { $Model = new mStoreItem($StoreItemID); $Model->{$_POST['field']} = $_POST['value']; $Result['result'] = $Model->save(); $this->output->delete_cache('/'); echo json_encode($Result); }
function addtocart($ProductID) { //Generate a new basket item $Item = new OrderItem(); $Product = new mStoreItem($ProductID); $Item->title($Product->title); $Item->source('shop:' . $Product->id()); $Item->subtitle($Product->description); $Item->quantity(1); $Item->image($Product->main_image()->filename); $Item->hidden(json_encode($Product->_data)); $Item->price($Product->price); $Item->addToOrder(); redirect('/checkout/'); }
function charge() { if (count($this->order->items()) == 0) { redirect(getUrl('basket')); } $this->order->__fromMemory(); $Customer = new mCustomer(); $Customer->email = $_SESSION['mCustomer']['email']; $Customer->lastname = $_SESSION['mCustomer']['lastname']; $Customer->postcode_1 = $_SESSION['mCustomer']['postcode_1']; $Customer->postcode_2 = $_SESSION['mCustomer']['postcode_2']; $Customer->load(); $Customer->__fromMemory(); data('Order', $this->order); data('Customer', $Customer); if (isset($_POST['stripeToken'])) { $API = new stripelib(); $Metadata = array(); foreach ($this->order->_data as $K => $V) { $Metadata['Order: ' . $K] = $V; } foreach ($Customer->_data as $K => $V) { $Metadata['Customer: ' . $K] = $V; } $Result = $API->charge($_POST['stripeToken'], $this->order->getTotal(false), 'Order: ' . $this->order->nice_id, $Metadata); if ($Result === true) { $this->order->payment_method = 'STRIPE'; $this->order->last_4 = substr($_POST['number'], -4, 4); $Customer->save($this->order); //Success! data('Finished', true); $this->display('success'); //Send the user an email $Mailer = new Mailer(); $Mailer->sendCheckoutComplete($Customer, $this->order); //Update availabe numbers foreach ($this->order->items() as $Item) { list($Type, $ID) = explode(':', $Item->source()); if ($Type == 'shop') { $Product = new mStoreItem($ID); $Product->available -= $Item->quantity(); $Product->save(); } } //clear basket and unset $this->order->clear(); $Customer->__clearMemory(); return; } else { $Error = $Result->getMessage(); //Some kind of error, genericly display and register on error handler of some sort data('StripeError', $Error); $this->display('charge'); //print_r($Result); return; } } else { //Not tried to charge $this->display('charge'); } }