/** * Returns the HTML for the Moodec cart review on the checkout page * @param array cart * @param bool is it the checkout page * @return string the HTML output */ function cart_review($cart, $removedProducts = array()) { global $CFG, $USER; // Require Moodec lib require_once $CFG->dirroot . '/local/moodec/lib.php'; // OPEN cart-overview $html = '<div class="cart-overview">'; // Output cart review message $html .= sprintf('<p class="cart-review__message">%s</p>', get_string('checkout_message', 'local_moodec')); if (!!$removedProducts && is_array($removedProducts)) { $html .= '<div class="cart-review__wrapper">'; $html .= sprintf('<p class="cart-review__message--removed">%s</p>', get_string('checkout_removed_courses_label', 'local_moodec')); $html .= '<ul>'; foreach ($removedProducts as $p) { $thisProduct = local_moodec_get_product($p); $html .= sprintf('<li class="cart-review__item--removed">%s</li>', $thisProduct->get_fullname()); } $html .= '</ul></div>'; } if ($cart->is_empty() === false) { $html .= '<ul class="products">'; // Go through each product in the cart foreach ($cart->get() as $pID => $vID) { $product = local_moodec_get_product($pID); $html .= '<li class="product-item">'; // Product title and variation $html .= sprintf('<h4 class="product-title"><a href="%s">%s</a></h4>', new moodle_url($CFG->wwwroot . '/local/moodec/pages/product.php', array('id' => $product->get_id())), $product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_fullname() : $product->get_fullname() . ' - ' . $product->get_variation($vID)->get_name()); // Product price $html .= sprintf('<div class="product-price">%s%.02f</div>', local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')), $product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_price() : $product->get_variation($vID)->get_price()); $html .= '</li>'; } $html .= '</ul>'; // Output cart summary section $html .= '<div class="cart-summary">'; // Cart total price $html .= sprintf('<h3 class="cart-total__label">%s</h3><h3 class="cart-total">%s%01.2f</h3>', get_string('cart_total', 'local_moodec'), local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')), $cart->get_total(false)); $html .= '</div>'; // Return to store button $html .= $this->return_to_store_action(); // Render all active Gateway options if (!!get_config('local_moodec', 'payment_dps_enable')) { $gatewayDPS = new MoodecGatewayDPS($cart->get_transaction_id()); $html .= $gatewayDPS->render(); } if (!!get_config('local_moodec', 'payment_paypal_enable')) { $gatewayPaypal = new MoodecGatewayPaypal($cart->get_transaction_id()); $html .= $gatewayPaypal->render(); } } else { // Empty cart message $html .= sprintf('<p class="cart-mesage--empty">%s</p>', get_string('cart_empty_message', 'local_moodec')); // Return to store button $html .= $this->return_to_store_action(); } // CLOSE cart-overview $html .= '</div>'; return $html; }