Add characteristics column to cart

  • Posts: 43
  • Thank you received: 3
9 years 4 months ago #208073

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.3.29
-- Browser(s) name and version -- : IE, FF, Safari

Hi all,

in my setup I´m using different characteristics, but only one for each product.
I don´t like to append the characteristics to the product´s name. This also causes an error in the sj minicart module I´m using.
So the option needs to be turned off.
However, I would like to display the characteristics on the cart. I already added a new column but have my issues with the related php code that needs to be inserted.

Any idea how this can be done?

Thanks.

Attachments:
Last edit: 9 years 4 months ago by disc.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 4 months ago #208082

Hi,

The characteristics value of each variant are stored in $row->characteristics when yo'u're in the "cart" file of the "checkout" view.
You'll have to loop on that array to extract the characteristic_value attribute of each characteristic object.

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

  • Posts: 43
  • Thank you received: 3
9 years 4 months ago #209345

Sorry, Nicolas, there´s nothing like that ($row->characteristics) in the cart.php.

I added that code to the table head to display the title of the column:
<th id="hikashop_cart_product_size_title" class="hikashop_cart_product_size_title hikashop_cart_title">
<?php echo JText::_('CART_PRODUCT_UNIT_SIZE'); ?>
</th>

That´s simple.

I also added that code to the table body:
<td data-title="<?php echo JText::_('CART_PRODUCT_CHARACTERISTICS'); ?>" class="hikashop_cart_product_characteristics">
<?php
$user = hikashop_loadUser(true);
echo $user->custom_field;
?>
</td>

I also understand that I need to loop this using 'foreach' but I´m really no php expert and I don´t think that I´m willing to become one B)
Could you point me to some code that I can copy in here or modify?

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 4 months ago #209355

Try that:
<?php foreach($row->characteristics as $c){ echo $c->characteristic_name; } ?>

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

  • Posts: 43
  • Thank you received: 3
9 years 4 months ago #209516

Mmhhh, doesn´t work.
I assume I need to change the parameter 'characteristic_name' by some individual name of the characteristic?
I also tried that with the alias of the characteristic name, but that doesn´t work either. Anyway that wouldn´t solve it as I´m using different characteristics - but as I mentioned only one per product.

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 4 months ago #209538

Hi,

Mmhhh, doesn´t work.

Can you please provide more details ?
Do you have some PHP warning (assuming that you are displaying the PHP warning ; otherwise you have to check your PHP log) ?
Which view are you editing ? (Because nicolas was talking about the checkout/cart but I'm not sure you're working on the same)

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: 43
  • Thank you received: 3
9 years 4 months ago #209621

Hi Jerome,

I am also talking about the cart view (see screenshot in the first post).
I going to attach the modified cart.php. The only things I´ve changed so far are modifications on the fieldset and adding the new column "unit size". For the header this is simple, but I do have my problems to display the values in each row.
I have no php warning - usually i´m not working with php that deep. The site itselfs works, but simply the values of the new column on the cart are not displayed.

Attachments:

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 4 months ago #209632

Hi,

Your screenshot in the first post show a cart ; but like I wrote, there are several views which display the cart, like Product/Cart , Checkout/Cart and Cart/Showcart
So if you do not provide the context, the simple image does not help much.
Because it could be the cart in the checkout or a cart module...

So, please understand that there is no one "cart view".
Also, please do not edit the core files directly and use view overrides ; I see that you talk about the "cart.php" file, which could mean that you're editing directly the core files instead of using overrides.

Now Nicolas made a little mistake, he used "characteristic_name" when it is "characteristic_value".

<?php
if(!empty($row->characteristics)) {
	foreach($row->characteristics as $c) {
		echo $c->characteristic_value;
	}
}
?>

But ; if you take a look at the PHP log ; if you had activate the "error reporting" in your Joomla configuration in order to see directly the PHP warning message in your page ; you would see a message telling you that "characteristic_value" property does not exist for the object.
And such kind of information is useful when you are developing or performing customization. It allows you to know when you have a little mistake, instead of thinking that you have blank content or "it does not work", you have the reason why.

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.
The following user(s) said Thank You: disc

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

  • Posts: 43
  • Thank you received: 3
9 years 4 months ago #209789

Solved!
It was just the wrong parameter. "characteristic_value" of course was right.
I suppose displaying the characteristics on the cart will be requested by many users. So maybe you think about to add this to the cart by default?!

Yes you are right: I´m editing the core files which is much easier than using the override view. But that doesn´t matter as long as I have backups of these files, so in case of an update the changes are not lost.

Thanks again.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 4 months ago #209797

Hi,

We won't add that by default since, as you said in the beginning, the characteristic value is already added at the end of the product name by default. Adding columns for that would make it display twice on the module.

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

  • Posts: 43
  • Thank you received: 3
9 years 3 months ago #210812

