Subscription when placing an order for unauthorized users in Bitrix
Rus
Eng
Подписка при оформлении заказа неавторизованным пользователям в Битрикс
I solve complex technical challenges for Bitrix and 1C—ranging from auditing existing code to configuring complex integrations—with a guarantee of results.
Recommended

Website hosting

If you are choosing hosting for your project, I recommend Timeweb. Modern infrastructure, a wide range of plans from starter options to high-load VPS, and responsive tech support that actually helps instead of sending template replies. I host some of my own projects there and recommend it to my clients.

Go to site Affiliate link. The price remains the same for you.

All English-language materials have been translated fully automatically using the Google service

When you have a live online store and there are constant purchases by "peeking" customers on it, you don't want it to be his first and last purchase, so it would not be bad to invite him to subscribe to news and promotions, suddenly there is something else will interest you

To do this, go to Store -> Settings -> Order Properties -> Property List and create fields of type Y / N. Set the mnemonic code as you wish. But remember the ID of the properties, we need it to access the array of order properties $arFields ['ORDER_PROP' ]

Next, in the init.php file, we will place a handler that will subscribe the user to all categories, you can naturally subscribe to one or two as you wish by simply setting your id in the $ RUB_ID array.

  AddEventHandler ('sale', 'OnOrderAdd', Array ("OnSaleComponentOrderCreatedClass", "Subscrible"));

class OnSaleComponentOrderCreatedClass
{
    function Subscrible ($ ID, & $ arFields)
    {
        if ($ arFields ['ORDER_PROP'] [23] == 'Y') {// if the subscription box is checked
            $ USER = false;

            CModule :: IncludeModule ("subscribe"); // Include the subscription module

            $ RUB_ID = array ();
            $ rsRubric = CRubric :: GetList (array (), array ("ACTIVE" => "Y"));
            while ($ arRubric = $ rsRubric-> GetNext ()) {
                $ RUB_ID [] = $ arRubric ['ID'];
            }

            / * create an array for subscription * /
            $ subscr = new CSubscription;

            $ arFields = Array (
                "USER_ID" => $ USER, // Create an anonymous subscription without linking to a user, but you can specify any ID
                "FORMAT" => "html / text",
                "EMAIL" => $ arFields ['ORDER_PROP'] [2], // email of the user in my property number 2
                "ACTIVE" => "Y",
                "RUB_ID" => $ RUB_ID,
                "SEND_CONFIRM" => "N",
                "CONFIRMED" => "Y"
            );

            $ subscr-> Add ($ arFields, SITE_ID);
        }
    }
}  
Aleksandr Tichiy
Author

Aleksandr Tichiy

Fullstack developer · 1C-Bitrix

I build and modernize online stores and corporate portals on 1C-Bitrix. Integrations with 1C, high-load performance, 152-FZ compliance. Writing about architecture and e-commerce.


Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site