Post by rolandkeys » Thu May 17, 2012 8:33 am

Hi everyone,

I'm trying to get the names of products that are in checkout process. For example: a user is about to confirm that he wants to buy product1 and product2; so I need to store only the name of the products in a variable and invoke it in a paymentcontroller class. I actually know how to do this echo'in it in a tpl file, but when i try to use the same code to invoke it in the controller class, it sends error.

To get product names I'm using this array in a PaymentController class

Code: Select all

$products = $this->cart->getProducts();
		foreach ($products as $product) {	
			$this->data['nameproducts'][] = array(
					'name'       => $product['name']
					);
					
			
		}
Then I try to convert it to a single string, because I have to pass it through an URL.

Code: Select all

$this->data['productnames'] = implode(', ', $nameproducts);

$this->data['action'] = "https://domain.com/LinkDeamon.cfm?total=".$this->data['total']."&description=".$this->data['productnames'];
Thanks in advance for any help!

Newbie

Posts

Joined
Thu May 17, 2012 7:26 am

Post by Avvici » Sat Jun 16, 2012 7:35 am

Because you are trying to implode a multidimensional array which is this:

Code: Select all

$this->data['nameproducts'][] = array(
               'name'       => $product['name']
               );
Just work with the cart array and use the variables you already know to be true: $product['name']

This: $this->data['nameproducts'] is just passing it to the TPL which is irrelevant in your case.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by straightlight » Sun Jun 24, 2012 8:23 pm

Another solution would be to use the product ID key amongst the multidimensional array that would match with your second array. This methodology is already used in OpenCart in some places and especially on the admin products to load the products and the product descriptions but this time by languages.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Avvici » Sun Jun 24, 2012 8:40 pm

What part of what you said is not what I suggested? l ol

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by straightlight » Sun Jun 24, 2012 8:42 pm

Where the product ID variable has not been added in your block code straightforward.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Avvici » Sun Jun 24, 2012 11:54 pm

straightlight wrote:Where the product ID variable has not been added in your block code straightforward.
::) okay okay....

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC
Who is online

Users browsing this forum: No registered users and 1 guest