Add same product to cart with two line items

  • Posts: 4
  • Thank you received: 0
9 years 10 months ago #218789

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5.9
-- Browser(s) name and version -- : n/a
-- Error-message(debug-mod must be tuned on) -- : No errors

We are using a third-party extension to offer room reservations. This extension has no built-in checkout process, and a very limited range of checkout plugins. We are also using Hikashop to sell physical products, and would like to integrate the reservation system into Hikashop's checkout process.

I have created a single "umbrella" product in Hikashop - all reservations will use product ID when they are added to the cart. I have created a plugin which successfully adds the product to the session cart as a reservation is finalized. However, if more than one reservation is finalized in the same session, Hikashop will consolidate all reservation products into a single line-item in the cart. Is there a way to force Hikashop to consider each addition of a single product ID as a separate line-item?

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

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #218833

Hi,

I think that the easiest way would be to create a custom item field, and populate that field when adding the product to the cart.
That way it will display one item per line, and you can do a little view override to not display the custom item field info in the cart.

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

  • Posts: 4
  • Thank you received: 0
9 years 10 months ago #218915

I've looked at [Display -> Custom Fields]. When I try to add a new one, the table is hard-coded to "address". Will this affect a cart product record in the way you describe?

Looking at the feature guide, it appears this option is only available for products with the "Essential" or "Business" version. Is that correct? Is there any way to accomplish this with the "Starter" version we are currently using?

Last edit: 9 years 10 months ago by routinet. Reason: additional info

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

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #218923

Hi,

Yes my bad, these kind of custom fields are only available in the commercial versions of HikaShop. I forgot to mention it.
So in your case there could be another solution, it's to edit the view "checkout / cart", "product / cart", the order views and emails too and edit the code of the foreach of the products in order to display an item with a certain quantity in as many line as its quantity.

So a bit more work, but it is possible.

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

  • Posts: 4
  • Thank you received: 0
9 years 10 months ago #219012

That will not affect the model, though. The reservations do not all have the same price. It is a real possibility for multiple reservations during a session. Each reservation's price would be affected by date(s), number of attendees, and some other attributes. I'm not adverse to overriding the views, but I am very hesitant to override the model... we would like to preserve the upgrade path.

Do you have any other recommendations?

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 10 months ago #219055

Hi,

I still recommend to go with a custom item field.
In fact, if the price must vary, I would recommend to use the donation plugin:
demo.hikashop.com/index.php/en/hikashop/...t-page/donation-page
That way, you can do the integration simply by redirecting the customer from your reservation extension to the add to cart URL of your product with the value of the custom item field(s) in the URL so that your customer is directly taken to the checkout with the correct price to pay and the data from the reservation extension in the cart. Then, he just have to checkout normally and that's it.
Here is a thread which explains how should look like such add to cart link:
www.hikashop.com/forum/2-general-talk-ab...-product-fields.html

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

  • Posts: 4
  • Thank you received: 0
9 years 10 months ago #219815

We have purchased and installed the Business version of HikaShop, and I have set up a custom field. Do you have an example of how I can set this programmatically?

My plugin is hooking into the Koparent extension as it completes a reservation. The config page for the plugin allows the admin to designate on which Hikashop product id it should act ($this->_hikapid, after initialization).

As my plugin is loaded, I instantiate the cart like this:

$this->_hikacart = hikashop_get('class.cart');
      $this->_hikacart->loadCart();
      $this->_hikacartitems = $this->_hikacart->get();

As the user completes the reservation form, Koparent's save event fires (onContentAfterSave, with a particular context for reservations). My plugin attempts to add an item to the current session's cart like this:
$this->_hikacart->update($this->_hikapid,1)

This works fine, and adds the product to the cart, but additional saves do not appear as additional line items - all cart items of product id "X" are aggregated into a single line item. I do not see any access to the custom fields through hikashopCartClass::update(). I see where it *may* be possible in hikashopCartClass::updateEntry(), but I'm unsure of the structure of the parameters needed for that method.

Can you provide any further guidance? My end goals are to 1) have each reservation be handled as a separate line item in Hikashop, and 2) have Hikashop use the price determined by Koparent.

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 10 months ago #219845

Hi,

The link I gave you explains that:
www.hikashop.com/forum/2-general-talk-ab...ct-fields.html#19870

$items = array();
$items = 123;
$data=array('item'=>$items);
JRequest::setVar('data',$data);
$class = hikashop::get('class.cart');
$class->update(23, 1);

There, the custom item field with the column name "tracking_id" is set with the value 123 for the product with the id 23 and that product is added to the cart with the quantity 1.

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

Time to create page: 0.078 seconds
Powered by Kunena Forum