Example #1
0
    /**
     * display shop place order
     * @return Object
     * @throws ShopException
     */
    public function dispShopPlaceOrder()
    {
        /** @var $cart Cart  */
        try {
            if ((!$cart = Context::get('cart')) || !$cart->items) {
                throw new ShopException("Cart doesn't exist anymore.");
            }
        }
        catch (Exception $e) {
            $this->setRedirectUrl(getNotEncodedUrl('', 'act', 'dispShopHome'));
            return new Object(-1, $e->getMessage());
        }

        // 1. Setup payment info
        /**
         * @var shopModel $shopModel
         */
        $shopModel = getModel('shop');

        // Get selected payment method name
        $payment_method_name = $cart->getPaymentMethodName();

        // Get payment class
        $payment_repository = new PaymentMethodRepository();
        $payment_method = $payment_repository->getPaymentMethod($payment_method_name, $this->module_srl);

        $payment_method->onPlaceOrderFormLoad();

        Context::set('payment_method', $payment_method);
        Context::set('payment_method_name', $payment_method_name);

        // 2. Setup all other order info
        Context::set('billing_address', $cart->getBillingAddress());
        Context::set('shipping_address', $cart->getShippingAddress());

        $shipping_method_name = $cart->getShippingMethodName();
        $shipping_repository = new ShippingMethodRepository();
        $shipping_method = $shipping_repository->getShippingMethod($shipping_method_name, $this->module_srl);
        Context::set('shipping_method_name', $shipping_method->getDisplayName());
		$shipping_variants = $shipping_method->getVariants();
		Context::set('shipping_method_variant', $shipping_variants[$cart->getShippingMethodVariant()]);

        Context::set('extra', $cart->getExtraArray());
        Context::set('cart_products', $cart->getProducts());

        if ($discount = $cart->getDiscount()) {
            Context::set('discount', $discount);
            Context::set('discount_value', $discount->getReductionValue());
            Context::set('discounted_value', $discount->getValueDiscounted());
        }

        if ($coupon = $cart->getCoupon()) {
            Context::set('coupon', $coupon);
        }

        $this->setTemplateFile('place_order.html');
    }
        /**
         * activate shipping method
         * @return Object
         */
        public function procShopServiceActivateShippingMethod()
        {
            $name = Context::get('name');
            $status = Context::get('status');

            if(!isset($name) || !isset($status))
            {
                return new Object(-1, 'msg_invalid_request');
            }

            $shipping_repository = new ShippingMethodRepository();
            $shipping_method = $shipping_repository->getShippingMethod($name, $this->module_srl);
            $shipping_method->status = $status;

            try
            {
                $shipping_repository->updateShippingMethod($shipping_method);
            }
            catch(Exception $e)
            {
                return new Object(-1, 'msg_invalid_request');
            }

            $this->setMessage('Shipping method successfully updated!');
        }
Example #3
0
 public function getShippingMethod()
 {
     $shipping_repository = new ShippingMethodRepository();
     $shipping_method_name = $this->getExtra('shipping_method');
     if ($shipping_method_name) {
         return $shipping_repository->getShippingMethod($shipping_method_name, $this->module_srl);
     }
     $default_shipping = $shipping_repository->getDefault($this->module_srl);
     return $default_shipping;
 }