Product Export from Website to 1C (CommerceML)

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementing Product Export from Website to 1C (CommerceML)

If import from 1C is catalog synchronization to website, export is the reverse task: sending orders, stock, or customer data back to 1C. Often required in online stores where 1C is accounting system and website is sales point.

What is transmitted to 1C

Most common scenarios:

Data CommerceML file Frequency
New orders sale.xml By event / every N minutes
Order status changes sale.xml By event
Website stock offers.xml By schedule
Customers import.xml By schedule

Exchange Protocol (Website Side)

1C requests data via CommerceML2 protocol:

GET /1c-exchange/?type=sale&mode=checkauth
GET /1c-exchange/?type=sale&mode=init
GET /1c-exchange/?type=sale&mode=query        — get orders list
POST /1c-exchange/?type=sale&mode=success     — confirm receipt
GET /1c-exchange/?type=sale&mode=file&filename=sale.xml — download file

Generating sale.xml

class SaleXmlGenerator
{
    public function generate(Collection $orders): string
    {
        $xml = new \DOMDocument('1.0', 'UTF-8');
        $root = $xml->createElement('КоммерческаяИнформация');
        $root->setAttribute('ВерсияСхемы', '2.10');
        $xml->appendChild($root);

        foreach ($orders as $order) {
            $orderNode = $xml->createElement('Документ');

            $this->addElement($xml, $orderNode, 'Ід', $order->uuid);
            $this->addElement($xml, $orderNode, 'Номер', $order->number);
            $this->addElement($xml, $orderNode, 'Дата', $order->created_at->format('Y-m-d'));
            $this->addElement($xml, $orderNode, 'Сумма', number_format($order->total, 2, '.', ''));

            // Контрагент
            $client = $xml->createElement('Контрагенты');
            $agent = $xml->createElement('Контрагент');
            $this->addElement($xml, $agent, 'Наименование', $order->customer_name);
            $client->appendChild($agent);
            $orderNode->appendChild($client);

            // Товари
            $products = $xml->createElement('Товары');
            foreach ($order->items as $item) {
                $product = $xml->createElement('Товар');
                $this->addElement($xml, $product, 'Ід', $item->product->onec_guid);
                $this->addElement($xml, $product, 'Наименование', $item->product->name);
                $this->addElement($xml, $product, 'Количество', $item->quantity);
                $products->appendChild($product);
            }
            $orderNode->appendChild($products);

            $root->appendChild($orderNode);
        }

        return $xml->saveXML();
    }
}

Confirming order receipt

1C after successful receipt sends list of processed order GUIDs. Site marks them as transmitted to 1C:

public function markAsSent(Request $request): Response
{
    $guids = explode("\n", $request->getContent());

    Order::whereIn('uuid', array_filter($guids))
         ->update(['sent_to_1c' => true, 'sent_to_1c_at' => now()]);

    return response('success');
}

Updating statuses from 1C

1C can return order processing statuses (paid, shipped, cancelled). Site receives updated orders via POST /1c-exchange/?type=sale&mode=file:

public function processSaleResponse(string $xmlPath): void
{
    $xml = simplexml_load_file($xmlPath);

    foreach ($xml->Документ as $doc) {
        $guid = (string) $doc->Ід;
        $status = (string) $doc->Статус;

        Order::where('uuid', $guid)->update([
            'status' => $this->mapOnecStatus($status),
            'onec_status' => $status,
        ]);
    }
}

private function mapOnecStatus(string $onecStatus): string
{
    return match($onecStatus) {
        'Оплачен' => 'paid',
        'Отгружен' => 'shipped',
        'Отменён' => 'cancelled',
        default => 'unknown',
    };
}

Common Difficulties

  • Empty product GUIDs — if product created on site, not imported from 1C, its GUID unknown in 1C. Need logic to create new product in 1C or match by SKU
  • Encoding — some 1C versions require Windows-1251 files
  • Testing — need access to client's test 1C database during development

Timeline

Export orders to 1C with receipt confirmation and status updates: 8–14 work days.