Product price editable on checkout

  • Posts: 23
  • Thank you received: 0
9 years 8 months ago #215292

Thanks but it doesn't work, I miss something for sure, this is my code :

<?php
define( '_JEXEC', 1); //  This will allow to access file outside of joomla.
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$user = JFactory::getUser();
$session =& JFactory::getSession();
$database = JFactory::getDBO();
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_hikashop'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')) return true;


$app = JFactory::getApplication();
$order_id = $app->getUserState('com_hikashop.order_id');
if (!$order_id) die("Nessun id ordine");


//GET IVA
$query = $database->getQuery(true);
$query->select('tax_rate');
$query->from($database->quoteName('#__hikashop_tax'));
$query->where($database->quoteName('tax_namekey')." = ".$database->quote('IVA'));
$database->setQuery($query);
$iva = $database->loadResult(); 

$orderClass = hikashop_get('class.order');
$orderProductClass = hikashop_get('class.order_product');
$fullorder = $orderClass->loadFullOrder($order_id,false,false);

$input = new JInput;
$post_array = $input->getArray($_GET);
$prodotto = new stdClass();


$prodotto->order_product_id = $post_array[$id];
$prodotto->order_product_quantity = 1;
$prodotto->order_product_price = 100;
$products = array ($prodotto);
$orderProductClass->save($products);

By the way, about recalculatefullprice, I pass it a good object, checked by var_dump before the call, but inside the function is NULL, what's wrong?

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

  • Posts: 83932
  • Thank you received: 13587
  • MODERATOR
9 years 8 months ago #215303

Hi,

The save function of orderProductClass is to add new order_products, not to update existing ones.
For existing ones, you want to use instead the update function of orderProductClass and in that case, it's the product object that you want to pass to the function.

For the recalculatefullprice function, I don't know what code you're using to call it so I can't say much more.

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

  • Posts: 23
  • Thank you received: 0
9 years 8 months ago #215391

nicolas wrote: Hi,

The save function of orderProductClass is to add new order_products, not to update existing ones.
For existing ones, you want to use instead the update function of orderProductClass and in that case, it's the product object that you want to pass to the function.

For the recalculatefullprice function, I don't know what code you're using to call it so I can't say much more.


Ok, let's recap. Nobody told me about this update function, since the start everyone has written about the save function, I'm a little confused.
WHAT I DID AND WHAT I NEED TO DO:
  • I edited end.php with a form to let the user write the new price of every product in order, the form sends this data to a save.php, it passes order_product_price and order_product_id.
  • Inside save.php I load joomla and hikashop framework, then with a for I write in a standard class the data passed by the POST, in this way:
    for ($i = 0; $i < count ($fullorder->products); $i++){
    	$id = "orderidprodotto". $i;
    	$prezzo = "prezzo". $i;
    	$prodottoinordine = $orderProductClass->get($post_array[$id]);
    
            $obj = new stdClass();
    	$obj->order_product_id = $post_array[$id];
    	$obj->order_id = $prodottoinordine->order_id;
    	$obj->product_id = $prodottoinordine->product_id;
    	$obj->order_product_quantity = (int) $prodottoinordine->order_product_quantity;
    	$obj->order_product_name = $prodottoinordine->order_product_name;
    	$obj->order_product_code = $prodottoinordine->order_product_code;
    	$obj->order_product_price = (float) $post_array[$prezzo];
    	$obj->order_product_tax = (float) $post_array[$prezzo] * $iva;
    
    	$element[$i]=$obj;
    }
    and put it in an array ($element). $prodottoinordine is an object loaded with the class.order_product ($prodottoinordine = $orderProductClass->get($post_array[$id]))
  • Now what I need is recalculate all the total and subtotal prices (can recalculatefullprice helps me?) and finally save (update?) my order

Last edit: 9 years 8 months ago by toninom.

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

  • Posts: 23
  • Thank you received: 0
9 years 8 months ago #215397

ok, something works, it needs to update every order_product inside the for, the passed object must have an order_product_id and an order_product_quantity, plus the data to edit, order_product_price and order_product_tax in my case. Hoping this info can helps someone else. EDIT: ok I can directly use the object loaded by order_prodcut class, just modifying price and tax and updating it by the update function (the save function wanted a new object, so I was using a new obj).
Now I need to update the order info, like order_full_price, order_subtotal, order_tax_info, can I use the recalculatefullprice function to automate this action? If yes there is something that I need to know ? Once I recalculate all the total and subtotal, can I use class.order save function? Or there is an update like orderproduct?

You are fantastic and you have a lot of patience , but I have to say it , the documentation is really poor , would be useful more doc about at least the most basic functions .

Last edit: 9 years 8 months ago by toninom.

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

  • Posts: 83932
  • Thank you received: 13587
  • MODERATOR
9 years 8 months ago #215410

So, yes, you want to do two things:
- At the end of your loop, you want to add a call to the update function of class.order_product in order to update the order_product entry for each product of the order.
Then, after the loop, you create a $order object with just the order_id set in it and you want to call the recalculatefullprice function of class.order with that $order parameter passed to the function. Then, you want to call the save function of class.order on that $order object (where the full price will have been calculated, in order to store the new full price of the order.

Most of the documentation is orientated to merchants, not developers. And even the developer documentation is orientated to people wanting to integrate HikaShop with other systems via plugins. For what you're trying to do, yes the documentation is really poor because it's not our target, unfortunately.

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

  • Posts: 23
  • Thank you received: 0
9 years 8 months ago #215430

Thanks, now all seems to work. I just add this code for the order product tax info :

$tasse = unserialize($prodottoinordine->order_product_tax_info);
$tasse[0]->tax_amount = $prodottoinordine->order_product_tax;
$prodottoinordine->order_product_tax_info = serialize($tasse);
Is it right ?

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

  • Posts: 83932
  • Thank you received: 13587
  • MODERATOR
9 years 8 months ago #215459

Yes, that should be enough.

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

Time to create page: 0.073 seconds
Powered by Kunena Forum