Update a custom field

  • Posts: 171
  • Thank you received: 9
10 years 3 months ago #166695

-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.2.
-- PHP version -- : 5

Hi,

I had a small need what I want to add to the hikashop order management frontend:
when a user orders, after his order status is set to confirmed, in the order list (view/order/listing.php) a new button is shown with the option to let the user indicate, that his order has been shipped. This button works like "cancel order" button, but it makes it's status to "shipped". That's working OK, I've made a new function in controllers/order.php

But I do also want to let the user to set when his order has been shipped. So in listing.php I load the specified custom field like this:

<?php
$fields = $fieldsClass->getFields('frontcomp',$this->row,'order','checkout&task=state');												
echo $fieldsClass->display($fields['kiszallitva_igenyles'],$data->kiszallitva_igenyles, 'data[orderfields][kiszallitva_igenyles]');
?>

I want to run an sql in the called function in this way:
$db = JFactory::getDBO();		
			$fieldsClass = hikashop_get('class.field');
			$jinput = JFactory::getApplication()->input;
			$kiszallitasi_datum = $jinput->get('data[orderfields][kiszallitva_igenyles]');
			
			$query = 'UPDATE '.hikashop_table('order').' SET kiszallitva_igenyles='.$kiszallitasi_datum.' WHERE order_number='.$db->Quote($order->order_number);		
			$db->setQuery($query);
			$result = $db->query();

But the custom field (kiszallitva_igenyles) is not called, it's empty. Could you provide me a small help how to fix this sql part?

Last edit: 10 years 3 months ago by Jerome. Reason: code fix

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #166707

Hi,

I don't think that

$jinput->get('data[orderfields][kiszallitva_igenyles]');
will work.

If you want to read the value in the form, you should use the same kind of code that we made in HikaShop.
$data = JRequest::getVar('data', array(), '', 'array');
if(isset($data['orderfields']['kiszallitva_igenyles'])) {
 /* your stuff */
}
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.
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
10 years 3 months ago #166742

Thanks Jerome, again.

Now saves successfully to the field it needs, but there's some problem. The field is an advanced date picker field, I choose for example 2014/08/20 (I checked in firebug console) that this is in it:

<input type="hidden" value="2014/08/20" name="data[orderfields][kiszallitva_igenyles]" id="kiszallitva_igenyles">
Then the field value is saved with this data: 12.587500000000000000

Edit: I also tried with the base Joomla calendar, same happens: not the choosed dated saved...

Turned on Bug Reporter, and getting this:
Undefined variable: data in /home/www/.../shop/templates/berettyanshop/html/com_hikashop/order/show.php on line 375 Notice: Trying to get property of non-object in /home/www/.../shop/templates/berettyanshop/html/com_hikashop/order/show.php on line 375

I also found another problem, but maybe this is in relation with the above one:
when displaying the field with this code:
echo $fieldsClass->display($fields['kiszallitva_tetel'], $data->kiszallitva_tetel.$product->order_product_id, 'data[product][kiszallitva_tetel]');

the first field is working OK, but if I have more fields in the list, just the first one works.

Have u got any idea what can cause this or how to solve the above problems?

Last edit: 10 years 3 months ago by pepecortez. Reason: Bug Report log

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #166747

Hi,

The advanced date picker does not provide a date in a specific format, it provides the date serialized.
Something like "YYYYMMDDHHmmSS" if I remember right.
It allows to be sorted easily and change the date format display without having to modify the database.
I think that you have to store it as a text, using $db->Quote()

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.
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
10 years 3 months ago #166770

Jerome wrote: Hi,

The advanced date picker does not provide a date in a specific format, it provides the date serialized.
Something like "YYYYMMDDHHmmSS" if I remember right.
It allows to be sorted easily and change the date format display without having to modify the database.
I think that you have to store it as a text, using $db->Quote()

Regards,


OMG, so true, I don't know why I missed that. So the correct version looks like this, if some needs same:
if(isset($data['orderfields']['kiszallitva_igenyles'])) {
			
			$query = 'UPDATE '.hikashop_table('order').' SET kiszallitva_igenyles='.$db->Quote($data['orderfields']['kiszallitva_igenyles']).' WHERE order_number='.$db->Quote($order->order_number);		
			$db->setQuery($query);
			$result = $db->query();
			
			}

Have u got any ideas for the other problem?
Can I add somehow individual ID to the displayed custom fields? I think that cause the "not-working" problem.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #166779

