Pickup order in XML specified places

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #232286

-- HikaShop version -- : 2.6.1.

Hi there!

There's a special shipping mode in my country, where users can change from a continously refreshed list where they want to collect their package when they make an order.

The list of places are loaded from an XML file from here.

Is there any ready-to-use plugin that can be easily overwritten to use this?
If not, would anybody be so kind to give me some points to how to create a shipping plugin for this?

Thanks in advance!

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #232291

Hi,

That would require the development of a plugin for that.
The best is to implement the checkout API of HikaShop in order to add your own view on the checkout workflow so that you can display the selection interface when necessary and process the selection of the customer.
You can read more about it here:
www.hikashop.com/support/documentation/6...tation.html#checkout
And you can find an example in the folder plugins/hikashop/userpoints/ as the user points plugin can be configured you have its own view on the checkout to let the customer choose if he wants to use his points or not:
www.hikashop.com/support/documentation/257-using-points.html

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233151

nicolas wrote: Hi,

That would require the development of a plugin for that.
The best is to implement the checkout API of HikaShop in order to add your own view on the checkout workflow so that you can display the selection interface when necessary and process the selection of the customer.


I know that that's maybe not the best idea, but I've seen that in Hikashop Manual Shipping plugin there's a setting to overwrite the user's address. I was wondering to examine that plugin much better, but I was not able to find the code that is using as in /plugins/hikashopshipping/manual/manual.php I can not find any useful code.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233168

Hi,

That's because the manual plugin inherit of all the functions of the hikashopShippingPlugin class that you can find in administrator/components/com_hikashop/helpers/helper.php
You want to look at the getShippingAddress function there.
So you can copy the manual plugin into a manual2 plugin (and rename everything accordingly) and the implement that getShippingAddress function in the class of the plugin in order to override it and display whatever you want.

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233537

Hi Nicolas,

I've made a copy from manual shipping plugin, and added getShippingAddress function. I've successfully populated the data from the xml file to a dropdown, but I've got a few problems which I would like to ask you to give me some guidelines to fix it.

In getShippingAddress I modified case 4 this way:

case 4:
	if(!empty($params->shipping_override_address_text))
	$mainframe = JFactory::getApplication();
	$document =& JFactory::getDocument();
	//$xmlurl = $params->shipping_override_address_text; - link can be edited in admin, underneath for the example the fix link
        $xmlurl = 'http://partner.pickpackpont.hu/stores/validboltlista.xml';
	$xmlfile = JPATH_CACHE . DS . 'validboltlista.xml';
	$styleppp = '#hikashop_checkout_address_left_part,#hikashop_checkout_address_right_part{width:100% !important}'; 
	$document->addStyleDeclaration($styleppp);
	$params->shipping_override_address_text = '<div style="margin-top:10px; padding: 10px; border: 1px solid #ff0000;background: #d2b8b8;color:#000; font-weight:bold; text-align: center;">Choose from the dropdown list above which PPP you wanna pick up your parcel...</div>';
		if (is_writable(JPATH_CACHE)) {
			if (filesize($xmlfile) < 100 || !file_exists($xmlfile) || (((time() - filemtime($xmlfile)) / 3600 / 24) > 7)) {
				$cont = file_get_contents($xmlurl);
				file_put_contents($xmlfile, $cont, LOCK_EX);
			}
		}
			
		$xmlcacheurl = JURI::base() . '/cache/validboltlista.xml';
		$_SESSION['hikashop_ppp_xml'] = $xmlcacheurl;
		$document->addScriptDeclaration('var xmlurl = "' . $xmlcacheurl . '";');
		
		if (simplexml_load_file($xmlfile)) {
		} else {
		$mainframe->enqueueMessage(JText::_('Error: No XML file'), 'error');
		return;
		}
					
		$Shops = simplexml_load_file($xmlcacheurl);
			
		echo "<select name='PPPlehetosegek' id='PPPlehetosegek'>";
			echo "<option value=''>Start typing the city where you wanna get your parcel...</option>";
			foreach($Shops as $Shop)
			{
			echo "<option value='".$Shop->ShopCode.' - '.$Shop->ZipCode.' '.$Shop->City.', '.$Shop->Address.' - '.$Shop->Name."'>".$Shop->ZipCode.' '.$Shop->City.', '.$Shop->Address.' - '.$Shop->Name."</option>";
			}
		echo "</select>";
			
		return $params->shipping_override_address_text;
		$params->shipping_override_address_text = $_POST['PPPlehetosegek'];
			
		break;

