X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Retrieve product hidden attributes (https://forum.x-cart.com/showthread.php?t=76855)

amarquis 03-04-2019 01:22 AM

Retrieve product hidden attributes
 
In X-Cart 5, I can create hidden attributes for any product.

I have found this page https://devs.x-cart.com/basics/basics-of-working-with-product-attributes.html which explains how to retrieve product attributes. How can I retrieve hidden attributes for a given product? Everything I tried failed and I am unsure what to use. Thanks.

amarquis 03-05-2019 04:57 AM

Re: Retrieve product hidden attributes
 
I would have the same question for global attributes too in fact as they don't seem to be returned either by the method described in the documentation. Would be nice to get an answer...

amarquis 03-08-2019 01:55 AM

Re: Retrieve product hidden attributes
 
Thanks a lot for your contributions. Much appreciated!

tony_sologubov 04-24-2019 04:01 AM

Re: Retrieve product hidden attributes
 
Hi amarquis,

If you need to pull hidden attributes, you need to add the \XLite\Model\Attribute::TYPE_HIDDEN type to the following array mentioned in the https://devs.x-cart.com/basics/basics-of-working-with-product-attributes.html article

Code:

                        array(
                            \XLite\Model\Attribute::TYPE_CHECKBOX,
                            \XLite\Model\Attribute::TYPE_TEXT
                        )


so it would become:

Code:

                        array(
                            \XLite\Model\Attribute::TYPE_CHECKBOX,
                            \XLite\Model\Attribute::TYPE_TEXT,
                            \XLite\Model\Attribute::TYPE_HIDDEN
                        )


As for global attributes, you need to write a function that would return such attribute values. If you plan on extending \XLite\Model\Product class, this function can look like this:

Code:

    public function getGlobalAttributes()
    {
        $cnd = new \XLite\Core\CommonCell;
        $cnd->product = $this->getProductId();

        $attributeValues = \XLite\Core\Database::getRepo('XLite\Model\AttributeValue\AttributeValueSelect')->search($cnd);

        $return = [];

        foreach ($attributeValues as $attributeValue) {
            if (is_null($attributeValue->getAttribute()->getProduct())) {
                $return[] = $attributeValue->asString();
            }
        }

        return $return;
    }


Tony

FactorInteractivo 04-09-2020 05:52 AM

Re: Retrieve product hidden attributes
 
With the solution you propose I only see the value of the global attributes but I don't see their name.
For example if a global attribute is "Color" with the value "Red", I only see "Red".

How can i fix this?

tony_sologubov 04-10-2020 01:22 AM

Re: Retrieve product hidden attributes
 
Hi @FactorInteractivo,

What X-Cart version you are using?
Best,

Tony


All times are GMT -8. The time now is 12:36 PM.

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