Cart: How to add Custom Field value to prices?

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #203407

-- HikaShop version -- : HikaShop Business: 2.4.0
-- Joomla version -- : Joomla! 3.4.1

Hello

We create engravings as a service. There are start-up costs. I have defined for products a "custom fiels" (text). There, the initial costs are entered in the backend. Now I want to show this also in the cart and add to the subtotal and total price.

File: checkout / cart.php

Line 147, is inserted:
if ($ this-> row->field_fixkosten_artikel)
echo 'Vorbereitung für diesen Artikel ';

Line 258 (original 256), is inserted:
if ($ this-> row-> field_fixkosten_artikel)
{
/ * full_total-> prices [0] -> price_value += $ this-> row-> field_fixkosten_artikel * ????????? * /
$ this-> full_total-> prices [0] -> price_value_with_tax += $ this-> row-> field_fixkosten_artikel;
echo $ this-> row-> field_fixkosten_artikel;
}

Questions:
- How do I get it formatted the same as the product price?
- How do I calculate the price without tax?

Regards,
Petar Ristanovic
www.sokart.ch


Attachments:

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #203476

Hi,

In that case, you should not modify the views. You should instead create a product price override plugin to modify the price of the product based on the custom field.
You can use as an example the donation plugin: demo.hikashop.com/index.php/en/hikashop/...t-page/donation-page

The following user(s) said Thank You: sokartch

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #203515

Ok. I'll try it. Thank You Very Much.

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #203826

Hello
I have business license but can not find a donation plugin in Joomla list.
What went wrong?

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #203851

Hi,

I don't see why the plugin wouldn't be there unless it has been manually uninstalled.
Do you still have the files in the folder plugins/system/custom_price/ ?
In that case, you can zip them and install the package manually via the Joomla installer like a normal extension and it will add it back.

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #203858

Hi
I think, the problem was the name "HikaShopCustom Price plugin".
You wrote "You can use as an example the donation plugin..." and I searched for "donation"... Sorry.
Today, after "plugins/system/custom_price" i searched for "custom"...
Regards

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #203862

Hi,

That's the old name of the donation plugin which has been changed a while back but which you would still have it you updated from an old version as the name of already installed plugins is not updated when you update HikaShop.

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #204111

Hello
Sorry. I have to ask you again.
I have to add an amount to the sum of the product.
- Article (backend), I define the price eg USD 10.00 per piece and in the custom field USD 9.90 Preparation costs are not of this article.
- On the product side (front-end) I order 10 articles. In the "Specifications" I can see "Preparation costs 9.90".
---
Now I switch to the cart:
In the row for this product as I can see, USD 100, but I have to get 109.90
---
Do you really think that can do that a plug-in based on the donation (custom price) plugin?

Regards
Petar Ristanovic
www.sokart.ch

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 5 months ago #204170

Hi,

I will more recommend you to use the "shipping price per product" or to use a custom plugin to set some "order additional".
You can also use a custom plugin to perform a product price override using the original product price and a custom field value ; but it won't give you the details for the "preparation cost" and the price will be "merge" with the product.
Placing the price into the shipping or in a separate field of the order footer will be more like your requirements.

Here a sample plugin for order additional use
www.hikashop.com/forum/checkout/872829-w...s-a-gift.html#179177

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: 73
  • Thank you received: 0
9 years 5 months ago #204743

Hello

Some products in a cart may have "flag". I needs to delete those products in the cart.
public function onBeforeCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
$cartContent = $cartClass->get();
$c = $cartClass->loadFullCart();
if ( count($c->products) ) {
foreach($c->products as $product) {
if( !empty($product->field_forced) ) { // if product has been forced in the cart
??? how to delete a product/item
}
}
unset($product);
}
...


For products in the basket certain products need to be added ...
public function onAfterCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
$cartContent = $cartClass->get();
$c = $cartClass->loadFullCart();
if ( count($c->products) ) {
foreach($c->products as $product) {
if( !empty($product->field_vorbereitung) ) { // if product has preparation costs
??? how to add a product/item
}
}
unset($product);
}
...

In the discussions in the forum terms and examples are shown. Where can I find detailed descriptions of classes, members and methods?

Last edit: 9 years 5 months ago by sokartch.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #204782

Hi,

There are no detailed descriptions of classes, members and methods. No where.
Otherwise, we would have published it.
If you want to know what a function of a class does, you need to look at its file and read the code.
For example, for the cart manipulation functions, you can look at the file administrator/components/com_hikashop/classes/cart.php

However, the simplest would be to redirect to the add to cart URL of the product in order to add it (and with a quantity of 0 and the add to 0 in the URL to remove it).
www.hikashop.com/forum/4-how-to/48848-ad...tom-page-solved.html

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #205050

Hello

