Post by dansmithpm » Fri Dec 16, 2011 9:26 pm

Firstly let me apologise if this has been raised elsewhere, I've been searching for a day or so and not found anything.

I'm integrating a product designer into opencart. This is a flash component which is self contained and allows the user to dynamically create items such as mugs, t-shirts etc. I have a new install of 1.5.1.3

The component has it's own add to cart button which triggers a php script. I'm trying to get that script to pass some further data through to the cart, and in turn, through to an order. The component creates an XML file and custom product images for the order.

I've found elsewhere on the forum how to add an item to a cart via posting a form :

Code: Select all

<form action="index.php?route=checkout/cart" method="post">
<input type="hidden" name="product_id" value="50">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="design" value="12">
<input type="submit" name="submit" value="submit">
</form>
(this would be done via curl once I've got it all sorted out), so that's not a problem. However, I can't see how to add an additional variable to that post and have it registered in the cart.

I've tried adding to the cart.php controller the following line

Code: Select all

'design'   => $this->request->post['design'],
as below

Code: Select all

$this->data['products'][] = array(
'key'      => $product['key'],
'thumb'    => $image,
'name'     => $product['name'],
'model'    => $product['model'],
'option'   => $option_data,
'quantity' => $product['quantity'],
'stock'    => $product['stock'],
'reward'   => ($product['reward'] ? sprintf($this->language->get('text_reward'), $product['reward']) : ''),
'price'    => $price,
'design'   => $this->request->post['design'],
'total'    => $total,
'href'     => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
and then in the cart.tpl add

Code: Select all

<td><?php echo $product['design'];?></td>
and process further from there, though it never makes it through. The product is added to the cart via product id and quantity, though that's as far as I've got.

I assume that once this is sorted, to add to the order shouldn't be too much of an issue, I think I'm just misunderstanding the framework etc.

Really appreciate any help !! ???

Newbie

Posts

Joined
Fri Dec 16, 2011 9:15 pm

Post by hydrowire » Fri Dec 16, 2011 10:13 pm

Hi dansmithpm,

Welcome to OpenCart.

When you add a product to cart, it only takes in 3 variables: $product_id, $quantity, $option. If you want to add extra variables, the only way you can do it without much modification to the cart session data structure is through the $option variable.

Open and edit catalog/controller/checkout/cart.php, search for this line that calls the add function:

Code: Select all

$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
or

Code: Select all

$this->cart->add($this->request->post['product_id'], $quantity, $option);
depending if you use index() or ajax update(). Either one, and just before that line, add in your variables through $option:

Code: Select all

$option['design'] = 12;
This is not all. What you did in your post is not complete and will not work because you need to extract the variable from the cart session. Open and edit system/library/cart.php, in getProducts() function, look around line 217 and add after:

Code: Select all

$product_data[$key] = array(
and in your case, add:

Code: Select all

'design'   => $options['design'],
This is the basic idea of adding extra variable to each cart item. Now, your code should be able to retrieve the extra variable.
*if possible, keep modification of system/library/cart.php to the minimum, because this is something to the core, and is better not to mess it up.

Developing Quality OpenCart Extensions since 2011.
View my extensions


User avatar
Active Member

Posts

Joined
Wed Jan 26, 2011 5:41 pm


Post by dansmithpm » Fri Dec 16, 2011 10:42 pm

Thanks so much for the quick response, will have a go later on! :)

Newbie

Posts

Joined
Fri Dec 16, 2011 9:15 pm

Post by dansmithpm » Sun Dec 18, 2011 5:16 am

got this working, couple of changes from as posted, so put back for reference for 1.5.1.3

catalog\controller\cart.php

Code: Select all

$option['design']=$this->request->post['design'];
added before

Code: Select all

$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);	


then round about line 177 in the section starting

Code: Select all

$this->data['products'][] = array(
added

Code: Select all

'design'   => $product['design'],
in system\library\cart.php in section starting (around line 217)

Code: Select all

$product_data[$key] = array(
added

Code: Select all

'design'		  => $options['design'],
then in cart.tpl in view\theme\template-name\template\checkout\cart.tpl
added

Code: Select all

 $product['design']
Thanks for the support, great forum for a great product! ;)

Newbie

Posts

Joined
Fri Dec 16, 2011 9:15 pm

Post by satish21 » Tue May 08, 2012 9:58 pm

Hello Team,

I am newbie with opencart. I am using opencart 1.5.2.1.

As per html layout, sidebar right contain cart, which content list of product added to cart with subtotal, VAT and total cost.

I have manage every thing properly except the "+" & "-" product quantity functionality.

"+" & "-" are the two buttons besides to product quantity.

By using these two buttons user can able to increase and decrease product quantity.

For more details I have attached screenshot. Please check it.

I am not able to manage this "+" and "-" functionality.

So please anybody support me to manage the "+" & "-" functionality.

Thanks in advance.

Regards,
Ankur.

Newbie

Posts

Joined
Tue Jul 26, 2011 1:02 pm

Post by pcMagic » Thu Jul 19, 2012 2:52 am

A couple of errors in the above...
dansmithpm wrote:got this working, couple of changes from as posted, so put back for reference for 1.5.1.3

catalog\controller\cart.php


NOT
catalog\controller\cart.php

SHOULD READ
catalog\controller\checkout\cart.php

Code: Select all

$option['design']=$this->request->post['design'];
added before

Code: Select all

$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);	


then round about line 177 in the section starting

Code: Select all

$this->data['products'][] = array(
added

Code: Select all

'design'   => $product['design'],
in system\library\cart.php in section starting (around line 217)

Code: Select all

$product_data[$key] = array(
NOT
$this->data[$key] = array(


SHOULD READ
$product_data[] = array(


added

Code: Select all

'design'		  => $options['design'],
then in cart.tpl in view\theme\template-name\template\checkout\cart.tpl
added

Code: Select all

 $product['design']
Thanks for the support, great forum for a great product! ;)
I agree Dan.. an excellent product and thank you for posting the code - I would not have managed it without your notes. ;D

Newbie

Posts

Joined
Wed Jul 18, 2012 8:07 pm

Post by pcMagic » Fri Jul 20, 2012 12:30 am

I have managed to generate customised data in the product page & transfer it to be displayed in the cart but am unable to add this to the product in the order.

Can anyone tell me which files control the saving of the fields to the order_product table ?

Newbie

Posts

Joined
Wed Jul 18, 2012 8:07 pm

Post by tigerton » Tue Aug 28, 2012 10:17 pm

Hi!

I'm trying to achieve something like this.. I've got a custom inputfield in the productpage where the user can enter a name for the product.. I want to pass this along to the cart (and later to checkout) but I can't seem to get this to work!

I'm using v 1.5.3.1...
I tried adding everything in the way you've described but I get an error of undefined index from the cart.php in system/library

Code: Select all

Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242
this "$product_data[] = array(" I cannot find.. I do however find the code you've put in red :)

Honestly I'm getting a bit confused from these corrections and whatnot, perhaps some kind soul could make a clear "tutorial" of how to do it! I'm also wondering how I would pass the extra variable through from the product.tpl file..?
Last edited by tigerton on Tue Aug 28, 2012 10:35 pm, edited 1 time in total.

Newbie

Posts

Joined
Fri Mar 19, 2010 3:36 pm

Post by labeshops » Tue Aug 28, 2012 10:34 pm

tigerton wrote:Hi!

I'm trying to achieve something like this.. I've got a custom inputfield in the productpage where the user can enter a name for the product.. I want to pass this along to the cart (and later to checkout) but I can't seem to get this to work!

I'm using v 1.5.3.1...
I tried adding everything in the way you've described but I get an error of undefined index from the cart.php in system/library

Code: Select all

Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242
Honestly I'm getting a bit confused from these corrections and whatnot, perhaps some kind soul could make a clear "tutorial" of how to do it! I'm also wondering how I would pass the extra variable through from the product.tpl file..?

Is there any reason you couldn't just use a text option field for this that is already built into opencart? Just do an option field: name as a text field and assign it to the product.

Running Opencart v3.0.3.9 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by tigerton » Wed Aug 29, 2012 10:05 pm

labeshops wrote:
tigerton wrote:Hi!

I'm trying to achieve something like this.. I've got a custom inputfield in the productpage where the user can enter a name for the product.. I want to pass this along to the cart (and later to checkout) but I can't seem to get this to work!

I'm using v 1.5.3.1...
I tried adding everything in the way you've described but I get an error of undefined index from the cart.php in system/library

Code: Select all

Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/system/library/cart.php on line 242
Honestly I'm getting a bit confused from these corrections and whatnot, perhaps some kind soul could make a clear "tutorial" of how to do it! I'm also wondering how I would pass the extra variable through from the product.tpl file..?

Is there any reason you couldn't just use a text option field for this that is already built into opencart? Just do an option field: name as a text field and assign it to the product.
... *walks away in shame*
You're right, I could just as well use an inbuild textinput option.. works like a charm thanks! However I still want another value to pass along that's not gonna be something the user inputs. It would be like an hidden input where I can add numbers (product-ids) to the value parameter and that would be passed along to the cart.. so basically the same thing as the "design" in this thread.

So would still be very grateful for some help!

Newbie

Posts

Joined
Fri Mar 19, 2010 3:36 pm

Post by labeshops » Wed Aug 29, 2012 10:47 pm

You could use something like options boost that lets you set a different sku based on the option.

Running Opencart v3.0.3.9 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by tigerton » Thu Aug 30, 2012 3:08 pm

labeshops wrote:You could use something like options boost that lets you set a different sku based on the option.
Unfortunately options boost doesn't do the trick for me.. already tried that and turned out even with lots of hacking it didnt do what we needed so now im using Product accessories instead. But neither is doing what I need, I need a hidden input which i can give values dynamically using jquery which will then be passed along at "add to cart". Same as the guy in this thread basically!

Newbie

Posts

Joined
Fri Mar 19, 2010 3:36 pm

Post by tigerton » Wed Sep 05, 2012 10:40 pm

So...

Anyone able to help me with this?!
I'm running Opencart v1.5.3.1 and this is exactly how i do it:

In product.tpl added input

Code: Select all

<input type="hidden" name="design" size="2" value="666" />
In catalog/controller/checkout/cart.php
Find:

Code: Select all

$this->data['products'][] = array(
          			'key'      => $product['key'],
          			'thumb'    => $image,
					'name'     => $product['name'],
          			'model'    => $product['model'],
          			'option'   => $option_data,
          			'quantity' => $product['quantity'],
          			'stock'    => $product['stock'],
					'reward'   => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
					'price'    => $price,
					'total'    => $total,
					'href'     => $this->url->link('product/product', 'product_id=' . $product['product_id']),
					'remove'   => $this->url->link('checkout/cart', 'remove=' . $product['key']),
					
				);
And add this to the bottom:

Code: Select all

'design'   => $product['design'],
Then in the same file find:

Code: Select all

 $this->cart->add($this->request->post['product_id'], $quantity, $option);
And add this on the line before:

Code: Select all

$option['design']=$this->request->post['design'];
Then open file system\library\cart.php
and find:

Code: Select all

$this->data[$key] = array(
						'key'             => $key,
						'product_id'      => $product_query->row['product_id'],
						'name'            => $product_query->row['name'],
						'model'           => $product_query->row['model'],
						'shipping'        => $product_query->row['shipping'],
						'image'           => $product_query->row['image'],
						'option'          => $option_data,
						'download'        => $download_data,
						'quantity'        => $quantity,
						'minimum'         => $product_query->row['minimum'],
						'subtract'        => $product_query->row['subtract'],
						'stock'           => $stock,
						'price'           => ($price + $option_price),
						'total'           => ($price + $option_price) * $quantity,
						'reward'          => $reward * $quantity,
						'points'          => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
						'tax_class_id'    => $product_query->row['tax_class_id'],
						'weight'          => ($product_query->row['weight'] + $option_weight) * $quantity,
						'weight_class_id' => $product_query->row['weight_class_id'],
						'length'          => $product_query->row['length'],
						'width'           => $product_query->row['width'],
						'height'          => $product_query->row['height'],
						'length_class_id' => $product_query->row['length_class_id'],
					);
(There was no "$product_data[] = array(".. suppose this is another version of opencart).
In this I add (last):

Code: Select all

'design'        => $options['design'],
Then in both catalog/view/theme/mytheme/template/checkout/cart.tpl and catalog/view/theme/mytheme/template/module/cart.tpl I try to output the value:

Code: Select all

<?php
        	if($product['design']){
        		echo $product['design'];
        	}
        	?>
inside the foreach-loop..

this is the error the cart module throws:
Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/catalog/view/theme/boomwatches/template/module/cart.tpl on line 12

And this is the error the cart in checkout throws:
Notice: Undefined index: design in /home/boomwatch/domains/boomwatches.se/public_html/vqmod/vqcache/vq2-catalog_controller_checkout_cart.php on line 245

And this is the line which throws the error:
$this->data['products'][] = array(
'key' => $product['key'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'stock' => $product['stock'],
'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
'price' => $price,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),
'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key']),
'design' => $product['design'],
);

VERY grateful for any light on this!

Newbie

Posts

Joined
Fri Mar 19, 2010 3:36 pm

Post by tigerton » Thu Sep 06, 2012 8:07 pm

Update:

So I'm still getting the error.. I've noticed however that the value is actually passed to the cart and the checkout..
The issue seems to be that since I'm using a module called "product accessories", when I add the product it adds multiple products and since the others don't have a input called "design" it throws an error.. Have to solve this somehow since it's keeping the add to cart from functioning properly and displays an error on top of page. Any idea how to just set the design to null when there is none?

EDIT:

Managed to solve this! Here's how for anyone attempting the same:
The issue was indeed with the Product accesories module.. It adds it's own

Code: Select all

$this->cart->add($accessory_id, $accessory_quantity, array());
below the other one inside checkout/cart.php.. Notice that where the $options normally is it's just an empty array. So I just changed it to

Code: Select all

$this->cart->add($accessory_id, $accessory_quantity, array('design' => ''));
in order to pass an empty "design" value so that the systemfile doesn't try to get a value that doesn't exists..

So like I said now I get the value in both the cart module and the checkout.. By getting it in the cart module as well you find

Code: Select all

$this->data['products'][] = array(
and add

Code: Select all

'design'   => $product['design'],

to it!

Haven't tried it all the way to the order yet.. hoping it'll work!

Newbie

Posts

Joined
Fri Mar 19, 2010 3:36 pm

Post by zwik » Fri Sep 07, 2012 10:50 pm

I have tried all the options mentioned above to pass the data to cart but it is not getting through. Only the amount of design i.e $option['design'] = 12; Only number 12 or if i change it, it is visible but nothing else is shown.

I have one page on which the customer fill the cart. Then on next page i have two options for the clients. One is In Store pickup. In this option the client will simply pick the product from the store. The second option is By Mail. The customer will fill the form and at the end there is drop down box for shipping method. Only one amount is present which i want to add it in the cart on this page. The cart should mention shipping method and the amount of $ 2.95, which should be added in the total cart amount.
I will appreciate if somebody help me out.

Newbie

Posts

Joined
Wed Jun 27, 2012 12:47 am

Post by zwik » Sat Sep 08, 2012 3:53 pm

Finally my problem was solved the data is shown in the cart. My mistake was that in cart.tpl file i have copied <td><?php $product['design'];?></td>. It was not working or not showing value in cart. The correct script which has start working is <td><?php echo $product['design'];?></td>. After changing it to this script it started working.
My question is how can i sum up a single value in cart at a later stage when customer fill the cart. The value which is the cost of shipping method should be added in the next step when the client has filled the cart. It is because there are two kind of customers one who need shipping method should get the total price with shipping method and the one who dont need should not get the shipping method.
How can i do it. I am a newbie and will appreciate if someone can help me out.

Newbie

Posts

Joined
Wed Jun 27, 2012 12:47 am

Post by zwik » Sun Sep 09, 2012 3:52 am

I am passing numeric value through a form to the cart. I want that it should be displayed after Subtotal and then should be added in the total amount. I was able to pass the value to cart but how it should be added in the total i dont know. I have tried but not getting through. If somebody can help me i will appreciate it.

Newbie

Posts

Joined
Wed Jun 27, 2012 12:47 am

Post by timparnell » Sat Nov 24, 2012 9:27 pm

I have a similar issue. I have greatly modified the options so you can put in a global setting.
the data i am passing to the cart is
option[14] 63
option[15] 67
product_id 1099
quantity 1

Everything is ok except i need to modify system/library/cart to pick up the passed data

i can set the options manually to display in the cart but I can't extract the data to pass into the
$option_query = $this->db->query
$option_value_query = $this->db->query

but i can't seem to extract the relevant info from the session data....
Anyone help on ths.

tim@pointreddesign.co.uk | http://www.pointreddesign.co.uk


User avatar
New member

Posts

Joined
Wed Feb 01, 2012 11:03 pm
Location - Norwich, Norfolk, UK

Post by jagdish2157 » Tue May 28, 2013 5:00 pm

is there any way in opencart, when customer find something like xyz product in my shop if not found then customer can give name of that product xyz so it can be deliver him by On-demand feature. If it is possible then please reply
Thanks

New member

Posts

Joined
Tue May 28, 2013 4:45 pm


Post by MickelMiky » Fri Jul 05, 2013 4:32 pm

I assume that once this is sorted, to add to the order shouldn't be too much of an issue, I think I'm just misunderstanding the framework etc.

Newbie

Posts

Joined
Fri Jul 05, 2013 4:21 pm
Who is online

Users browsing this forum: No registered users and 9 guests