nicolas wrote: We won't add that by default since, as you said in the beginning, the characteristic value is already added at the end of the product name by default.


That´s up to you, but to be honest I´ve never seen a web shop that adds a characteristic to the product name. I mean this really looks confusing. I personally think that it´s much clearer to have that in a separate column.

Anyway I´ve got the same issue with the order confirmation mail.
Also in this mail I would like to add the column with characteristics. The design and the head of the table is again no problem, but the value of the characteristic in the table body does not work.

I identified that the related code is in the preload version of the mail. So I would need something similar as this code for the product name as well for the characteristics, right?

$cartProduct('PRODUCT_NAME') = $t;

$t = '';
$statusDownload = explode(',',$config->get('order_status_for_download','confirmed,shipped'));
if(!empty($item->files) && in_array($data->order->order_status,$statusDownload)){
$t .= '<p>';
foreach($item->files as $file){
$fileName = empty($file->file_name) ? $file->file_path : $file->file_name;
$file_pos = empty($file->file_pos) ? '' : ('&file_pos=' . $file->file_pos);
if(empty($customer->user_cms_id))
$file_pos .= '&email=' . $customer->user_email;
$t .= '<a href="'.hikashop_frontendLink('index.php?option=com_hikashop&ctrl=order&task=download&file_id='.$file->file_id.'&order_id='.$data->order_id.$file_pos.$url_itemid).'">'.$fileName.'</a><br/>';
}
$t .= '</p>';
}
$cartProduct('PRODUCT_CHARACTERISTICS) = $t;

$t = '';
if(!empty($row->characteristics)) {
$t .= '<p>';
foreach($row->characteristics as $c) {
echo $c->characteristic_value; }
}

Edit: I replaced the squared brackets, otherwise the code will not be displayed.

Last edit: 9 years 3 months ago by disc.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 3 months ago #210822

Hi,

Characteristics are not stored with the product data in the order and are not loaded with the order when the order is loaded.
What you have is the information in $row->order_product_options that you can unserialize in order to get the information of the characteristics values of the product in the order.

Note: if you want to add code with brackets in the forum you can use the [ code ] and [ / code ] tags around your code (without the spaces).

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

  • Posts: 43
  • Thank you received: 3
9 years 3 months ago #210855

Hi Nicolas,

I can comprehend rudimentarily what you say but I have clue how the related code needs to look like.
I did the same on the cart. Therefor you provided that code:
<?php
if(!empty($row->characteristics)) {
foreach($row->characteristics as $c) {
echo $c->characteristic_value; } }
?>

which worked fine. But i really don´t know how to modify that for the mail (no PHP expert! ;) )

When you say that characteristics are not stored in the order, does that mean when turning off the function "adding characteristics value to the products name" that the characteristic will not be stored anywhere?
So in the result you are not able to see what kind of product the customer has purchased?
I mean this would be a show stopper using Hikashop for that kind of products when you don´t like to add the characteristic to the product name!

Last edit: 9 years 3 months ago by disc.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 3 months ago #210889

Hi,

1. It should be something like that:

if(!empty($row->order_product_options)){
$characteristics = unserialize($row->order_product_options);
foreach($characteristics as $c){
 echo $c->characteristic_value;
}
}

2. It will always be stored in order_product_options
If you don't want to add the characteristic value to the product_name, you can always add some CSS to hide the characteristic value added to the product name and add your own display with order_product_options. That's why it's there.

Last edit: 9 years 3 months ago by nicolas.

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

  • Posts: 43
  • Thank you received: 3
9 years 3 months ago #211037

1. It should be something like that:

if(!empty($row->order_product_options)){
$characteristics = unserialize($row->order_product_options);
foreach($characteristics as $c){
 echo $c->characteristic_value;
}
}


Could be something like that, but doesn´t work ;-)

2. It will always be stored in order_product_options
If you don't want to add the characteristic value to the product_name, you can always add some CSS to hide the characteristic value added to the product name and add your own display with order_product_options. That's why it's there.


Does that mean that I have to turn on the option "add characteristic to product name" to make sure that the characteristic will be stored in the order and then use CSS (e. g. something like "position: absolute; left: -9999px; top: -9999px;" to make the characteristic "invisible" if I don´t want to display them at the end of the products' name?

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 3 months ago #211064

Hi,

1. I don't see why that wouldn't work except of course if you don't have the product object in the variable $row. Now I don't know the full code you're using so I can't say much more.
But why not simply do a var_dump of the variable where you have your product data in your code and look at the data yourself ? You'll see where the information you want is and that way you'll know how to get it.

2. No. It means that it doesn't matter to you since you're displaying it differently anyway. You can turn off the option, or turn it on and hide it with CSS, it doesn't matter since you'll display it differently yourself based on order_product_options.

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

Time to create page: 0.084 seconds
Powered by Kunena Forum