Jump to content

How to use hook extra carrier and add a custom shipping module?


Recommended Posts

  • 4 weeks later...

I have implemented successfully an extra carrier through hook extracarrier. Everything works fine, but I wonder if there is any way to upgrade shipping cost without having to edit the order.php and Cart.php files after the carrier step.

Link to comment
Share on other sites

The function that manages this hook is:

 hookextraCarrier ($ params).



This hook should be registered when installing the module:

OR! $ This-> registerHook ('extraCarrier')



If you look at the file themes /prestashop/orde-carrier.tpl, you will see that the hook is positioned within a table. Then, you should create a .tpl file that fits this table.

Link to comment
Share on other sites

That is exactly what I want to discover. I have implemented successfully the carrier extra, but the module do not update the shopping cart with the value that was calculated. according to the modality of freight that was chosen by the customer.

The hook cart may be the answer. But how to use it to do so I do not know yet.

Link to comment
Share on other sites

That's true, I agree with you. For example, a carrier-type module do not need be registered in any zone of delivery, but the validation of prestashop takes into consideration this and the price and weight ranges to calculate shipping cost.

Link to comment
Share on other sites

I used the hook cart to retrieve the value of the delivery, via post, and I created a cookie to store this value. In Cart.php class, function getOrderShippingCost (), I replaced:


// Start with shipping cost at 0

       $shipping_cost = (0;



To:

global $cookie;
       // Start with shipping cost at 0
       $shipping_cost = (!$cookie->__isset('shipping_cost') ? 0 : $cookie->__get('shipping_cost'));



So far this has worked well.

  • Like 1
Link to comment
Share on other sites

Maybe because nobody needed it yet. The Prestashop is a young program. It has a lot to evolve. Even to recover carriers from the ps_carrier table is difficult, the results do not include carriers connected to a module. The restrictions contained in the guide AdminPayment can not be applied in this way.

I am collecting data to make some suggestions to the Presta ream, what do you think?

Link to comment
Share on other sites

Even to recover carriers from the ps_carrier table is difficult, the results do not include carriers connected to a module. The restrictions contained in the guide AdminPayment can not be applied in this way.


How do you mean this exactly? You have an example?
Link to comment
Share on other sites

Maybe because nobody needed it yet. The Prestashop is a young program. It has a lot to evolve. Even to recover carriers from the ps_carrier table is difficult, the results do not include carriers connected to a module. The restrictions contained in the guide AdminPayment can not be applied in this way.

I am collecting data to make some suggestions to the helpful, what do you think?

Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...
I used the hook cart to retrieve the value of the delivery, via post, and I created a cookie to store this value. In Cart.php class, function getOrderShippingCost (), I replaced:


// Start with shipping cost at 0

       $shipping_cost = (0;



To:

global $cookie;
       // Start with shipping cost at 0
       $shipping_cost = (!$cookie->__isset('shipping_cost') ? 0 : $cookie->__get('shipping_cost'));



So far this has worked well.



What happens when validating orders! Is the cookie available all the times? What for paypal IPN? The IPN script will not have the cookie! So wrong amount of shipping will be entered there is no cookie coming from the paypal IPN host!
Link to comment
Share on other sites


What happens when validating orders! Is the cookie available all the times? What for paypal IPN? The IPN script will not have the cookie! So wrong amount of shipping will be entered there is no cookie coming from the paypal IPN host!


You're right. The cookie is available for payments using the client's browser. IPN payment type - server to server - I copied the validation function into the payment module.
My payment modules always create a database. So when the customer is directed to the payment page, paypal for example, the freight is stored in this table.
When payment is completed and this information is sent to the store, the module retrieves this value from the database and use the validation function that was copied from class PaymentModule.

   private    function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, [b]$freight[/b])



And inside that function, the freight is set:

           $order->total_shipping = floatval(Tools::convertPrice(floatval(number_format($freight, 2, '.', '')), $currency));



You get the idea?

Link to comment
Share on other sites


What happens when validating orders! Is the cookie available all the times? What for paypal IPN? The IPN script will not have the cookie! So wrong amount of shipping will be entered there is no cookie coming from the paypal IPN host!


You're right. The cookie is available for payments using the client's browser. IPN payment type - server to server - I copied the validation function into the payment module.
My payment modules always create a database. So when the customer is directed to the payment page, paypal for example, the freight is stored in this table.
When payment is completed and this information is sent to the store, the module retrieves this value from the database and use the validation function that was copied from class PaymentModule.

   private    function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, [b]$freight[/b])



And inside that function, the freight is set:

           $order->total_shipping = floatval(Tools::convertPrice(floatval(number_format($freight, 2, '.', '')), $currency));



You get the idea?



hi!

here goes a better and elegant way as you are already modifying the core:

p<. step1. create a hook like 'shippingCost' in your module

p<. step2. Add this lines

$shipping_cost=Module::hookExec('IcodeShipping',array('shippingCost',0));
       return $shipping_cost; 



just after these lines in function 'getOrderShippingCost' in the class 'Cart.php'


 
if ($this->isVirtualCart())
         return 0;



step3. Implement the hook 'shippingCost' in your module! You can use hookExtraCarrier to show extra messages. All the creativity in your module.

That's all about it B-)

Link to comment
Share on other sites

  • 2 years later...
  • 3 years later...

I am not getting the option of carrier??it is taking automatically delhivery(as a carrier) i have added one more carrier option i.e. Express deleivery but in front for customer it is not showing?how to do it?please help me out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...