Lots of our merchants' customers use Telegram every day and barely open marketing email. So we built Chat'N'Sell. It turns an existing online store into a shop inside Telegram: a bot plus a Mini App storefront, built from the store's own catalogue. Checkout still happens on the store. The OpenCart connector turned out to be the most interesting one to build. Here is what we ran into and how we solved it. The constraint: the store stays the source of truth We didn't want merchants keeping a second catalogue in a bot builder. So the store stays the source of truth: products, variants, prices and stock are read from OpenCart; shoppers browse in the Mini App, but pay in the store's own checkout with its payment methods, shipping and taxes; orders placed from Telegram are reported back, so the bot can send order updates. All the logic lives in our service: the bot, the storefront, broadcasts, discounts. Merchants configure everything in the Chat'N'Sell dashboard, and there is almost nothing to set up inside OpenCart. The extension is deliberately thin, a connector with three jobs: expose the catalogue, accept a cart from Telegram, and report changes. Thin, though, doesn't mean simple. One codebase for OpenCart 3.0, 4.0 and 4.1 OpenCart 3 and 4 have different model APIs. Which models are loaded also depends on the context. Instead of calling models, the shared core reads the catalogue tables directly, the same way OpenCart's own cart library does. The same PHP (7.1+, no framework calls) runs inside both packages. Only a thin adapter per major version differs. Variants: two different models OpenCart 3 has no variant products, only options. We turn the required list options (select, radio, image) into variant axes and list every combination, capped at three axes. Each combination's stock is the stock of its scarcest option value. OpenCart 4 adds real variant products: child products with master_id that pin some of the master's options. Those pinned options become the variant options, and the children become the variants. Combination ids have to be stable. Otherwise a reinstall would break every cart and link in Telegram. So we derive the id from the option values themselves and push it far above any product id, which keeps it safe as a JSON number. No extra table needed. Some products also need input the bot can't collect, such as free text without a default, checkboxes, or a fourth list option. Those are marked as blocked, and the Mini App sends the shopper to the product page instead of pretending it can sell them. Prices the shopper will actually pay The price in the bot has to match the checkout to the cent. Unit prices follow OpenCart's cart rules: specials and quantity-1 discounts for the default customer group, before tax. Bot-only discounts were harder. Merchants set them in the Chat'N'Sell dashboard, and the store has to honour them at checkout. OpenCart can't set a price per cart line (4.0.2 had a hidden parameter for it, and 4.1 removed it). So a bot price becomes an order total line ("Telegram price"), recalculated from the live cart on every page, the same way a coupon works: it applies only to lines that a signed checkout link put in the cart during this session; only up to the quantity in that link (extra units are charged at the shop price); never more than the line itself, and taxes are reduced by the matching share. Checkout handoff with a signed link When a shopper taps Checkout in the Mini App, they open the store with a signed payload. The payload is base64url JSON plus an HMAC-SHA256 signature over it, and the link stays valid for 30 minutes. The extension verifies it and fills the native cart. If something is unavailable, it tells the shopper what was refused or clamped. The order is then mapped back to the bot checkout it came from. Change events without a queue OpenCart has no reliable background queue, and we didn't want the merchant's Save button or the shopper's checkout waiting on our API. So: every change (product, category, order status) is written to a local chatnsell_event table first; the push runs in register_shutdown_function, after fastcgi_finish_request() has already sent the page to the browser; failed pushes stay in the table and are retried with backoff. The server can also poll the table, so nothing gets lost. Signing every request Both directions are signed with HMAC-SHA256 over timestamp + "." + payload, and the receiver allows 5 minutes of clock skew. One subtle part was the query string. Proxies and web servers sometimes re-encode it, so the verifier checks every plausible "path + query as sent" form and compares all of them with hash_equals without an early exit. That way, timing doesn't reveal which form matched. What we'd tell anyone building for OpenCart Read the tables if you need to support 3.x and 4.x from one codebase. Treat variants as two different features, not one. Plan for the cart's limitations early. Order totals are the escape hatch. Never make the merchant's request wait for your API. If you run an OpenCart store and want to try selling in Telegram: the connector is free, the bot and storefront are set up in the Chat'N'Sell dashboard, and there is a free plan. The setup guide is here: Telegram shop for OpenCart. Questions about the internals are welcome in the comments.
Selling from an OpenCart store inside Telegram: what we learned building the connector
Full Article
Original Source
Read the full article at Dev →KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.