B2Bsellers Suite
API Referenceswww.b2b-sellers.comPublic demoshopRoadmap
Beta < 0.9.X
Beta < 0.9.X
  • Home
  • Products & Configuration
    • Plans & Plugin Concept
    • Demoshops
    • B2Bseller Suite - CORE Plugin
      • CORE-Plugin Configuration
      • B2B Flow/Business Events
      • B2B Rules
      • B2B Body Classes
      • B2bContextTrait
      • B2bPlatformContext
      • Registration process
      • UseCustomer URL Parameter
      • How to add „Menü Item“ on B2BPlattform
      • EmployeePermissionTrait
      • Express checkout setup
    • B2Bseller Suite - purchasable Addons
      • Offer Function for Sales Agents
      • Spare Parts Shop
      • Subscription Article
      • Copper and brass product surcharges
      • Rating groups
      • B2B Platform Theme
      • E-Procurement (OCI,EDI,Ariba, Punchout)
      • Register Requests
      • Order lists
      • Bonus program
      • Product Request
      • URL Authentication
      • Cost centers
      • Training or e-learning - event articles with attendee registration
    • B2Bsellers Suite - Connectors
      • Import Customers and Employees from an external REST-API OR CSV
      • Import Orders from an external REST-API (ERP)
      • Import Customer Prices from an external REST-API
      • POST Register Request to an external REST-API
    • Third Party Extensions
      • Parent products in the listing
  • Guides
    • Setup
      • Installation
      • Requirements
      • Dockware Setup (Docker)
      • Use Test-Customers
      • Cronjobs
      • CLI-Commands
      • How to start the b2b-platform vue.js watcher
    • Developer Onboarding
      • Development Helpers
    • Own Extensions
      • Concept of Extensions
      • How to develop your own extensions
      • How to extend the b2b platform
      • Example Plugins
    • Migration
    • Tips for Deployment / Continuous Integration
    • Performance
    • Guides for ERP-Interface
      • Overview - Full integrated ERP-Systems
      • Integration of ERP orders to Shopware 6
      • Integration Customers and Employees from ERP
  • Ressources
    • Usable Components
      • Vue.js - B2B Platform
      • Storefront
    • E-Mail Templates
    • FAQs
    • Support
  • API-References
    • Database Schema
    • Store-API
      • Account Request
      • Customer Activity
      • Customer Activity Type
      • Customer Last Orders
      • Customer List
      • Customer Price
      • Customer Sales Ranking
      • Customer Search
      • Delivery Interval
      • Delete Product Subscription
      • Document
      • Employee
      • Employee Permission
      • Employee Role
      • Employee Order
      • Event Product
      • Login Target List
      • Offer Document
      • Offer
      • Offer Mail
      • Offer Order
      • Offer Status
      • Ordered Products
      • Payment Condition
      • Platform Cms
      • Product List
      • Product Table Listing
      • Product Subscription
      • Product Subscription List
      • Sales Statistic
      • Snippet
    • Entities
      • Custom Fields for existing Shopware Entities
      • Budget
      • BudgetEmployee
      • CollectionAccount
      • CustomerPrice
      • Employee
        • EmployeeCustomer
        • EmployeePermission
        • EmployeeRole
      • CustomerActivity
        • CustomerActivityType
      • Offer
        • OfferAddress
        • OfferCustomer
        • OfferItem
        • OfferStatus
      • ProductSubscription
      • ProductSubscriptionOrder
      • PasswordlessLogin
      • PaymentCondition
      • ProductExplodedView
      • B2bProductList
        • B2bProductListItem
        • B2bProductListType
      • RegisterRequest
        • RegisterRequestStatus
        • RegisterRequestActivity
      • SalesRepresentativeCustomer
    • Admin API
      • Order Import Endpoint
  • Release Notes
    • B2BsellersCore
      • Version v0.9.6
      • Version v0.9.5
      • Version v0.9.4
      • Version v0.9.3
      • Version v0.9.2
      • Version v0.9.1
    • B2BOffer (Archived)
      • Version v0.9.1
Powered by GitBook
On this page
  • What can this connector do?
  • Current plans for future extensions:
  • Example request and response of the OMNISELLER REST API:
  • Settings in the plug-in config
  • Source code preview

Was this helpful?

  1. Products & Configuration
  2. B2Bsellers Suite - Connectors

Import Customer Prices from an external REST-API

What can this connector do?

This connector fills the customer individual prices database table. The connector retrieves the customer-specific prices from an external REST API for each customer created in Shopware and writes them into the b2b_customer_prices database table.

This plugin has been developed in such a way that you can easily extend it to your individual API. We from B2Bsellers will also add more connectors in due course.

Currently, the SAGE 100 - OMNISELLER B2B-API client is already connected. Therefore, SAGE100 customers can already use our connector without additional development.

We recommend setting up a cron job that collects the customer-specific prices, e.g. once a day. Please note that the cron job can run for a while depending on the customer size and interface response time.

Available shell command: b2b:price-connector:import

Alternatively, you can specify a parameter: customerNumber to update only the prices of one customer.

