public function addJson() { $cart = new CartModel(); $cart->loadCurrent(); $entity = Ajde::app()->getRequest()->getPostParam('entity'); $entity_id = Ajde::app()->getRequest()->getPostParam('entity_id'); $qty = Ajde::app()->getRequest()->getPostParam('qty'); $cart->addItem($entity, $entity_id, $qty); return ['success' => true]; }
public function addJson() { Ajde_Model::register($this); $cart = new CartModel(); $cart->loadCurrent(); $entity = Ajde::app()->getRequest()->getPostParam('entity'); $entity_id = Ajde::app()->getRequest()->getPostParam('entity_id'); $qty = Ajde::app()->getRequest()->getPostParam('qty'); $cart->addItem($entity, $entity_id, $qty); return array('success' => true); }
public function checkout() { Ajde_Model::register($this); // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public static function mergeUserToClient() { if ($user = Ajde_User::getLoggedIn()) { // Do we have a saved cart for logged in user? $userCart = new CartModel(); if ($userCart->loadByUser($user)) { // Do we have a saved cart for client? $clientCart = new CartModel(); if ($clientCart->loadByClient() === false) { $clientCart->client = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); $clientCart->insert(); } foreach ($userCart->getItems() as $item) { /* @var $item Ajde_Shop_Cart_Item */ $clientCart->addItem($item->getEntity(), null, $item->getQty()); } $userCart->delete(); } } }
/** * This method reads the e-mail body template and fills it * with the values from the cart and the given information * about the user. * @return HTML e-mail body */ private function createMailBody() { $engine = $this->getTemplateEngine(); // read the template for the e-mail body $msgTpl = $engine->readTemplate(Template::MAIL_ORDER); // create a new CartModel instance to get access to the cart's products $cart = new CartModel(); // write all ordered products in the cart into e-mail $rows = ""; $amount = 0; foreach ($cart->getProducts() as $product) { $rowTpl = $engine->readTemplate(Template::MAIL_ORDER_ROW); $rowTpl = $engine->replaceTag("name", $product->getName(), $rowTpl); $rowTpl = $engine->replaceTag("options", StringUtils::arrangeOptions($product->getProperties()), $rowTpl); $rowTpl = $engine->replaceTag("price", StringUtils::formatAmount($product->getPrice()), $rowTpl); $rows .= $rowTpl; $amount += $product->getPrice(); } // write the POST-ed values into e-mail $msgTpl = $engine->replaceTag("firstname", StringUtils::removeTags($_POST["name-firstname"]), $msgTpl); $msgTpl = $engine->replaceTag("lastname", StringUtils::removeTags($_POST["name-lastname"]), $msgTpl); $msgTpl = $engine->replaceTag("email", StringUtils::removeTags($_POST["name-email"]), $msgTpl); $msgTpl = $engine->replaceTag("address", StringUtils::removeTags($_POST["name-address"]), $msgTpl); $msgTpl = $engine->replaceTag("addressnr", StringUtils::removeTags($_POST["name-addressnr"]), $msgTpl); $msgTpl = $engine->replaceTag("zipcode", StringUtils::removeTags($_POST["name-zipcode"]), $msgTpl); $msgTpl = $engine->replaceTag("city", StringUtils::removeTags($_POST["name-city"]), $msgTpl); $msgTpl = $engine->replaceTag("country", StringUtils::removeTags($_POST["name-country"]), $msgTpl); $msgTpl = $engine->replaceTag("shippingmethod", StringUtils::removeTags($_POST["name-shippingmethod"]), $msgTpl); $msgTpl = $engine->replaceTag("paymentmethod", StringUtils::removeTags($_POST["name-paymentmethod"]), $msgTpl); $msgTpl = $engine->replaceTag("total", StringUtils::formatAmount($amount), $msgTpl); $giftboxYesNo = isset($_POST["name-giftbox"]) ? "yes" : "no"; $msgTpl = $engine->replaceTag("yesno", $giftboxYesNo, $msgTpl); // replace the placeholder in e-mail's template with the product rows $msgTpl = $engine->replaceTag("rows", $rows, $msgTpl); // translate all keys in the template $msgTpl = $this->handleTranslations($msgTpl); // set the table with all informations to the view for displaying it $this->getView()->setTable($msgTpl); return $msgTpl; }
public static function kurangiStok($po_id, $minus = 1, $session = 1) { if ($session) { $arrObjBulk = isset($_SESSION['cartqty_bulk']) ? $_SESSION['cartqty_bulk'] : array(); $arrObjRetail = isset($_SESSION['cartqty']) ? $_SESSION['cartqty'] : array(); } else { $cm = new CartModel(); $cm->getByID($po_id); $arrObjBulk = json_decode($cm->po_pesanan_bulk); $arrObjRetail = json_decode($cm->po_pesanan_retail); } $out_of_stock_ID = array(); //kebutuhan $kebutuhan = array(); //get all product $arrProd = array(); //bulk foreach ($arrObjBulk as $numb => $objb) { if ($session) { $pid = $objb['id']; $qty = $objb['qty']; } else { $pid = $objb->id; $qty = $objb->qty; } if ($pid == "" || $pid < 1) { continue; } $exp = explode(",", $pid); foreach ($exp as $numc => $obj_real) { $p = new ProdModel(); $p->getByID($obj_real); $arrProd[$obj_real] = $p; //cek apakah outof stok $kebutuhan[$obj_real]++; } foreach ($kebutuhan as $obj_real => $jumlah) { $kebutuhan[$obj_real] = $jumlah * $qty; } } //satuan foreach ($arrObjRetail as $num => $obj) { if ($session) { $pid = $obj['id']; $qty = $obj['qty']; } else { $pid = $obj->id; $qty = $obj->qty; } if ($pid == "" || $pid < 1) { continue; } $p = new ProdModel(); $p->getByID($pid); $arrProd[$pid] = $p; $kebutuhan[$pid] += $qty; } //pr($kebutuhan); foreach ($kebutuhan as $pid => $jumlah) { $prod = $arrProd[$pid]; //kalau session ga bisa out of stock if ($prod->prod_stock < $jumlah && $session) { continue; } //isi log $ps = new ProdStok(); $ps->stok_date = leap_mysqldate(); $ps->stok_prev = $prod->prod_stock; $ps->stok_po_id = $po_id; $ps->stok_prod_id = $prod->prod_id; $ps->stok_userid = Account::getMyID(); if ($minus) { //kurangi stok $prod->prod_stock -= $jumlah; } else { $prod->prod_stock += $jumlah; } $prod->load = 1; $prod->save(); $ps->stock_note = "Pemesanan Customer"; if (!$session) { $ps->stock_admin = 1; $ps->stock_note = "Admin Update {$minus}"; } $ps->stok_actual = $prod->prod_stock; if ($ps->stok_prev > $ps->stok_actual) { $ps->stok_debit_credit = 1; } else { $ps->stok_debit_credit = 0; } $ps->save(); } }
public function complete() { $cart = new CartModel(); $cart->loadCurrent(); $cart->emptyItems(); // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); if ($session->has('currentTransaction')) { $transaction->loadByPK($session->get('currentTransaction')); } $session->destroy(); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function checkout() { // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); // Can we skip this step? if (!$transaction->hasLoaded() && !config('shop.offerLogin') && $cart->hasItems()) { $this->redirect('shop/transaction:setup'); } $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function paymentJson() { $request = Ajde::app()->getRequest(); $provider = $request->getPostParam('provider', false); if (empty($provider)) { return array('success' => false, 'message' => __('Please choose a payment provider')); } // Check for current transaction Ajde_Model::register($this); $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { if ($transaction->payment_status !== 'pending') { return array('success' => false, 'message' => __('Payment already initiated, please refresh this page')); } } else { return array('success' => false, 'message' => __('No current transaction found')); } $transaction->payment_provider = $provider; $provider = $transaction->getProvider(); $redirectUrl = $provider->getRedirectUrl(); if ($redirectUrl !== false) { $transaction->payment_status = 'requested'; $transaction->save(); $cart = new CartModel(); $cart->loadCurrent(); $cart->emptyItems(); if ($provider->usePostProxy()) { $this->setAction('postproxy'); $proxy = $this->getView(); $proxy->assign('provider', $provider); return array('success' => true, 'postproxy' => $proxy->render()); } return array('success' => true, 'redirect' => $redirectUrl); } return array('success' => false, 'message' => 'Could not contact the payment provider, please try again'); }
public function deleteOrder() { $po = new CartModel(); $po_id = isset($_GET['po']) ? addslashes($_GET['po']) : die('no id'); $po->getByID($po_id); if ($po->userid != Account::getMyID()) { die('Hacking Attempt'); } $po->payment_status = 4; $po->load = 1; $po->save(); CartWeb::kurangiStok($po_id, 0, 0); header("Location:" . _SPPATH . "myorder"); exit; }
/** * Clean the cart (remove all products). */ public static function clean() { $cm = new CartModel(); $cm->clean(); }
public function setStatus() { $payment_status = isset($_GET['ps']) ? addslashes($_GET['ps']) : die('no ps'); $po_id = isset($_GET['po']) ? addslashes($_GET['po']) : die('no po'); $po = new CartModel(); $po->getByID($po_id); $payment_status_lama = $po->payment_status; if ($payment_status_lama == '3') { //canceled ke gak canceled // kurangi stok CartWeb::kurangiStok($po_id, 1, 0); } if ($payment_status == '3') { //gak canceled ke canceled // release stok //tambah stok CartWeb::kurangiStok($po_id, 0, 0); } if ($payment_status == '1') { //leap mail $lm = new Leapmail(); $lm->senderMail = "*****@*****.**"; $isi .= "Terima Kasih Anda Telah Melakukan Pembayaran \n\n"; $isi .= ""; $isi .= "Detail Pesanan : " . _BPATH . "CartOrder/details?po={$po_id} \n"; $isi .= "Order History : " . _BPATH . "myorder \n\n"; $isi .= "\n\n Pengiriman akan kami jalankan secepatnya."; $isi .= "\n\n Lama delivery sesuai JNE delivery sekitar 3-4 hari untuk paket REGULAR dan 1 hari untuk paket Yakin Esok Sampai."; $isi .= "\n\n Untuk Informasi lebih lanjut bisa melakukan email ke info@b3l1.com"; $lm->sendEmail($po->user_email, "Konfirmasi Pemrosesan Pemesanan Produk B3l1.COM", $isi); } if ($payment_status == '2') { //leap mail $lm = new Leapmail(); $lm->senderMail = "*****@*****.**"; $isi .= "Pengiriman Produk Pesanan Anda Sudah Dilakukan \n\n"; $isi .= ""; $isi .= "Detail Pesanan : " . _BPATH . "CartOrder/details?po={$po_id} \n"; $isi .= "Order History : " . _BPATH . "myorder \n\n"; $isi .= "\n\n Lama delivery sesuai JNE delivery sekitar 3-4 hari untuk paket REGULAR dan 1 hari untuk paket Yakin Esok Sampai."; $isi .= "\n\n Untuk Informasi lebih lanjut bisa melakukan email ke info@b3l1.com"; $lm->sendEmail($po->user_email, "Pengiriman Produk B3l1.COM", $isi); } $po->payment_status = $payment_status; $po->load = 1; $po->save(); }