Example #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');
    }
		/**
		 * Persist cart via Ajax
		 */
		public function procShopToolUpdateCheckout()
		{
			$cart = NULL;
			try
			{
				$this->persistCart($cart);
			}
			catch(Exception $exception)
			{
				return new Object(-1, $exception->getMessage());
			}

			$this->add('cart', $cart);

			$shippingRepo = new ShippingMethodRepository();
			// Init the list of all available methods
			$shipping_methods = $shippingRepo->getAvailableShippingMethodsAndTheirPrices($this->module_srl, $cart);
			$this->add('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() : '';
			$this->add('selected_shipping_method', $selected_shipping_method);
		}
Example #3
0
 public function getShippingMethodVariant()
 {
     if (!$this->getShippingMethod()->hasVariants()) {
         return null;
     }
     $shipping_variant = $this->getExtra('shipping_variant');
     if (!$shipping_variant) {
         // If a variant hasn't been selected yet, we just return the first one
         $shippingRepo = new ShippingMethodRepository();
         $shipping_methods = $shippingRepo->getAvailableShippingMethodsAndTheirPrices($this->module_srl, $this);
         $available_keys = array_keys($shipping_methods);
         $selected_shipping_method = $this->getShippingMethodName();
         foreach ($available_keys as $key) {
             if (strpos($key, $selected_shipping_method) !== false) {
                 $this->setExtra('shipping_variant', $key);
                 return $key;
             }
         }
     }
     return $shipping_variant;
 }