USA States in CSV export

  • Posts: 231
  • Thank you received: 4
  • Hikaserial Standard
9 years 8 months ago #194319

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.0

When I export an order as a CSV file the US State is being exported as:

state_South_Carolina_4304

How can I use the standard State shortcodes so the above would be:

SC

Are these stored in a db table somewhere I can change? I need to replicate this:

geography.about.com/od/lists/a/stateabbreviate.htm

For each state in the database.

Thanks

Lee

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

  • Posts: 13201
  • Thank you received: 2322
9 years 8 months ago #194355

Hi,

You could potentially replace the content of the view "order / export" in the backend template by something like:

<?php
while(ob_get_level() > 1)
	ob_end_clean();

$config =& hikashop_config();
$format = $config->get('export_format','csv');
$separator = $config->get('csv_separator',';');
$force_quote = $config->get('csv_force_quote',1);

$export = hikashop_get('helper.spreadsheet');
$export->init($format, 'hikashop_export', $separator, $force_quote);

if(!empty($this->orders)){
	$maxProd = 0;
	$productFields = null;
	foreach($this->orders as $order){
		$nbProd = count($order->products);
		if($maxProd < $nbProd){
			$maxProd = $nbProd;
			if(empty($productFields)){
				$productFields = array_keys(get_object_vars(reset($order->products)));
			}
		}
	}

	if($maxProd && !empty($productFields)) {
		$first = array();
		$o = reset($this->orders);
		foreach($o as $key => $val) {
			if(is_array($val))
				continue;
			$first[] = $key;
		}
		$o = null;
		for($i=1;$i<=$maxProd;$i++){
			foreach($productFields as $field){
				$first[] = 'item'.$i.'_'.$field;
			}
		}
	} else {
		$first = array_keys(get_object_vars(reset($this->orders)));
	}
	$export->writeLine($first);

	/* Added */
	$db = JFactory::getDBO();
	$db->setQuery('SELECT b.zone_namekey, b.zone_code_3 FROM '.hikashop_table('zone_link').' as a LEFT JOIN '.hikashop_table('zone').' AS b ON a.zone_child_namekey = b.zone_namekey WHERE a.zone_parent_namekey = '.$db->quote('country_United_States_of_America_223'));
	$usStates = $db->loadObjectList();
	$stateCodes = array();
	foreach($usStates as $usState){
		$stateCodes[$usState->zone_namekey] = $usState->zone_code_3;
	}
	/* EO Added */

	foreach($this->orders as $row){
		// Let's apply the right date format... an human one!
		if(!empty($row->user_created)) $row->user_created = hikashop_getDate($row->user_created,'%Y-%m-%d %H:%M:%S');
		if(!empty($row->order_created)) $row->order_created = hikashop_getDate($row->order_created,'%Y-%m-%d %H:%M:%S');
		if(!empty($row->order_modified)) $row->order_modified = hikashop_getDate($row->order_modified,'%Y-%m-%d %H:%M:%S');

		if($maxProd && !empty($productFields)){
			for($i=1;$i<=$maxProd;$i++){
				$prod =& $row->products[$i-1];
				foreach($productFields as $field){
					$n = 'item_'.$i.'_'.$field;
					$row->$n = @$prod->$field;
				}
			}
		}

		/* Added */
		foreach($row as $key => $value){
			if(in_array($value,array_keys($stateCodes))){
				$row->$key = $stateCodes[$value];
			}
		}
		/* EO Added */

		$export->writeLine($row);
	}
}

$export->send();
exit;

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

  • Posts: 231
  • Thank you received: 4
  • Hikaserial Standard
9 years 8 months ago #194478

Xavier,
thanks for the reply.

Which file in the backend do you mean precisely? Can you provide the file path?

I think I found it:

/administrator/components/com_hikashop/views/order/tmpl/export.php


Thanks

Last edit: 9 years 8 months ago by ltempest.

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

  • Posts: 231
  • Thank you received: 4
  • Hikaserial Standard
9 years 8 months ago #194484

Xavier,
I have modified the export file in the /administrator/components/com_hikashop/views/order/tmpl/export.php location to your code but it is still not exporting the State as the three character zone version.

Sorry!

Lee

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

  • Posts: 13201
  • Thank you received: 2322
9 years 8 months ago #194492

Hi,

I guess that you are using the export from the mass action, right ?
I was thinking of the export from the orders listing interface in backend.

So you have to edit the file "plugins/hikashop/massaction_order/massaction_order.php" and in the function "onProcessOrderMassActionexportCsv()"

Add:

/* Added */
	$db = JFactory::getDBO();
	$db->setQuery('SELECT b.zone_namekey, b.zone_code_3 FROM '.hikashop_table('zone_link').' as a LEFT JOIN '.hikashop_table('zone').' AS b ON a.zone_child_namekey = b.zone_namekey WHERE a.zone_parent_namekey = '.$db->quote('country_United_States_of_America_223'));
	$usStates = $db->loadObjectList();
	$stateCodes = array();
	foreach($usStates as $usState){
		$stateCodes[$usState->zone_namekey] = $usState->zone_code_3;
	}
	foreach($params->elements as $k => $element){
		foreach($element->address as $l => $data){
			foreach($data as $m => $value){
				if($m == 'address_state' && in_array($value,array_keys($stateCodes))){
					$params->elements[$k]->address[$l]->address_state = $stateCodes[$value];
				}
			}
		}
	}
/* EO Added */
Before:
$this->massaction->_exportCSV($params);

The following user(s) said Thank You: admindcusa

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

  • Posts: 8
  • Thank you received: 0
9 years 3 months ago #210150

And this is why I've bought 3 copies of your shopping cart software Hikashop Business for my clients and getting ready to purchase another one soon for another client. It is your customer support that defines how good your product is.
Thank you for your help.
Jonathan
Digital Creations USA, Inc.

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

Time to create page: 0.090 seconds
Powered by Kunena Forum