Cart page : add donation line

  • Posts: 36
  • Thank you received: 0
9 years 1 week ago #220720

-- url of the page with the problem -- : solishop.fr
-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.5

Hello,

I add a line just above the total line on the cart page.
I already add the html part :

<td id="hikashop_checkout_donation_title" class="hikashop_checkout_donation_title">
<?php echo JText::_('HIKASHOP_DONATION'); ?>
</td>
<td>
<form method="post">
<input type="number" name="donation" style="width:30%" value="0" min="0">
<input type="submit" value="Ok">
</form>
</td>


Then I recover the value here :

<td class="hikashop_cart_total_value" data-title="<?php echo Jtext::_('HIKASHOP_TOTAL'); ?>">
<span class="hikashop_checkout_cart_final_total">
<?php
$total = $this->currencyHelper->format($this->full_total->prices[0]->price_value_with_tax,$this->full_total->prices[0]->price_currency_id);
if (isset($_POST["donation"]))
$total += $_POST["donation"];
echo $total;
?>
</span>
</td>


So the client enter the price and press enter or click on the button "Ok".
The page refresh and print the new price, but instead of print the price for example : 32,42 €
It print only : 32

And I don't know how to correct this...

And for the mail sent to the client and vendor I want to also put the donation line to inform them.
But how can I send and retrieve the value to the file where I custom the mail sent ?

Thank you,

Last edit: 9 years 1 week ago by newt.

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 1 week ago #220737

Hi,

You should add the donation before the call to the format function. For example:

$total = $this->currencyHelper->format($this->full_total->prices[0]->price_value_with_tax+(float)@$_POST["donation"],$this->full_total->prices[0]->price_currency_id);
echo $total;
Also, I would recommend to store your donation in $_SESSION so that you can then use it in the emails and also use it in your checkout, when the value is not sent by the input.

The emails can be edited via the menu System>Emails with the Business edition.
Otherwise, you have to directly edit the files in the folder media/com_hikashop/mail/

The following user(s) said Thank You: newt

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

  • Posts: 36
  • Thank you received: 0
9 years 1 week ago #220793

Thank you !

How can I use $_SESSION to store the donation value ?

Yes I know where to edit this :)

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 week ago #220795

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

  • Posts: 36
  • Thank you received: 0
9 years 1 week ago #221009

Thanks for the link but I don't understand all...

The file I edit is cart.php from the views hikashop/checkout/joomspirit_76.
It says to replace session_start() with the code but I don't find session_start().
Should I place it below the line at the beginning of the file ?

defined('_JEXEC') or die('Restricted access');


Which path should I add to this line ? :

define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));

The path to the cart.php file ?

I tried

./components/com_hikashop/views/checkout/tmpl

but it doesn't work..

Regards,

Last edit: 9 years 1 week ago by newt.

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 1 week ago #221034

$_SESSION is like $_POST.
So you can set it like that:

if(!empty($_POST["donation"])) $_SESSION["donation"] = $_POST["donation"];

and then use it like you would use $_POST. The great thing is that once you set it, you can use it anywhere, even on other pages after that.

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

  • Posts: 36
  • Thank you received: 0
9 years 1 week ago #221195

Thank you

But when I go the the file where I can edit the mails sent to the client ? I can't display the value of $_SESSION;
How can the program know for which command is the donation ?

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 1 week ago #221210

Hi,

You can edit the emails via the menu System>Emails.
There, in the "HTML version" area, you can use such code:

<?php echo $_SESSION["donation"]; ?>
and it should work.

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

  • Posts: 36
  • Thank you received: 0
9 years 1 week ago #221297

I tried this but it display nothing..
Even the total is wrong it doesn't add the donation value.

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 1 week ago #221354

Hi,

That's normal that the total doesn't change. With the code you did before, you simply change the total displayed on the checkout, but not the total in the database.

What you need to do is a small HikaShop plugin implement the onAfterCartProductsLoad(&$cart) trigger of HikaShop in order to set the donation value as an additional in the $cart->additional array.
The system will then add it to the display automatically everywhere.
An example of implementation of that can be found here:
www.hikashop.com/forum/taxes/873285-fix-tax-import.html#190511

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

  • Posts: 36
  • Thank you received: 0
9 years 5 days ago #221661

Thank you for the plugin.

I installed it but don't know how to use it ?
I actived it and went in Hikashop's Option.
I clicked on the new button but I can only fill a name and some others but there isn't mention of any price or something ?

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 4 days ago #221826

Hi,

You can't just use it for what you want to do. You need to modify its code.
When you configure it via the new button of the System>Plugins menu, you'll get a screen with the options of the plugin and you'll be able to set the price that you want to be displayed on the cart in the checkout.

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

  • Posts: 36
  • Thank you received: 0
9 years 4 days ago #221898

I understand but the I didn't manage to keep the value donation.
I saved it in $_SESSION and you said I could recover it everywhere but when I want to display it it doesn't work.

The plugin you gave me allow me to add the donation value to the total right ?

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 3 days ago #221915

Hi,

I didn't say that you could get the value from anywhere if you put it in the SESSION. I only said that you would be able to get it in the order creation email by doing that.

And no, the plugin global cart fee doesn't allow you to add the donation value to the total. What it does is it allows you to add a fixed value to the total of the cart. As I said, in order for it to do what you want, you'll have to modify its code.

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

  • Posts: 36
  • Thank you received: 0
8 years 11 months ago #222914

Ok :)
I got it for the value. I used it but how can I display it too in the other mail ? I have to recover it in the notification of the command status how can I do it ?

I can't just put it in the database where is the final total ?

Ok i'll try to understand it and modify

Thank you !

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
8 years 11 months ago #222989

You'll have to store it in the hikashop_order table together with the rest of the order data and then you'll be able to access it in the order status notification email.
For example if you add your data in a new column of that table that you call "my_data", you can use the tag below in the HTML version of the email and it will display your data in the email:
{VAR:order.my_data}

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

  • Posts: 36
  • Thank you received: 0
8 years 11 months ago #223106

Te hikashop_order table is $data ?
Can I do $data->order->my_data = 'my donation value'; ??

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
8 years 11 months ago #223109

I don't know. Where are you trying to do that ?
In which function of which file ?

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

  • Posts: 36
  • Thank you received: 0
8 years 11 months ago #223251

It is in the order creation email file.

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

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
8 years 11 months ago #223259

Well, that won't do anything. There is no save done on $data->order after that code.
So you need to do the save yourself:

$orderClass=hikashop_get('class.order');
$order = new stdClass();
$order->order_id = $data->order_id;
$order->my_data = 'my donation value';
$orderClass->save($order);

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

Time to create page: 0.099 seconds
Powered by Kunena Forum