} else { if (array_key_exists('moodec', $PAGE->theme->layouts)) { $PAGE->set_pagelayout('moodec'); } else { $PAGE->set_pagelayout('standard'); } } $PAGE->set_title(get_string('cart_title', 'local_moodec')); $PAGE->set_heading(get_string('cart_title', 'local_moodec')); // Get the renderer for this page $renderer = $PAGE->get_renderer('local_moodec'); // // Check for new items and add to cart // // Get the cart in it's current state $cart = new MoodecCart(); // If we are adding to the cart, process this first if (isset($_POST['action']) && $_POST['action'] === 'addToCart') { // Updates the cart var with the new addition $cart->add($_POST['id']); // redirect back to the course page redirect(new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')); } // If we are adding to the cart, process this first if (isset($_POST['action']) && $_POST['action'] === 'addVariationToCart') { // Updates the cart var with the new addition $cart->add($_POST['id'], $_POST['variation']); // redirect back to the course page redirect(new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')); } if (isset($_POST['action']) && $_POST['action'] === 'removeFromCart') {
if (array_key_exists('moodec', $PAGE->theme->layouts)) { $PAGE->set_pagelayout('moodec'); } else { $PAGE->set_pagelayout('standard'); } } $PAGE->set_title(get_string('checkout_title', 'local_moodec')); $PAGE->set_heading(get_string('checkout_title', 'local_moodec')); $PAGE->navbar->add(get_string('cart_title', 'local_moodec'), new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')); $PAGE->navbar->add(get_string('checkout_title', 'local_moodec')); // Get the renderer for this page $renderer = $PAGE->get_renderer('local_moodec'); // Force the user to login/create an account to access this page require_login(); // Get the cart $cart = new MoodecCart(); if ($cart->is_empty()) { redirect(new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')); } // Check if the products in the cart are valid, store the ones that are not // (so we can notify the user they've been removed) $removedProducts = $cart->refresh(); // Check if a transaction has already been made for this cart if (!!$cart->get_transaction_id()) { // Get the existing transaction if the cart has recorded one $transaction = new MoodecTransaction($cart->get_transaction_id()); // We reset the transaction, in case the items in the cart have changed $transaction->reset(); } else { // Otherwise create a new transaction $transaction = new MoodecTransaction();
<?php /** * Moodec DPS Payment Success * * @package local * @subpackage local_moodec * @author Thomas Threadgold * @copyright 2015 LearningWorks Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(__FILE__) . '/../../../../config.php'; require_once $CFG->dirroot . '/local/moodec/lib.php'; require_login(); // This is the result of the transaction from DPS $data = required_param('result', PARAM_CLEAN); // We instantiate the cart in order to get the transaction id $cart = new MoodecCart(); // Then we can set up the gateway using the cart transaction id $gateway = new MoodecGatewayDPS($cart->get_transaction_id()); // Now handle the data from DPS $gateway->abort($data); redirect(new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')); // PERHAPS MAKE CONFIGURABLE?
function product_button($product) { global $CFG; $cart = new MoodecCart(); if (isloggedin() && is_enrolled(context_course::instance($product->get_course_id(), MUST_EXIST))) { $html = sprintf('<div class="product-form"><button class="product-form__add button--enrolled" disabled="disabled">%s</button></div>', get_string('button_enrolled_label', 'local_moodec')); } else { if ($cart->check($product->get_id())) { // Display 'in cart' button $html = sprintf('<div class="product-single__form"> <a href="%s" class="product-form__add btn button--cart">%s</a> </div>', new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'), get_string('button_in_cart_label', 'local_moodec')); } else { // Check whether this is a simple or variable product if ($product->get_type() === PRODUCT_TYPE_SIMPLE) { // Display simple product 'add to cart' form $html = sprintf('<form action="%s" method="POST" class="product-form"> <input type="hidden" name="action" value="addToCart"> <input type="hidden" name="id" value="%d"> <input type="submit" class="product-form__add" value="%s"> </form>', new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'), $product->get_id(), get_string('button_add_label', 'local_moodec')); } else { // Variable product selection 'add to cart' form $html = sprintf('<form action="%s" method="POST" class="product-form"> <input type="hidden" name="action" value="addVariationToCart"> <select class="product-tier" name="variation">', new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')); // output variations foreach ($product->get_variations() as $variation) { $html .= sprintf('<option value="%d">%s</option>', $variation->get_id(), $variation->get_name()); } // output rest of the form $html .= sprintf(' </select> <input type="hidden" name="id" value="%d"> <input type="submit" class="product-form__add" value="%s"> </form>', $product->get_id(), get_string('button_add_label', 'local_moodec')); } } } return $html; }