MASS Action selection using related field

  • Posts: 18
  • Thank you received: 0
10 years 1 month ago #207572

-- url of the page with the problem -- : www.store.glidingaustralia.org
-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.3

Hello,

I have a custom field on the product table, which is called gl_code. It contains the Ledger Code for the accounting system.

I want to export all order lines for the month and include this code with the output.

The MASS Action process will let me select Orders and then I can export all the details of each order line - this is good.

But then I also want to include the gl_code from the product table. The information to link is there because of the order_product_id. is a column in the export.

Of course I can make this connection outside Hikashop but it would be very nice to export all the necessary information in one file because then it can import straight to the accounting system. Perhaps I have missed the way to do this.

Thank you

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #207640

Hi,

In HikaShop we can't export custom product field in the order data.

But, we have a solution ;) You can create a custom product field and a custom item field with the same name.
Then you will have to edit the view "product / show_block_custom_item" and in the foreach add the line:

$oneExtraField->field_value = $this->row->field_namekey;

This will fill the custom item field with the value of the custom product field, so this way you will be able to export the value in the massaction order data.

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

  • Posts: 18
  • Thank you received: 0
10 years 1 month ago #207680

Thank you.

But I am not very skilled with php or with Hikashop so I need a little more guidance :(

My custom field in the prodict table has the column name gl_code. So I tried to create a custom field with the same name in the Item table and then I got an error saying there was already a field with that name in the Product table.

So then I made a field with the name item_gl_code in the Item table.

I have found the view and I can see that this creates the list of selectable fields. But I am not sure how to place the line of code or how I should replace the field names and values:

$oneExtraField->item_gl_code = $this->row->gl_code;

or something else?

Sorry to ask stupid questions.

Tim

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #207703

Hi,

So you have to use the following code:

	$namekey = $oneExtraField->field_namekey;
	$fieldNamekey = str_replace('item_','',$oneExtraField->field_namekey);
	if(isset($this->row->$fieldNamekey))
		$itemData = $this->row->$fieldNamekey;

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

  • Posts: 18
  • Thank you received: 0
10 years 1 month ago #207746

Thank you. But this code is strange:

I have a custom field in Product Table: gl_code.
I have a custom field in Item: item_gl_code.

I want item_gl_code in the Item table to have the value from gl_code for a matching product.

So I can see how the view "product / show_block_custom_item" will help, and I can see that the foreach is the right place to make the change.

But I am confused by this code:

$namekey = $oneExtraField->field_namekey;
$fieldNamekey = str_replace('item_','',$oneExtraField->field_namekey);
if(isset($this->row->$fieldNamekey))
$itemData = $this->row->$fieldNamekey;

The variable $namekey is assigned but not used after. What is it for?

Should I replace "field_namekey" with my field value "item_gl_code" ? It looks as if that is what is needed.

How is the variable $itemdata used? It looks as if when I insert this code in the view, $itemdata is assigned by a JREQUEST as the first line of the foreach - so putting this code in before will do nothing because the $itemdata will be over written. And if I put it after, then $itemdata will have the wrong data.

I am sure that my understanding is the problem - and I am sorry for the questions. But I don't want to put this code in until I understand, in case I break the shop.

Cheers

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #207756

My bad, I should have given you more explanations.

As you said, the line:

$namekey = $oneExtraField->field_namekey;
Is not used (it was present in my first version of the code and I forgot to remove it), so you only need to add the code:
	$fieldNamekey = str_replace('item_','',$oneExtraField->field_namekey);
	if(isset($this->row->$fieldNamekey))
		$itemData = $this->row->$fieldNamekey;
Right after:
$itemData = JRequest::getString('item_data_' . $fieldName, $this->element->$fieldName);

This way the code will check if there is a product field named as your item field but without the "item_" at the beginning.
If it is existing, so we replace the value of $itemData which is setting the custom field value by the product field value.

So no need to replace anything by "item_gl_code" in this code, and this can work for as many fields as you want.

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

  • Posts: 18
  • Thank you received: 0
10 years 1 month ago #207800

Thank you so much.

I can see now exactly how this code will work.

I hope this thread will help other people who have the same requirement.

Because it is a solution for any field, you may think about including it as a standard feature in your next version of Hikashop.

But again I thank you for the solution and for having patience with my questions.

Cheers

Tim

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

  • Posts: 18
  • Thank you received: 0
10 years 1 month ago #208041

OK, one more question:

I used the code you provided, and for sure it works - I can see and select the custom field gl_code and item_gl_code in the MASS Action form. Good so far.

but I see nothing in the columns gl_code or item_gl_code when I display the results.

I have values in the custom field gl_code of the product table.

I have the custom field item_gl_code in the Item table.

What I need is to show the value of gl_code in each row of the MASS Action report. This could be done either by:

1. Lookup of the gl_code from the product table when the MASS Action runs
2. Placing the value of gl_code into item_gl_code at the time the product is added to the order.

It doesn't matter which.

But it seems that neither of these things is happening

Sorry again. we are almost there, I know...

Cheers

Tim

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

  • Posts: 18
  • Thank you received: 0
10 years 1 month ago #208077

And here is the code as it now exists in the view:

<?php
foreach ($this->itemFields as $fieldName => $oneExtraField) {
$itemData = JRequest::getString('item_data_' . $fieldName, $this->element->$fieldName);
$fieldNamekey = str_replace('item_','',$oneExtraField->field_namekey);
if(isset($this->row->$fieldNamekey))
$itemData = $this->row->$fieldNamekey;
?>

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #208445

Hi,

When you are in the product edition page, are the custom item field automatically field ?
Are they taking the value of the custom product field by default ?

If it is, so when the customer add the product to the cart, the custom item field values are added to the cart too, and then the mass action export should display the values in the correct fields.

If the fields are filled on the frontend but you don't have the value in the mass actions (for the products added to the cart after the modification) please give us backend access via our contact form, and don't forget to give the url of that topic in your message.
www.hikashop.com/support/contact-us.html

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

Time to create page: 0.081 seconds
Powered by Kunena Forum