Your cart
0

How to create payment/shipping

This page explain to you how to develop EasyShop a plugin

See more here https://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla to get how Joomla! create a plugin.

A Payment/Shipping plugin maybe have more than a method which listed from the back-end MainMenu/Components/EasyShop/Payment(Shipping) methods

Develop a Payment Plugin

All payment plugins will be located in group easyshoppayment. When the execute method is called, the $order and $payment properties have already been presented.

                
                    // Import and use EasyShop Payment Legacy
                    JLoader::import('easyshop.plugin.payment');
                    use ES\Plugin\Payment;

                    class PlgEasyshoppaymentMypayment extends Payment
                    {
                        // This method will be called when an order has created by customer
                        public function execute()
                        {
                            $orderAmount = $this->order->get('total_price');
                            $products    = $this->order->get('products');
                            $testMode    = $this->payment->params->get('test');
                            // ...
                        }

                        // This method will be called by a payment gateway (such as PayPal...)
                        public function callback()
                        {

                        }
                    }
                
            

Develop a Shipping Plugin

All shipping plugins will be located in group easyshopshipping.

                
                    // Import and use EasyShop Shipping Legacy
                    JLoader::import('easyshop.plugin.shipping');
                    use ES\Plugin\Shipping;
                    use Joomla\Registry\Registry;

                    class PlgEasyshopshippingMyshipping extends Shipping
                    {
                        // This method will consider to register one or many shipping elements
                        public function onEasyshopShippingRegister()
                        {
                            /**
                             * @var $cart   \ES\Cart
                             * @var $method \ES\Method
                             */
                            $cart     = easyshop('class.cart');
                            $method   = easyshop('class.method');
                            $subTotal = easyshop('state')->get('cart.subTotal'); // Get subTotal in cart

                            foreach ($method->getShippingMethods() as $shipping)
                            {
                                $params    = new Registry($shipping->params);
                                $minAmount = (float) $params->get('min_order_amount');

                                // Check some restrictions
                                if($subTotal >= $minAmount)
                                {
                                    $shipTotal              = (float) $params->get('shipping_flat_fee');
                                    $shippingMethod         = $shipping;
                                    $shippingMethod->total  = $shipTotal;
                                    $shippingMethod->params = $params;
                                    // Now this shipping method will be displayed in the checkout page
                                    $method->addShippingMethod($shippingMethod);
                                }
                            }
                        }
                    }
                
            

How to create params for Payment/Shipping method

Place your params fields in the manifest XML file inside easyshop/fields[@name="params"]/fieldset[@name]. This works for the both payment method and shipping method.

                
                    <extension version="3.0" type="plugin" group="easyshoppayment" method="upgrade">
                        <name>plg_easyshoppayment_mypayment</name>
                        <author>Peter parker</author>
                        <creationDate>October 2017</creationDate>
                        <copyright>Copyright (C) 2016 - 2017 All Rights Reserved.</copyright>
                        <license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
                        <authorEmail>This email address is being protected from spambots. You need JavaScript enabled to view it.</authorEmail>
                        <authorUrl>www.my-site.net</authorUrl>
                        <version>1.0.0</version>
                        <description>PLG_EASYSHOPPAYMENT_MYPAYMENT_XML_DESCRIPTION</description>
                        <files>
                            <filename plugin="mypayment">mypayment.php</filename>
                            <folder>language</folder>
                        </files>
                        <easyshop>
                                <fields name="params">
                                    <fieldset name="payment_setting">
                                            <field
                                                    name="test"
                                                    type="list"
                                                    label="PLG_EASYSHOPPAYMENT_MYPAYMENT_TEST_MODE"
                                                    description="PLG_EASYSHOPPAYMENT_MYPAYMENT_TEST_MODE_DESC"
                                                    default="1"
                                                    filter="integer">
                                                <option value="1">JYES</option>
                                                <option value="0">JNO</option>
                                            </field>
                                            ...
                                        </fieldset>
                                </fields>
                        </easyshop>
                    </extension>
                
            

wWw.joomtech.net. All rights reserved.


© 2015 - 2019 wWw.joomtech.net. All rights reserved. JoomTech.net is not affiliated with or endorsed by the Joomla! Project or Open Source Matters. The Joomla!® name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.