Need to add permanent checkout checkbox

  • Posts: 48
  • Thank you received: 0
9 years 7 months ago #198058

-- HikaShop version -- : 2.3.1
-- Joomla version -- : 3.3.1
-- PHP version -- : 5.4.43
-- Browser(s) name and version -- : MOZILLA FF 33.0.3

Hello there Hika experts:
I need to add a checkbox to my checkout page where client can choose to add extra payment for special package handling and delivery ,the extra service always costs the same regardless the package.

I thought of adding a payment method where I always add the extra sum ,but I have two payment methods so this make my checkout page have 4 payment methods which entirely not practical:
example
- Pay with Tranzila .
- Pay with Tranzila with extra handling (+20$) .
- Pay with PayPal ...................................................... <=== This I can do but is not elegant !!
- Pay with PayPal with extra handling (+20$) .

So how do I go about this ,in an elegant way preferably ?

Last edit: 9 years 7 months ago by Saiah.

Please Log in or Create an account to join the conversation.

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 7 months ago #198066

Hi,

The more elegant way will be to use an order custom field and a little custom plugin.
Thanks to the order custom field (HikaShop Business is required), you can add extra content during the checkout, like checkbox, text field, date picker, etc.

Thanks to little custom plugin you can assign a price to a custom field.
www.hikashop.com/forum/checkout/872829-w...icles-as-a-gift.html
www.hikashop.com/forum/checkout/873239-g...ng-for-hikashop.html
( It is also possible to use a view override in the checkout in order to do same kind of work )

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 48
  • Thank you received: 0
9 years 7 months ago #198170

Thanks for your reply,

I have added a custom field to the address table with the name express that can either have the value yes or no (single drop down list).
Now I want to create a plugin that goes something like this:

class plgHikashopExpress extends JPlugin {
	function onAfterCartShippingLoad(&$cart) {
		$app = JFactory::getApplication();
		$order_fields = $app->getUserState(HIKASHOP_COMPONENT.'.checkout_fields', null);
		
		if((int)$address_fields->express == 'no')
			return;

		if(!empty($cart->order_currency_id))
			$currency_id = (int)$cart->order_currency_id;
		else
			$currency_id = (int)hikashop_getCurrency();

		$express = new stdClass();
		$express->name = 'Express Delivery';
		$express->value = '';
		$express->price_currency_id = $currency_id;
		$express->price_value = 20;
		$express->price_value_with_tax = 20;
		$express->additional['express'] = $express; 
	}
}

Would this work?
And how exactly do I install this plugin?
Thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 48
  • Thank you received: 0
9 years 7 months ago #198193

I have managed to install the plugin ,but I now know that the code I tried won't work.
I am trying now to access the express field in the address object in my cart ,to see if express delivery is tecked or not so I can add extra 20 to the payment or not.

Please Log in or Create an account to join the conversation.

  • Posts: 48
  • Thank you received: 0
9 years 7 months ago #198197

Sorry for the hassle.
It all worked out just fine:
I added extra field to address named it 'express'
then I installed the plugin based on the function onAfterCartShippingLoad(&$cart)
then I got the user id:
$hk_user_id = $app->getUserState(HIKASHOP_COMPONENT.'.user_id');
then I got the express state:
$db = JFactory::getDbO();
$db->setQuery('SELECT express FROM #__hikashop_address WHERE address_user_id =' . $hk_user_id);
$express_state = $db->loadObject();
And now it is all working the I want it to.

Thanks a lot for the help.

Please Log in or Create an account to join the conversation.

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 7 months ago #198199

Hi,

Because you're using a checkbox for the custom order field, you should check if the value is empty or not.
When you check the box, you will have the value of the custom field, otherwise, you have "nothing".
That's why in the code that you previously posted, you need to have a different check

if(empty($order_fields ->express))
	return;

But for sure, if you're using address fields and not order field ; the code is different and your last code is quite better (to load the current user address)

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.064 seconds
Powered by Kunena Forum