Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Adding product attributes to minicart

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 03-25-2016, 11:56 AM
 
benlind benlind is offline
 

Member
  
Join Date: Feb 2016
Posts: 24
 

Default Adding product attributes to minicart

How can I list custom product attributes in my minicart? I currently have this code that lists the minicart products:

Code:
<ul IF="hasItems()"> <li FOREACH="getItemsList(),item"> <span class="item-thumbnail"> <a href="{item.getURL()}" IF="item.hasImage()"> <widget class="\XLite\View\Image" image="{item.getImage()}" alt="{item.getName()}" maxWidth="40" maxHeight="40" centerImage="0" /> </a> </span> <span class="item-attributes"> </span> <list name="minicart.horizontal.item" item="{item}" /> </li> </ul>

I cannot figure out how to list the item's attributes. I have tried the following lines unsuccessfully:

Code:
<ul> <li FOREACH="item.getAttributeValuesIds(),ak,av"> Key: '{ak}' value: '{av}' </li> </ul> {foreach:item.getAttributeValuesIds(),key,value} These are values from item.getAttributeValuesIds() function. key: {key} and value: {value} {end:} {foreach:item.getAttributeValuesIds(),value} These are values from item.getAttributeValuesIds() function. value: {value} {end:} {item.getAttributeValuesIds()} {item.getAttributeValuesPlain()} {item.getAttributeValuesAsString()}

Both {item.getAttributeValuesIds()} and {item.getAttributeValuesPlain()} print "Array" to the page. I know that the products in my cart have attributes. How can I list them?

Thanks.
__________________
X-Cart version 5.2
Reply With Quote
  #2  
Old 03-28-2016, 06:12 AM
  seyfin's Avatar 
seyfin seyfin is offline
 

X-Cart team
  
Join Date: May 2004
Posts: 1,223
 

Default Re: Adding product attributes to minicart

Actually, X-Cart already displays so-called "multi-value" product attributes in the minicart (those attributes that need to be chosen by the customer when adding the product to cart) - please see screen shot attached.

However, if you need something else, please clarify in details what are you trying to implemented, and provide your X-Cart store URL.

Thank you.
Attached Thumbnails
Click image for larger version

Name:	2016-03-28 17-09-32 Screenshot.png
Views:	274
Size:	167.2 KB
ID:	4514  
__________________
Sincerely yours,
Sergey Fomin
X-Cart team
Chief support group engineer

===

Check this out. Totally revamped X-Cart hosting
http://www.x-cart.com/hosting.html

Follow us:
https://twitter.com/x_cart / https://www.facebook.com/xcart / https://www.instagram.com/xcart
Reply With Quote
  #3  
Old 04-06-2016, 06:50 PM
 
benlind benlind is offline
 

Member
  
Join Date: Feb 2016
Posts: 24
 

Default Re: Adding product attributes to minicart

Seyfin,

I don't mean those types of multi-value attributes. I mean the attributes you can edit on the product edit page under "Attributes." For example, if I add a brand or a product number to my product, I'd like to be able to get those attributes (by key) in the minicart. I've attached a screenshot of what type of attributes I'm talking about.

Thanks for the help!
Attached Thumbnails
Click image for larger version

Name:	X-Cart online store builder - Collector_s Edition Slinky-4.jpg
Views:	265
Size:	273.8 KB
ID:	4521  
__________________
X-Cart version 5.2
Reply With Quote
  #4  
Old 04-06-2016, 09:09 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Adding product attributes to minicart

You should iterate over the array returned by getAttributeValues() method and use the getActualValue() and getActualName() methods to get attribute names and values.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #5  
Old 07-27-2016, 05:06 PM
 
benlind benlind is offline
 

Member
  
Join Date: Feb 2016
Posts: 24
 

Default Re: Adding product attributes to minicart

That method, iterating over getAttributeValues(), is not what I need. That lists the product-specific attributes. What I want are the global attributes that are applied to the product.

I have a global field named "Part Number" that I want to have on each product, and I need to be able to programmatically retrieve it.
__________________
X-Cart version 5.2
Reply With Quote
  #6  
Old 07-27-2016, 08:59 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Adding product attributes to minicart

getAttributeValues() should return all attributes, including global attributes as well.

Each attribute should have getAttribute() method that returns \XLite\Model\Attribute model that you can check if it is a global attribute, or a per-class attribute (getProductClass() method), or a product-specific one (getProduct() method).
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
divya (01-03-2018)
  #7  
Old 03-09-2017, 06:42 PM
 
benlind benlind is offline
 

Member
  
Join Date: Feb 2016
Posts: 24
 

Default Re: Adding product attributes to minicart

I have still not been able to figure out how to list product attributes in the minicart.

I have expanded my experimentation to include this code:

PHP Code:
getAttributeValues:
<
span FOREACH="item.getAttributeValues(),a">
  
Key'{a.getName()}'
  
value'{a.getAttributeValue()}'
  
Key'{a.getActualValue()}' value'{a.getActualName()}'
</span>

getAttributesList:
<
li FOREACH="item.getAttributesList(),a">
  
Key'{a.getName()}'
  
value'{a.getAttributeValue()}'
  
Key'{a.getActualValue()}' value'{a.getActualName()}'
</li>

Values:
<
ul>
  <
li FOREACH="item.getAttributeValues(),val">
    
Key'{val.getActualValue()}' value'{val.getActualName()}'
  
</li>
</
ul>
ValuesIds:
<
ul>
  <
li FOREACH="item.getAttributeValuesIds(),ak,av">
    
Key'{ak}' value'{av}'
  
</li>
</
ul>
{foreach:
item.getAttributeValuesIds(),key,value}
  
These are values from item.getAttributeValuesIds() function. key: {key} and value: {value}
{
end:}
{foreach:
item.getAttributeValuesIds(),value}
  
These are values from item.getAttributeValuesIds() function. value: {value}
{
end:}
{
item.getAttributeValuesIds()}
{
item.getAttributeValuesPlain()}
{
item.getAttributeValuesAsString()}
<
widget class="\XLite\View\Product\AttributeValues" orderItem="{item}" /> 

However, NO attributes are being printed (global, class, or product-specific). I can call things like {item.getName()} and {item.getURL()}, and they return correct values.

Help?
__________________
X-Cart version 5.2
Reply With Quote
  #8  
Old 03-14-2017, 10:04 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Adding product attributes to minicart

I'm not sure why it doesn't print attributes.

As far as I see your template iterates over items returned by \XLite\View\Minicart::getItemsList().
This method returns an array of \XLite\Model\OrderItem object, so you should be able to call any of its methods on "item" in your template.
I see the getAttributeValues() and getAttributeValuesIds() methods in that class, but not getAttributesList().

Perhaps you should debug what these methods return to find out why it is empty for you.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:38 PM.

   

 
X-Cart forums © 2001-2020