Hi,

I don't understand your last problem ; what is the "if I have more fields in the list" ? Which list ? How ?
The way that you display the field is good but the value you have to the field Class is not the good one

$data->kiszallitva_tetel.$product->order_product_id
Why are you concatenate the order product id to the existing value of the custom field ?

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: 171
  • Thank you received: 9
10 years 3 months ago #167044

Jerome wrote: Hi,

I don't understand your last problem ; what is the "if I have more fields in the list" ? Which list ? How ?
The way that you display the field is good but the value you have to the field Class is not the good one

$data->kiszallitva_tetel.$product->order_product_id
Why are you concatenate the order product id to the existing value of the custom field ?

Regards,


Sorry, I copied the wrong lines, as I want to achieve almost the same to every each ordered items on a field named that.

I successfully solved the earlier described problem by adding in datepickerfield_class.php to $id variable a randomly generated number, so in this way, the multiple fields are loaded in listing view, now loaded with different ids, so they are not confused.

So, now in listing view I successfully solved to modify the order_status and adding date field by pushing just one click.

I also wanted to use the same method on show the order page (example link: /index.php?option=com_hikashop&ctrl=order&task=show&cid=353&Itemid=139)

But it gives a 403 error, maybe because this is a task page already? Or I don't know, just getting deeper in Joomla.
I wanted to use that function, but maybe I do not implemented it to the right place, or maybe I'm calling it not the right way.
function tetelkiszallitas_update(){

		$app = JFactory::getApplication();
		$order_id = JRequest::getVar('order_id');
		$product_id = JRequest::getVar('product_id');
		$redirect_url = JRequest::getVar('redirect_url');
		
		if(isset($data['product']['kiszallitva_tetel'])) {
	
				
				$query = 'UPDATE '.hikashop_table('order_product').' SET kiszallitva_tetel='.$db->Quote($data['product']['kiszallitva_tetel']).' WHERE order_product_id='.$db->Quote($order->order_number);		
				$db->setQuery($query);
				$result = $db->query();
				
				}	
		$redirect_url = JRequest::getVar('redirect_url');
		$app->redirect($redirect_url);
		return true;

	}

And the code that tries to use this in view/order/show.php:
<form id="adminForm_<?php echo $product->order_product_id; ?>_kiszallitott" action="#" method="post" name="adminForm_<?php echo $product->order_product_id; ?>_kiszallitott">
	<div class="szallitas_mezok_lista szallitas_mezok_<?php echo $product->order_product_id; ?>" style="display:none;">
<?php
	$orderClass = hikamarket::get('shop.class.order');
	$productClass = hikamarket::get('shop.class.product');
	$fieldsClass = hikamarket::get('shop.class.field');

	$fields =  $fieldsClass->getFields('frontcomp',$item,'item','checkout&task=state');												
?>
<?php //echo $row->kiszallitva_igenyles; 
	echo $fieldsClass->display($fields['kiszallitva_tetel'], $data->kiszallitva_tetel, 'data[product][kiszallitva_tetel]');
?>
	<button type="submit" class="btn btn-large right" name="tetelkiszallitas_update" value="MENTÉS" onclick="var field=document.getElementById('<?php echo $product->order_product_id; ?>');document.adminForm_<?php echo $product->order_product_id; ?>_kiszallitott.submit();return false;">MENTÉS</button>   
	</div>
	<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>"/>
	<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
	<input type="hidden" name="task" value="tetelkiszallitas_update" />
	<input type="hidden" name="product_id" value="<?php echo $product->order_product_id; ?>" />
	<input type="hidden" name="order_id" value="<?php echo $this->order->order_id; ?>" />
	<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
	<input type="hidden" name="redirect_url" value="<?php echo hikashop_currentURL(); ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>   

Any help would be really appreciated...

Last edit: 10 years 3 months ago by Jerome. Reason: cleaning code

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #167059

Hi,

I don't understand why you put some HikaMarket code into HikaShop views.
You have to understand that you have some luck that your code is working ; HikaMarket might not be loaded in every HikaShop pages ; so please be very very careful.
That's why I think you should see with a PHP developer for your requirement, developing new tasks for HikaShop is not something easy and it's really not recommended (because you won't be able to update HikaShop afterwards).
The best is to use plugins or view overrides (so you can't create new tasks at this moment).

Your problem is complex and is outside of what we can offer you in this support forum. It's not something which can be made in few minutes.

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.080 seconds
Powered by Kunena Forum