Product price editable on checkout

  • Posts: 23
  • Thank you received: 0
9 years 3 months ago #210755

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.4
-- Browser(s) name and version -- : Chrome

I don't know if there is an easy way to do this, but as I wrote on title I need to get editable the product price on checkout page. I checked cart.php but it'ìs a little hard to understand where I need to edit the code.

<th id="hikashop_cart_product_price_title" class="hikashop_cart_product_price_title hikashop_cart_title">
						<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>
					</th>
This seems to print the price, but I don't know where "CART_PRODUCT_UNIT_PRICE" is formatted
thanks in advance

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

  • Posts: 2143
  • Thank you received: 747
9 years 3 months ago #210764

CART_PRODUCT_UNIT_PRICE is only a placeholder, and the actual text you're seeing in the frontend is coming from a language file - depending on which language you're using.

Both Joomla and HikaShop are coming with tools to override such text, means for you to change it to whatever you prefer it to be. For the HikaShop tool see the documentation here: hikashop.com/download/languages.html#modify


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

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

  • Posts: 23
  • Thank you received: 0
9 years 3 months ago #210765

Thanks for answer me, but actually as I wrote I don't need to edit the language file, but I need to make the price editabile on front end checkout page

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

  • Posts: 2143
  • Thank you received: 747
9 years 3 months ago #210770

toninom wrote: ... as I wrote I don't need to edit the language file, but I need to make the price editable ...


Sorry, got that wrong, probably because most of your post referred to and quoted the table header and the text placeholder.

I'm sure the HikaShop guys will be commenting on your "real" question soon. ;)


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 3 months ago #210772

Hi,

I'm sorry but that kind of thing won't be possible without the item custom fields and some custom code.

First, to have an editable price in the product page, you need item custom fields.
See : demo.hikashop.com/index.php/fr/hikashop/...t-page/donation-page

Then, to edit an item custom field directly during the checkout ; it requires a pretty important custom development in order to add the feature allowing the edition of item custom field value directly in the cart, during the checkout.
And that's not something which can be done in a 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.

  • Posts: 23
  • Thank you received: 0
9 years 3 months ago #210891

Thanks, I already know that isn't so easy :(, becouse of this I decided to write here. So, can you give me just a way to follow? In some way I have to do this, and I need some tips to starts, otherwise I should read all hikashop code to better understand :(
Thanks again for your time and your support

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 3 months ago #210897

Hi,

I can't give you any hint if I don't understand your base structure.
You can't modify any product price anywhere in HikaShop ; except if you're using something like the donation plugin and I already gave you that information.
So without any details about your structure or website ; I am not able to help you or give you other useful details.

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: 23
  • Thank you received: 0
9 years 3 months ago #211016

I have an hikashop stock, what I need is that a manager may change the price during checkout, just like creating a custom quote for a specific customer. Isn't necessary to change the product price in the db, just in that specific order something like applying a custom discount . It shoud be displayed as for the quantitty.
I checked cart.php and listing_price.php (components/com_hikashop/views/checkout/tmpl) but it's a little hard to understand how the code works.
Hoping to have been clearer, thanks again for your help

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 3 months ago #211023

Hi,

You can't modify the price of a product in the cart. That's because products in the cart don't have any price. They just use the price of the product entry.
That's why, as Jerome said, you need to create a custom item field to be able to store that price value of the product in the cart.
Then, you need to use the donation plugin so that you can use that price instead of the normal price of the product.
And finally, you need to edit the "cart" of the view "checkout" in order to modify the display of the price in order to use an input field and then you want to create a system plugin implementing the onAfterRoute trigger of Joomla in order to catch the value entered in that field when the cart view is submitted on the checkout and update it in the entry of each product in the cart in the table hikashop_cart_product with a MySQL query.
That method will work and require only PHP and MySQL knowledge and looking at the checkout/cart view and the hikashop_cart_product table of your database. So that should be enough to get started if you're a developer. Otherwise, you can contact our partners for a quote on such custom development.
www.hikashop.com/home/our-partners.html

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

  • Posts: 23
  • Thank you received: 0
9 years 3 months ago #211187