My problems:
1.) I'm unable to pass the choosen dropdown element's data to shipping_override_address
2.) The dropdown list is shown on admin interface, and on order summary (after sending the order), but it should be just displayed on the checkout process.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233559

Hi,

You need to implement the onShippingSave function and look in the $_POST for the selection of the customer. Then, store that somewhere. For example, you could store it in the user session in $_SESSION. Then, you could implement the onAfterOrderCreate function in your plugin and store the selection from $_SESSION in the order in the database.
That way, when your getShippingAddress is called in the order summary and admin interface, you can provide the value stored with the order instead of displaying the dropdown.
It's quite convoluted.
That's why I had recommended to use instead the checkout API, which is much more straightforward...

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233611

Hi Nicolas,

I've got an idea that maybe simplifies the process. I should create an extra field for order, which is read-only and fill it with the selected data choosen from the dropdown lsit.

I've restarted the plugin as you adviced, tried to re-use some other plugin's part.

I've created the Checkout step. In onCheckoutStepDisplay function as I had no idea how to remove a step if not the specified shipping plugin is choosen, I take the new checkout step under the Address in configuration. I loaded the shipping class to examine if that shipping plugin is choosen (if not then the dropdown do not shows). After that I added the dropdown filled with the XML data.

1.) But whatever I choose from dropdown, there's no "selected" parameter in the code in front of the choosen item. Maybe that's why I'm unable take the data to next step. If dropdown name is "PPPlehetosegek" then I should use

$_POST['PPPlehetosegek']
shouldn't I?

2.) Also I don't know how to take the selected data to the custom field to fill in. Maybe I should also use the session as you adviced
$_SESSION['valasztott_PPP'] = $_POST['PPPlehetosegek'];
But then how to load it to the field?

3.) I tried to set in onAfterCheckoutStep to force the user to choose an item mandatory, and don't let him to move to next step until nothing is choosen. But maybe I copied no the correct code.
if(empty($_SESSION['valasztott_PPP']) || is_null($_SESSION['valasztott_PPP'])) {
	$go_back = true;
	$app->setUserState('No PPP choosen!');
	}

Thanks in advance for your long patience!

Last edit: 8 years 8 months ago by pepecortez.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233616

Hi,

The group of the plugin should be "hikashop", not "hikashopshipping".
And the class should be :
class plgHikashopPickpackpont extends hikashopPlugin {
not:
class plgHikaShopshippingPickpackpont extends hikashopShippingPlugin {

In the onAfterCheckoutStep function, you're supposed to get the data from the $_POST and store it in the session and set the $go_back variable to false if basically you find the variable in the $_POST, else set it to false.

In the onCheckoutStepDisplay function, you can then use the data stored in the session in order to set the value of the dropdown

Finally, you should add a onBeforeOrderCreate trigger there and get the data from the session and add it in the $order in a custom order field so that the system can display the custom order field value in the invoice/order details, emails.

The following user(s) said Thank You: pepecortez

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233752

Thanks Nicolas, almost working perfectly.

Small problems:
1.) Session just hold the data until one step in the checkout. I vardump-ed session variable on the next steps, but the dropdown field's value turns somehow to null.

2.) I'm unable to force the user to choose a value from dropdown. This code do not work, but I do not understand why:

function onAfterCheckoutStep($controller, &$go_back, $original_go_back, &$controller){
	$_SESSION['kivalasztott_PPP'] = $_POST["PPPlehetosegek"];
	$app = JFactory::getApplication();
	if($controllerName != 'plg.shop.pickpackpont')
		return false;
			
	if(isset($_SESSION['kivalasztott_PPP']) && !empty($_SESSION['kivalasztott_PPP'])) {
			$go_back = false;
			$app->setUserState('Pick Pack Pont successfully choosen!');
	}
	else{
		$go_back = true;
		$app->setUserState('No Pick Pack Pont choosen!');
	}
}

Last edit: 8 years 8 months ago by pepecortez.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233781

Hi,

Well, the purpose of the user session is to keep the variables throughout the pages, so there are two possibilities:
1. Your web server is not correctly configured and you loose the user session (but I doubt about that, because then you would have other issues with the cart and the login system).
2. You code is wrong. You set the $_SESSION with the POST too many times, even when nothing is submitted. An easy solution to avoid that is to add a

if(isset($_POST['PPPlehetosegek']))
before the line:
$_SESSION['valasztott_PPP'] = $_POST['PPPlehetosegek'];

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233834

Neither helped. :(

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233836

Hi,

Well, I've checked the code and it looks good. So I don't have any other advice. It would require debugging to understand what variables don't have the data they should where.

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

Time to create page: 0.067 seconds
Powered by Kunena Forum