Showing billing address in order listing

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345257

-- HikaShop version -- : 4.6.1
-- Joomla version -- : 4.2.3
-- PHP version -- : 8.0.22
-- Browser(s) name and version -- : EDGE
-- Error-message(debug-mod must be tuned on) -- : None

Hello,

So far i have managed to show the billing addresses on the order listing, that was very simple, see added screenshot.
We only need company names and cities. I've used the following to show the billing addresses.
<?php echo $row->address_company; ?> <?php echo $row->address_city; ?>

I've been fighting to show shipping addresses on our order listing, tried a couple of database values that i could find from our sql.
I can't seem to let the shipping addresses to show up.

What am i doing wrong? What did i not see?


Best regards,
Attachments:
Last edit: 2 years 1 month ago by alexnovo.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 1 month ago #345259

Hi,

The shipping address data is not loaded on the listing.

There is two reasons for that:
- it's not possible to add a join on both the shipping and the billing address as the columns would have the same name and there is no mechanism in MySQL to prefix columns during a MySQL query:
stackoverflow.com/questions/13153344/in-...e-table-it-came-from
- If you're selling digital goods, you only have a billing address and not shipping address. So we decided to only load the billing address as it is always there while the shipping address is only there if the goods are to be shipped.

Now, in your order / listing view file override, you can manually load the shipping address if you need it with a bit of code:

$addressClass = hikashop_get('class.address');
$shippingAddress = $addressClass->get($row->order_shipping_address_id);
echo $shippingAddress->address_city;

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345287

Nicolas that is exactly what we needed. I addes address_company to the code

$addressClass = hikashop_get('class.address');
$shippingAddress = $addressClass->get($row->order_shipping_address_id);
echo $shippingAddress->address_city;
echo $shippingAddress->address_company;

We use the webshop for internal use only. Employees order components with us on a cost center(billing address) and we send them to a sattelite company(shipping address).

That is why we need both to be visible.

Only thing is that the filter does not seem to work properly anymore. Not all values will show up when filtered.


Best regards,

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 1 month ago #345294

Hi,

Adding that customization won't change how the filters work.
What do you mean by "Not all values will show up when filtered". Could you provide some screenshot to illustrate the issue ?

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345300

Strange. When i try to look up certain words, only a couple of results come up instead of everything with those words.


For example see screenshots.
There are a lot of values with casino.
But when i enter the word in the filter, it will only show a few.

As far as i know there has not been made changes to a filter. As i do not know why i should change the one on the order listing and i neither would know at this moment where i could change that.


Best regards,
Attachments:
Last edit: 2 years 1 month ago by alexnovo.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 1 month ago #345303

Hi,

The search is on a limited number of fields.
It searches on :
- the user id
- the user username
- the user name
- the user email address
- the order number
- the invoice number
- the order total amount
- the billing address firstname, lastname
- the coupon code
- the custom fields of the table "order"
I suppose that the text you're trying to search is not in one of these.
It's not because you add the display of the shipping address in the listing that the system will be able to search in it, for example.
In the file administrator/components/com_hikashop/views/order/view.html.php you have this line which defines the list of columns on which the search is done:

$searchMap = array('c.id','c.username','c.name','a.user_email','b.order_user_id','b.order_number','b.order_id','b.order_invoice_number','b.order_invoice_id','b.order_full_price','d.address_firstname','d.address_lastname', 'b.order_discount_code');
It would potentially be possible to search on more fields of the billing address by adding them to that code. But for the shipping address, it's not possible as the shipping address is not part of the MySQL query loading the orders on the page, as I was explaining in my first message on this thread.

The following user(s) said Thank You: alexnovo

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345309

Works like a charm. Too bad the search on delivery address is not possible, but this already is a better way to work for us.


Best regards,

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345386

Hi Nicolas,

I've encountered another problem. Somehow when a employee selects pickup at office it shows another delivery address, see screenshot.


Best regards,
Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 1 month ago #345388

Hi,

In the settings of the shipping method, you have a "override shipping address" setting which changes the shipping address to what you selected. This area is shown according to this.

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345401

Somehow it does not change the data on the order listing. It does change the data in the order itself.

Could it be because of the code you have sent me before? Shouldn't there be a "if" somewhere which will show the shop address when pickup is selected? I looked into the employees account and the standard delivery address is choosen on the order listing, even when pickup is selected.

$addressClass = hikashop_get('class.address');
$shippingAddress = $addressClass->get($row->order_shipping_address_id);
echo $shippingAddress->address_city;
echo $shippingAddress->address_company;


Best regards,
Last edit: 2 years 1 month ago by alexnovo.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 1 month ago #345410

Hi,

Indeed, I sent a simple code as I didn't thought you were using that setting of shipping methods and I prefer to keep things as simple as possible for people not familiar with the code of HikaShop to be able to more easily grasp it.
It gets more complex if you want to handle that:

		if(!empty($row->order_shipping_method)) {
			$currentShipping = hikashop_import('hikashopshipping', $row->order_shipping_method);
			if(method_exists($currentShipping, 'getShippingAddress')) {
				$override = $currentShipping->getShippingAddress($row->order_shipping_id, $row);
				if($override !== false) {
					$row->override_shipping_address = $override;
				}
			}
		}
		if(!empty($row->override_shipping_address)) {
			echo $row->override_shipping_address;
		} else {
			$addressClass = hikashop_get('class.address');
			$shippingAddress = $addressClass->get($row->order_shipping_address_id);
			echo $shippingAddress->address_city;
			echo $shippingAddress->address_company;
		}

The following user(s) said Thank You: alexnovo

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345437

This works like a charm. Thank you!
We tweaked hikashop quite a bit to meet to our wishes as its only for internal use.

Employees order products for their service vans and the need cost centers(like billing addresses) but send most products to a sattelite or pick it up at our main office.
The Netherlands is not a huge country, in 3 hours you are able to go from one border to another.


Best regards,
Last edit: 2 years 1 month ago by alexnovo.

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

  • Posts: 26
  • Thank you received: 2
2 years 1 month ago #345439

I tweaked your code a little because the complete address came up on the order listing
and when i edited "main office+city" in the override shipping address in the shipping method it would not show up nicely in our invoices.

The code now is

   <?php
                      if(!empty($row->order_shipping_method)) {
			$currentShipping = hikashop_import('hikashopshipping', $row->order_shipping_method);
			if(method_exists($currentShipping, 'getShippingAddress')) {
				$override = $currentShipping->getShippingAddress($row->order_shipping_id, $row);
				if($override !== false) {
					$row->override_shipping_address = $override;
				}
			}
		}
		if(!empty($row->override_shipping_address)) {
			[b]echo 'Company main office City';[/b]
		} else {
			$addressClass = hikashop_get('class.address');
			$shippingAddress = $addressClass->get($row->order_shipping_address_id);
			echo $shippingAddress->address_company;
			echo ' ';
			echo $shippingAddress->address_city;

		}
                      ?>


Best regards,
Last edit: 2 years 1 month ago by nicolas.

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

Time to create page: 0.079 seconds
Powered by Kunena Forum