예제 #1
0
    /**
     * display shop checkout
     * @return Object
     * @throws ShopException
     */
    public function dispShopCheckout()
    {
        try {
            /** @var $cart Cart */
            if (!(($cart = Context::get('cart')) instanceof Cart)) throw new ShopException("No cart, you shouldn't be in the checkout page");

            $products = $cart->getProducts(null, true);
            if (empty($products)) {
                throw new ShopException('Cart is empty, you have nothing to checkout');
            }
        }
        catch (Exception $e) {
            $this->setRedirectUrl(getNotEncodedUrl('', 'act', 'dispShopHome'));
            return new Object(-1, $e->getMessage());
        }

        $shippingRepo = new ShippingMethodRepository();
        $paymentRepo = new PaymentMethodRepository();

		// Init the list of all available methods
		$shipping_methods = $shippingRepo->getAvailableShippingMethodsAndTheirPrices($this->module_srl, $cart);
        Context::set('shipping_methods', $shipping_methods);

		// Setup the selected shipping method - check if using default value or value from cart;
		$selected_shipping_method = $cart->getShippingMethodName();
		$selected_shipping_method .= $cart->getShippingMethodVariant() ? '__' . $cart->getShippingMethodVariant() : '';
		Context::set('selected_shipping_method', $selected_shipping_method);

        // payment methods
        $payment_methods = $paymentRepo->getActivePaymentMethods($this->module_srl);
        Context::set('payment_methods', $payment_methods);

        Context::set('addresses', $cart->getAddresses());
        Context::set('default_billing', $cart->getBillingAddress());
        Context::set('default_shipping', $cart->getShippingAddress());
        Context::set('needs_new_shipping', $cart->getBillingAddress() != $cart->getShippingAddress());
        Context::set('extra', $cart->getExtraArray());
        Context::set('cart_products', $products);
        if ($discount = $cart->getDiscount()) {
            Context::set('discount', $discount);
            Context::set('discount_value', $discount->getReductionValue());
            Context::set('discounted_value', $discount->getValueDiscounted());
        }
        $this->setTemplateFile('checkout.html');
    }