A
A
Anton2018-06-29 14:10:49
1C-Bitrix
Anton, 2018-06-29 14:10:49

How to add product properties to a letter to a customer when ordering?

There are properties on the product card, these properties fly with the product to the basket, then order ...
The network is full of examples of how to add order fields, delivery type or address to emails ...
But how to add product properties is not clear, for example: Men's shirt (size XXL), only the name flies to the letter, without the size.
The only example that I found on Habré did not work, or I did not use it correctly, because it is not clear: https://habr.com/sandbox/70044/
He writes

Since CSaleBasket::GetList does not return properties, I had to use CIBlockElement::GetById.

I started using
$rsElem = CIBlockElement::GetById($arItem["PRODUCT_ID"]); 
$arElem = $rsElem->GetNextElement();
$arProps = $arElem->GetProperties();

But I get an array of all product properties, and not an array of properties specifically selected by the user.
Here is my code at the moment:
// Письмо пользователю при оформлении нового заказа
AddEventHandler("sale", "OnOrderAdd", Array("mail_new", "OnOrderAdd_mail")); 
 class mail_new
{ 
 function OnOrderAdd_mail($ID, $val)
{
  // Получаем имя и мэйл пользователя
 $rsUser = CUser::GetByID($val["USER_ID"]);
 $arUser = $rsUser->Fetch();
 $arUser_name = $arUser["LAST_NAME"]." ".$arUser["NAME"];
 $arUser = $arUser["EMAIL"];
  // Получаем Содержимое заказа
$dbBasketItems = CSaleBasket::GetList(
        array(
                "NAME" => "ASC",
                "ID" => "ASC"
                ),
        array(
                "FUSER_ID" => CSaleBasket::GetBasketUserID(),
                "LID" => SITE_ID,
                "DELAY" => "N",
                "CAN_BUY" => "Y",
                "ORDER_ID" => "NULL"
                ),
        false,
        false,
        array()
        );
$tim = date("d.m.Y");                                
$zak = "Корзина заказа:<br /><table border='1'>";
 $zak = $zak."<tr><td align='center'>Товар</td><td align='center'>Цена</td><td align='center'>Кол-во</td><td align='center'>Сумма</td></tr>";
                 while ($arItem = $dbBasketItems->Fetch())
                {$number = $arItem["PRICE"];
$num = number_format($number,0,'.','');
                                  $st = (int)$arItem["QUANTITY"]*$arItem["PRICE"];
                                  $kol_vo = (int)$arItem["QUANTITY"];
                                  $zak = $zak."<tr><td align='left'>"."<a href='".$arItem["DETAIL_PAGE_URL"]."'>".$arItem["NAME"]."</a></td><td align='left'>".$num."</td><td align='left'>".$kol_vo."</td><td align='left'>".$st."</td></tr>";
                }
                                $arDeliv = CSaleDelivery::GetByID($val["DELIVERY_ID"]);
                                $zak = $zak."<tr><td align='left' colspan='3'><b>Доставка: </b>".$arDeliv["NAME"]."</td><td align='left'>".$val["PRICE_DELIVERY"]."</td></tr>";
                                $zak = $zak."</table>";
 $arEventFields = array(
"ORDER_DATE"  => $tim,
    "ORDER_ID"         => $ID,
    "SOSTAV"              => $zak,
    "ORDER_USER"    => $arUser_name,
    "EMAIL"                 => $arUser,
    "BCC"                     => $arUser,
    "PRICE"                  => (int)$val["PRICE"]." руб",
    "SALE_EMAIL"     => "[email protected]",
    );
 CEvent::SendImmediate("SALE_NEW_ORDER", s1, $arEventFields, "N", 25);
}
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Burlaka, 2018-06-29
@anton99zel

Read through the new kernel, D7.
Offhand:

$order_obj=\Bitrix\Sale\Order::load( $order_id );
$basket= $order_obj->getBasket();
$basket_items=$basket->getBasketItems();

/* @var \Bitrix\Sale\BasketItem $bi */
foreach ( $basket_items as $bi ) {
  $item_props= $bi->getPropertyCollection()->getPropertyValues();
}

A
Alex-1917, 2018-06-29
@alex-1917

Well, it's started!! )))
Have you completed the developer courses to the end or, as usual, did everything end at the introductory part?
What kind of property, I didn’t understand from the sheet, or rather reluctance to read ... The code would be written shorter, why ALL the sheet???!!

O
Oleg Mifle, 2018-06-29
@OlegMifle

There is a component sale.order.detail.mail Inserted
into the mail template somehow like this

<? EventMessageThemeCompiler::includeComponent("bitrix:sale.personal.order.detail.mail", "template_name", array(
// параметры компонента
 )) ?>

You copy the component template and get the desired properties without using a handler.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question