X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Third Party Add-Ons for X-Cart 5 (https://forum.x-cart.com/forumdisplay.php?f=64)
-   -   Pull product-variant attributes (https://forum.x-cart.com/showthread.php?t=76400)

Soptareanu @Alex 07-11-2018 05:56 AM

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.

mcupka 07-11-2018 07:30 AM

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

cflsystems 07-11-2018 07:48 AM

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

Soptareanu @Alex 07-11-2018 11:44 PM

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
                
(
                ) 


tony_sologubov 07-12-2018 03:52 AM

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.


Soptareanu @Alex 07-12-2018 04:45 AM

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.

mcupka 07-12-2018 05:08 AM

Re: Pull product-variant attributes
 
Glad you got this fixed!

hola@x-cart.es 03-05-2020 12:50 AM

Re: Pull product-variant attributes
 
Hello, how can I get the attribute name with attribute value using $model->getAttributeValueS()?


All times are GMT -8. The time now is 08:19 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.