Thanks for your support, this is the kind of help I was searching for. But seems to be harder than I thought :(. I'll try anyway. Thanks again

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

  • Posts: 23
  • Thank you received: 0
9 years 2 months ago #214538

Hi again, about my problem, what about to edit end.php (the thank you page) with some code allowing the user to edit the order ? Is it possible ? I'm able to load the fullorder but when I try to edit and save some order data nothing happen. This is what I did :

$app = JFactory::getApplication();
$order_id = $app->getUserState('com_hikashop.order_id');
$order_number = $app->getUserState('com_hikashop.order_number');

$orderClass = hikashop_get('class.order');
$fullorder = $orderClass->loadFullOrder($order_id,false,false);
With this I can read everything about the order, but if I edit something with this code :
$ordine = new stdClass();
$ordine->order_id = $order_id;

$orderClass->save($ordine);
Nothing happen in the db. Whats's wrong ? Just if I edit the order state like this :
$ordine->order_status = "confirmed";
I have it changed, but if I edit somenthing about the products array I have nothing changed :(

Can you give me some help ?

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 2 months ago #214563

Hi,

You can load the full order but you shouldn't use it as a parameter for the "save" function.
Using a stdClass like you did is the right solution ; otherwise you can use an object from the "orderClass->get" function.

For your sample code, you didn't modify anything in the order, so there is nothing to do in the database.
If you want to modify something in the "order" table, you can use that "$ordine" object ; but if you want to change products in that order (in fact, "order_product"), it is more complicated than that.
You need to add the "order_product" entry, you need to reprocess the order prices, etc.

You should use a trigger and modify the order content before the order save ; it would be easier than trying to load and modify an order directly from the database.

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: 23
  • Thank you received: 0
9 years 2 months ago #214611

The example code was just an example : D , just to know if I did well . Actually I need to let the user (a sales manager ) to edit the order info , Mainly the product price , in order to apply a custom discount for example. As I said I'm able to modify the order info, like the order_status or order_full_price and save it , but not the product info , what do you mean with "add the order_product entry " ?

With use a trigger you mean to write a plugin ? Which triggers should I use ? How can I load the fullorder inside the plugin ? Should I import some specific files ?

Really thanks again

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 2 months ago #214645

Hi,

The save function of the class.order has two cases where it can handle products:
- when you create a new order, you can pass all the data of all the products in $order->cart->products
- when you update an existing order, you can pass the products data in $order->product
in both cases, it must be an array and in the second case, you of course need to pass the order_product_id attribute in each product.
Then, you can use the save function on your order object with the data in it.

If you want to modify the order content before the order is created, you can implement the onBeforeOrderCreate trigger in a hikashop plugin. But this supposes that you already have the data on hand at that point. Not knowing the details of what you did, the edition of the end view like you did might be better.

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

  • Posts: 23
  • Thank you received: 0
9 years 2 months ago #214830

Thank you, you have clarified some of my doubts. Now, assuming for example that I want to edit all the product price of every product in order, setting all of them at 100€ (just to understand how to do), what I should write inside this for?

foreach($fullorder->products as $k => $product){
I tried everything but nothing works

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 2 months ago #214832

$app = JFactory::getApplication();
$order_id = $app->getUserState('com_hikashop.order_id');
$orderClass = hikashop_get('class.order');
$fullorder = $orderClass->loadFullOrder($order_id,false,false);
foreach($fullorder->products as $k => $product){
 $fullorder->products[$k]->order_product_price = 100;
}
$fullorder->product =& $fullorder->products;
$orderClass->save($fullorder);
should do the job I guess.

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

  • Posts: 23
  • Thank you received: 0
9 years 2 months ago #214919

Mmm this is clear, but jerome said that I can't use fullorder as a parameter in save function, I'll try anyway, thanks

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

  • Posts: 23
  • Thank you received: 0
9 years 2 months ago #215241

Of course it doesn't work.
I tried everything, I'm not able to modify the "order product" through the hikashop framework, how is it possible ?
Should I use the save of class.order_product or class.order? I tried both with no result.
I think I miss something.
Should this work ?

$prod = new stdClass(); 
$prod->order_id = $order_id;
$prod->order_product_id = $post_array[$id];
$prod->order_product_price = $post_array[$prezzo]; 
$orderProductClass->save($prod);
Or I need to populate the order with the products array and then save the order ? Like this :
$order = new stdClass();
$order->order_id = $orderid;
$ordine->products[0] = new stdClass();
	$ordine->products[0]->order_id = $order_id;
	$ordine->products[0]->order_product_id = $post_array[$id];
	$ordine->products[0]->order_product_price = $post_array[$prezzo];
        $orderclass->save ($ordine);

Please help me.

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

  • Posts: 23
  • Thank you received: 0
9 years 2 months ago #215252

Another problem, recalculatefullprice seems to not work, I pass my order object, but actually it pass nothing , a var_dump on $order inside recalculatefullprice shows me NULL, how can it be possible ?

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 2 months ago #215267

Hi,

The recalculateFullPrice function requires that you provide a $order object and it will modify directly that object. If $order is null in there, it means that you give a null $order when calling the function.

You can't give a $product object to the save function of class.order_product, you can only give it an array of $product objects. So for example, like that:

$prod = new stdClass(); 
$prod->order_id = $order_id;
$prod->order_product_id = $post_array[$id];
$prod->order_product_price = $post_array[$prezzo]; 
$products = array($prod);
$orderProductClass->save($products);
Using both the save function of class.order and giving it a $order object with products in an attribute or the save function of class.order_product and giving it an array of the products will work.
We use both methods throughout the code of HikaShop and it works just fine.

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

Time to create page: 0.100 seconds
Powered by Kunena Forum