Procedure and information:

  • You can create your own connectors with your own plugin and derive them accordingly.

  • The endpoints of the API must be maintained in the plugin config of the connector. See figure 1

  • A BEARER authentication is already integrated and can be used

  • Please maintain the connector name in the plugin config. If you use the Omniseller, enter "omniseller". If you have developed your own "connector", please enter the "technical connector name".

  • Please execute the command: b2b:price-connector:import

  • In our PriceImporter class, all customers will then be passed through and accordingly asked for individual prices at the external API. The connector itself returns a ready array for insertion into the "b2b_customer_prices" database.

  • Note: Before inserting new customised prices, the customised prices of each customer will be deleted. An update of the prices is from our experience not possible.

Current plans for future extensions:

Due to the amount of data, it may often be necessary to pick up and process only one specific customer instead of all at once. For this purpose, the following function can already be used

$this->priceImporter->importSingleCustomerPrices($io, $customerNumber).

However, we are planning to extend this in one of the future updates so that an activity log API can be used to query which customers were last processed and therefore only a few customers will be updated.

Example request and response of the OMNISELLER REST API:

Request URL: POST api.omniseller365.com/b2b-prices/specialPrices This request returns all customer-specific prices.

On the other hand, this request only returns the individual prices of a customer and then inserts them into Shopware.

Response from the API is an array of customised prices:

[
          {
                   "SKU": "22805867",
                   "Price": 3.69,
                   "SalesDiscount": 0.00,
                   "Amount": 1.00,
                   "Type": "P",
                   "Info": "",
                   "IsGrossPrice": false
          }
]

If you have the possibility that the interface to your ERP system can develop an individual response, you can send the sample response from Omniseller to the interface contact person.

Settings in the plug-in config

Source code preview

In the following source code block you can see how a new connector is created and which functions are possible here.

<?php

namespaceB2bPriceConnector\Components\Connectors;

useDoctrine\DBAL\Connection;
useGuzzleHttp\Client;
useGuzzleHttp\Exception\RequestException;
useShopware\Core\Checkout\Customer\CustomerEntity;
useShopware\Core\Framework\Uuid\Uuid;
useShopware\Core\System\SystemConfig\SystemConfigService;

classOmnisellerPriceConnectorimplementsPriceConnectorInterface
{
privateClient$client;
privatearray$config;
privateConnection$connection;
private ?string$currencyId;

publicfunction__construct(
SystemConfigService$configService,
Connection$connection
    )
    {
$this->client = newClient();
$this->connection = $connection;
$this->config = $configService->get('B2bPriceConnector.config');
$this->currencyId = $this->getCurrencyIdByIsoCode($this->config['omnisellerCurrency']);
    }

privateconstCONNECTOR_NAME = 'omniseller';

publicfunctionsupports(string$connectorName): bool
    {
return$connectorName === self::CONNECTOR_NAME;
    }

publicfunctiongetConnectorName(): string
    {
returnself::CONNECTOR_NAME;
    }

publicfunctiongetPriceByCustomer(CustomerEntity$customer): array
    {
$data = [];
$prices = $this->fetchCustomerPrices($customer->getCustomerNumber());

if (empty($prices)) {
return$data;
        }

foreach ($pricesas$price) {
$productId = $this->getProductIdByNumber($price['SKU']);

if (empty($productId)) {
continue;
            }

$data[] = [
'customerId' =>$customer->getId(),
'customerNumber' =>$customer->getCustomerNumber(),
'productId' =>$productId,
'productNumber' =>$price['SKU'],
'currencyId' =>$this->currencyId,
'currencyIsoCode' =>$this->config['omnisellerCurrency'],
'from' => (int)$price['Amount'],
'to' =>null,
'priceNet' =>$price['Price'],
            ];
        }

return$data;
    }

privatefunctionfetchCustomerPrices(string$customerNumber): array
    {
try {
$url = $this->config['omnisellerApiUrl'];
$url .= '?shopID=' . $this->config['omnisellerShopId'];
$url .= '&customerID=D' . $customerNumber;
$url .= '&currency=' . $this->config['omnisellerCurrency'];
$url .= '&hasCount=true';

$response = $this->client->get($url, [
'headers' => [
'Bearer' =>$this->config['omnisellerToken'],
'Dev-Key' =>$this->config['omnisellerDevKey']
                ]
            ]);

$content = $response->getBody()->getContents();

if (empty($content)) {
return [];
            }

$result = json_decode($content, true);

if (empty($result)) {
return [];
            }

if (count($result) === 1&&isset($result[0]) &&isset($result[0]['RESPONSE'])) {
return [];
            }
        } catch (RequestException$e) {
return [];
        }

return$result;
    }

privatefunctiongetProductIdByNumber(string$productNumber): ?string
    {
$id = $this->connection->fetchOne("SELECT id FROM product WHERE product_number = :productNumber LIMIT 1", [
'productNumber' =>$productNumber
        ]);

if(!empty($id)) {
returnUuid::fromBytesToHex($id);
        }

returnnull;
    }

privatefunctiongetCurrencyIdByIsoCode(string$isoCode): ?string
    {
$id = $this->connection->fetchOne("SELECT id FROM currency WHERE iso_code = :isoCode LIMIT 1", [
'isoCode' =>$isoCode
        ]);

if(!empty($id)) {
returnUuid::fromBytesToHex($id);
        }

returnnull;
    }
}

Last updated 2 years ago

Was this helpful?

Figure 1: Here you can make the settings. The data for the Omniseller can be obtained from the interface provider.