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

Pull product-variant attributes

 
Reply
   X-Cart forums > X-Cart 5 > Third Party Add-Ons for X-Cart 5
 
Thread Tools Search this Thread
  #1  
Old 07-11-2018, 05:56 AM
 
Soptareanu @Alex Soptareanu @Alex is offline
 

Advanced Member
  
Join Date: Apr 2018
Posts: 39
 

Default Pull product-variant attributes

Is there a way to pull all attributes and options of each product-variant in Complex Schema. In order to do this task I use
PHP Code:
public function convertModel(\XLite\Model\AEntity $model$withAssociations)
    {
        return array(
            
'id'                 => $model->getId(),
            
'sku'                => $model->getSku(), 
            
'productid'       => $model->getProduct()->getProductId(),
            
'url'              => $model->getProduct()->getFrontURL(),
            
'variantid'          => $model->getVariantId(),
            
'disponibilitate' => $model->getDisponibility(),
            
'amout'              => $model->getAvailableAmount(),
            
'price'              => $model->price,
            
'string'          => $model->getSomeString(),
            
'image'              => $model->getProduct()->getImage()->url
            
'variant_img'      => $model->getImage(), // ??
            
'options'          => $model->getAttributeValueS()
        );
    } 
And the output is
PHP Code:
Array
(
    [
0] => stdClass Object
        
(
            [
id] => 1001
            
[sku] => SKU664314
            
[productid] => 12710
            
[url] => https://www.my-xcart.com/cart.php?target=product&product_id=12710
            
[variantid] => SKU66431-8c(1l
            
[disponibilitate] => 5
            
[amout] => 1
            
[price] => 0
            
[string] => Some String
            
[image] => 
            [
variant_img] => 
            [
options] => stdClass Object
                
(
                )

        ) 
As you can see, the getAttributeValueS() returns an empty object.
__________________
Soptareanu Alex
Reply With Quote
  #2  
Old 07-11-2018, 07:30 AM
 
mcupka mcupka is offline
 

eXpert
  
Join Date: Jan 2013
Posts: 204
 

Default Re: Pull product-variant attributes

Why are you using a capital S for 'ValueS'? It should be lower case or else you're not calling that entirely.

For example, see https://devs.x-cart.com/basics/basics-of-working-with-product-attributes.html
Reply With Quote
  #3  
Old 07-11-2018, 07:48 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default Re: Pull product-variant attributes

getAttributeValueS is for attributeValueS property so the S is correct - that's how the property is defined in the model class - it is for Attribute Value Select
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #4  
Old 07-11-2018, 11:44 PM
 
Soptareanu @Alex Soptareanu @Alex is offline
 

Advanced Member
  
Join Date: Apr 2018
Posts: 39
 

Default Re: Pull product-variant attributes

Quote:
Originally Posted by cflsystems
getAttributeValueS is for attributeValueS property so the S is correct - that's how the property is defined in the model class - it is for Attribute Value Select

I also try to put $model->getProduct()->getAttributes() but i got as result this
PHP Code:
[options] => stdClass Object
                
(
                ) 
__________________
Soptareanu Alex
Reply With Quote
  #5  
Old 07-12-2018, 03:52 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Pull product-variant attributes

Hi @Soptareanu @Alex,

$model->getAttributeValueS() does not return an empty object. It returns collection of objects, so you should cycle through its child elements and call something like this:

Code:
foreach ($model->getAttributeValueS() as $attributeValue) { $result = $result . ' ' . $attributeValue->asString(); }

See more in \XLite\Model\AttributeValue\AttributeValueSelect class.

Tony


Quote:
Originally Posted by Soptareanu @Alex
Is there a way to pull all attributes and options of each product-variant in Complex Schema. In order to do this task I use
PHP Code:
public function convertModel(\XLite\Model\AEntity $model$withAssociations)
    {
        return array(
            
'id'                 => $model->getId(),
            
'sku'                => $model->getSku(), 
            
'productid'       => $model->getProduct()->getProductId(),
            
'url'              => $model->getProduct()->getFrontURL(),
            
'variantid'          => $model->getVariantId(),
            
'disponibilitate' => $model->getDisponibility(),
            
'amout'              => $model->getAvailableAmount(),
            
'price'              => $model->price,
            
'string'          => $model->getSomeString(),
            
'image'              => $model->getProduct()->getImage()->url
            
'variant_img'      => $model->getImage(), // ??
            
'options'          => $model->getAttributeValueS()
        );
    } 
And the output is
PHP Code:
Array
(
    [
0] => stdClass Object
        
(
            [
id] => 1001
            
[sku] => SKU664314
            
[productid] => 12710
            
[url] => https://www.my-xcart.com/cart.php?target=product&product_id=12710
            
[variantid] => SKU66431-8c(1l
            
[disponibilitate] => 5
            
[amout] => 1
            
[price] => 0
            
[string] => Some String
            
[image] => 
            [
variant_img] => 
            [
options] => stdClass Object
                
(
                )

        ) 
As you can see, the getAttributeValueS() returns an empty object.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote

The following user thanks tony_sologubov for this useful post:
Soptareanu @Alex (07-12-2018)
  #6  
Old 07-12-2018, 04:45 AM
 
Soptareanu @Alex Soptareanu @Alex is offline
 

Advanced Member
  
Join Date: Apr 2018
Posts: 39
 

Default Re: Pull product-variant attributes

Quote:
Originally Posted by tony_sologubov
Hi @Soptareanu @Alex,

$model->getAttributeValueS() does not return an empty object. It returns collection of objects, so you should cycle through its child elements and call something like this:

Code:
foreach ($model->getAttributeValueS() as $attributeValue) { $result = $result . ' ' . $attributeValue->asString(); }

See more in \XLite\Model\AttributeValue\AttributeValueSelect class.

Tony
It works. Thanks a lot.
__________________
Soptareanu Alex
Reply With Quote

The following user thanks Soptareanu @Alex for this useful post:
mcupka (07-12-2018)
  #7  
Old 07-12-2018, 05:08 AM
 
mcupka mcupka is offline
 

eXpert
  
Join Date: Jan 2013
Posts: 204
 

Default Re: Pull product-variant attributes

Glad you got this fixed!
Reply With Quote
  #8  
Old 03-05-2020, 12:50 AM
 
hola@x-cart.es hola@x-cart.es is offline
 

Newbie
  
Join Date: Oct 2013
Posts: 4
 

Default Re: Pull product-variant attributes

Hello, how can I get the attribute name with attribute value using $model->getAttributeValueS()?
__________________
X-cart Spain
www.x-cart.es
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Third Party Add-Ons for X-Cart 5


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:25 AM.

   

 
X-Cart forums © 2001-2020