C
C
cornsi2020-05-18 13:38:49
1C-Bitrix
cornsi, 2020-05-18 13:38:49

How to display in the cart a property added along with a product (Bitrix)?

Hello. I set up in Bitrix the ability to add a product to the cart, indicating an additional property: the user enters any text and sends the product with it to the cart.

I have placed a text field on the product page. I set it up so that the values ​​​​from it fall into the admin panel, but I can’t find a solution how to display this text in the basket.

The code that is responsible for adding the product to the cart:

Add2BasketByProductID($PRODUCT_ID, 1, array(
    array("NAME" => "Текст для нанесения", "CODE" => "CUSTOMTEXT", "VALUE" => $_POST['custom-text'])
) );


The cart is handled in init.php. Added code (see below, 'customtext') but it returns empty value.

foreach ($basket as $basketItem) {
$productid = $basketItem->getProductId();
$goodID = getElementByID($productid);

$items[$productid] = [
            'id' => $basketItem->getProductId(),
            'basket_id' => $basketItem->getId(),
            ...
            'customtext' => isset($goodID['PROPS']['CUSTOMTEXT']) ? $goodID['PROPS']['CUSTOMTEXT']['VALUE'] : '',
            ...
]


Tell me, please, where is the error? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-05-18
@rpsv

Are you setting the element's property to the value that the user enters? It’s really not worth doing this (case: 2 people went to the site, both entered different text, what will be displayed for whom?).
Cart items have a NOTES field, fill it out when adding goods to the cart, then you won’t have to mess with the template (as far as I remember, the standard one displays). If not, then just add the output of this field to the template.
Documentation: https://dev.1c-bitrix.ru/api_d7/bitrix/sale/techni...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question