---
However, the simplest would be to redirect to the add to cart URL of the product in order to add it (and with a quantity of 0 and the add to 0 in the URL to remove it).
---
My feeling tells me that it will not work from a function triggered ...
public function onBeforeCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {

If yes: How do I remove a product in onBeforeCartUpdate from the cart?

I'm desperate and think about giving up. Two days I try to understand the source and to find a way.

Again:

- I need for certain products "preparatory costs" as a product to add.
- I have developed a own plugin ...
- Adding product works well in the
public function onAfterCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
$cartContent = $cartClass->get();
$c = $cartClass->loadFullCart();
if ( count($c->products) ) {
foreach($c->products as $product) {
if( !empty($product->field_vorbereitung) ) { // if product has preparation costs
$cartClass->updateEntry('1',$cartContent,(int)$product->field_vorbereitung,'1',false,$type,$force);
}
}
unset($product);
}
...

I want to delete items marked with (in backend I set field_forced = '1';) in:
public function onBeforeCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
$cartContent = $cartClass->get();
$c = $cartClass->loadFullCart();
if ( count($c->products) ) {
foreach($c->products as $product) {
if( !empty($product->field_forced) ) { // if product is "preparation costs"
?????????????????
}
}
unset($product);
}

In this way the list is always up to date when the "real" products will be deleted.

Regards!

Last edit: 9 years 5 months ago by sokartch.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #205051

Hi,

You could try with:
$cartClass->updateEntry(0,$cartContent,(int)$product->cart_product_id,0,false,$type,$force);

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #205186

Hi

Yes, I'm still alive :)

- I was able to organize without deleting product from basket. Snapshuss "First.jpg"



- I now have a problem if I will add the same product twice in the basket. I expect that only the number in the basket will be updated. Image "Second.jpg". For this, the total price calculation is incorrect. I could not find the cause. Do You have an idea?



The Database (phpMyAdmin)

Attachments:
Last edit: 9 years 5 months ago by sokartch.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #205191

I think that you want to add the line:
$cartClass->mainProduct = null;
in you code before the updateEntry, otherwise, the system thinks that the extra product you add is an option of the product and it gets messed up.

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #205287

Hi
- It has improved with the main product and price mess.
- Additional product does not seem to be properly "registered". It adds him repeatedly (at Add to cart of main product) instead to increase his account. In the database I can not detect a difference between products.... This may be the cause that we can not delete this "addional" article.
Our client is getting impatient, we can ever solve this problem?

Product add, delete or change places should be provided in the Cart class. This should be able to be used in the plug-ins without side effects.

Attachments:
Last edit: 9 years 5 months ago by sokartch.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #205353

Hi,

The product being duplicated by updateEntry happens when it checks if another product in the cart already has the same product_id, the same custom item fields values and the same options. It's done in the big

if($type=='product'){
block of code in the updateEntry function of the class.cart. I don't see why that wouldn't work.

The cart class was never meant to be used by other developers. On top of that, the structure dates from 5 years ago at a lot to it has been added to it to support the many functionalities we added in that time rendering it a lot more cryptic than it was meant.
We're aware of that.
We're actually rewriting the whole add to cart system to make it clean, faster, more powerful and simpler to use.

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

  • Posts: 73
  • Thank you received: 0
9 years 5 months ago #205910

Hi

I solved almost all the problems ...

Delete a product:
public function onBeforeCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
...
$cartClass->updateEntry(0,$cartContent,(int)$product->cart_product_id,0,false,'item',$force);
...
}

Add a product:
public function onAfterCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
...
$cartClass->mainProduct = null;
$cartClass->updateEntry('1',$cartContent,(int)$product->field_vorbereitung,'1',false,'product',$force);
...
}

I have this code to change the price of a product. But so calculated prices will not be applied in the Shopping Cart. Why and what can I do?
---
public function onBeforeCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force) {
$price_factor = 1.0;
$cartContent = $cartClass->get();
$c = $cartClass->loadFullCart();
if ( count($c->products) ) {
foreach($c->products as $product) {
if (!empty($product->field_must_be_engraved)) {
$price_factor = (float)$product->field_preis_faktor;
} else if (empty($product->field_forced)) {
$product->prices[0]->unit_price->price_value *= $price_factor;
$product->prices[0]->unit_price->price_value_with_tax *= $price_factor;
$product->prices[0]->price_value *= $price_factor;
$product->prices[0]->price_value_with_tax *= $price_factor;
...
}
---

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #205930

Hi,

The prices of the products are loaded and calculated dynamically on each page. Setting them in the $products array in the onBeforeCartUpdate won't do anything.

If you want to override the prices of products in the cart, what you want is to take example on the donation plugin of HikaShop:
demo.hikashop.com/index.php/en/hikashop/...t-page/donation-page
It overrides the price of the products in the cart (what you want to do)

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

Time to create page: 0.120 seconds
Powered by Kunena Forum