Skip to content
advanced Phase 92 · Enterprise Features

B2B Features

B2B features - company accounts, shared catalogs, quick order, requisition lists

45m
0 problems
Topic Progress 0%

B2B Architecture

B2B Feature Set

  ┌─────────────────────────────────────────┐
  │           Adobe Commerce B2B            │
  ├─────────────────────────────────────────┤
  │  Company Accounts  │  Shared Catalogs   │
  │  Quick Order       │  Requisition Lists │
  │  Quote Negotiation │  Purchase Orders   │
  │  Credit Limits     │  Approval Rules    │
  └─────────────────────────────────────────┘

Company Repository

namespace Magento\Company\Api;

interface CompanyRepositoryInterface
{
    public function get(int $companyId): CompanyInterface;
    public function getList(SearchCriteriaInterface $searchCriteria): CompanySearchResultsInterface;
    public function save(CompanyInterface $company): CompanyInterface;
    public function delete(CompanyInterface $company): bool;
}

Company Structure

namespace Magento\Company\Api\Data;

interface CompanyInterface
{
    public function getId(): ?int;
    public function getName(): string;
    public function getWebsiteId(): int;
    public function getRootGroupId(): int;
    public function getDefaultBilling(): ?int;
    public function getDefaultShipping(): ?int;
    public function getRejectQuoteIf?: ?bool;
    public function getRequisitionListActive?: ?bool;
    public function isQuotesEnabled(): bool;
    public function getCreditLimit(): float;
    public function getCreditUsed(): float;
    public function getCreditAvailable(): float;
}

Company Account Management

Company Service

namespace Vendor\B2B\Service\Company;

class CompanyService
{
    private CompanyRepositoryInterface $companyRepo;
    private CompanyUsersInterface $companyUsers;

    public function createCompany(array $data): CompanyInterface
    {
        $company = $this->companyFactory->create();
        $company->setName($data['name']);
        $company->setWebsiteId($data['website_id']);
        $company->setStatus(CompanyInterface::STATUS_ACTIVE);
        $company->setCreditLimit($data['credit_limit'] ?? 0);

        return $this->companyRepo->save($company);
    }

    public function addMember(
        int $companyId,
        int $customerId,
        string $role
    ): void {
        $company = $this->companyRepo->get($companyId);
        $customer = $this->customerRepo->getById($customerId);

        $customer->setCompanyId($companyId);
        $customer->setJobTitle($data['job_title'] ?? '');
        $this->customerRepo->save($customer);

        // Assign role
        $this->assignRole($customerId, $role);
    }

    public function getMembers(int $companyId): array
    {
        return $this->companyUsers->getUsers($companyId);
    }
}

Company Roles

namespace Vendor\B2B\Role;

class CompanyRoleManager
{
    private RoleRepositoryInterface $roleRepo;

    public function createRole(int $companyId, array $data): RoleInterface
    {
        $role = $this->roleFactory->create();
        $role->setCompanyId($companyId);
        $role->setName($data['name']);
        $role->setPermissions($data['permissions']);

        return $this->roleRepo->save($role);
    }

    public function getPermissions(int $roleId): array
    {
        $role = $this->roleRepo->get($roleId);
        return $role->getPermissions();
    }
}

Quick Order

Quick Order Service

namespace Vendor\B2B\Service\QuickOrder;

class QuickOrderService
{
    private ProductRepositoryInterface $productRepo;
    private CartRepositoryInterface $cartRepo;

    public function processQuickOrder(
        int $customerId,
        array $items
    ): CartInterface {
        $cart = $this->createOrGetCart($customerId);

        foreach ($items as $item) {
            $product = $this->productRepo->get($item['sku']);

            $cartItem = $this->cartItemFactory->create();
            $cartItem->setProductId($product->getId());
            $cartItem->setQty($item['qty']);
            $cartItem->setQuoteId($cart->getId());

            $cart->addItem($cartItem);
        }

        $cart->collectTotals();
        $this->cartRepo->save($cart);

        return $cart;
    }
}

SKU-Based Quick Order

namespace Vendor\B2B\Service\QuickOrder;

class SkuQuickOrder
{
    public function processSkuList(
        int $customerId,
        array $skuQtyPairs
    ): CartInterface {
        $items = [];

        foreach ($skuQtyPairs as $sku => $qty) {
            try {
                $product = $this->productRepo->get($sku);
                $items[] = [
                    'sku' => $sku,
                    'qty' => $qty,
                    'product_id' => $product->getId(),
                ];
            } catch (NoSuchEntityException $e) {
                $this->errors[] = sprintf('SKU %s not found', $sku);
            }
        }

        return $this->quickOrderService->processQuickOrder($customerId, $items);
    }
}

Requisition Lists

Requisition List Service

namespace Vendor\B2B\Service\RequisitionList;

class RequisitionListService
{
    private RequisitionListRepositoryInterface $listRepo;

    public function createList(
        int $customerId,
        string $name
    ): RequisitionListInterface {
        $list = $this->listFactory->create();
        $list->setCustomerId($customerId);
        $list->setName($name);

        return $this->listRepo->save($list);
    }

    public function addItem(
        int $listId,
        int $productId,
        float $qty
    ): void {
        $list = $this->listRepo->get($listId);

        $item = $this->itemFactory->create();
        $item->setListId($listId);
        $item->setProductId($productId);
        $item->setQty($qty);

        $list->addItem($item);
        $this->listRepo->save($list);
    }

    public function addToListFromCart(
        int $listId,
        CartInterface $cart
    ): void {
        foreach ($cart->getItems() as $cartItem) {
            $this->addItem(
                $listId,
                $cartItem->getProductId(),
                $cartItem->getQty()
            );
        }
    }

    public function moveToCart(
        int $listId,
        int $customerId
    ): CartInterface {
        $list = $this->listRepo->get($listId);
        $cart = $this->createOrGetCart($customerId);

        foreach ($list->getItems() as $item) {
            $cartItem = $this->cartItemFactory->create();
            $cartItem->setProductId($item->getProductId());
            $cartItem->setQty($item->getQty());
            $cartItem->setQuoteId($cart->getId());

            $cart->addItem($cartItem);
        }

        $cart->collectTotals();
        $this->cartRepo->save($cart);

        return $cart;
    }
}

Quiz

1. What is a company account in B2B?

Question 1 options

2. What is a shared catalog?

Question 2 options

3. What is a requisition list?

Question 3 options

Flashcards

Question

What is a company account?

Answer

Organization with users, roles, and credit limits

Question

What is a shared catalog?

Answer

Custom product catalog with company-specific pricing

Question

What is quick order?

Answer

Fast ordering by SKU or CSV upload

Question

What is a requisition list?

Answer

Saved product list for repeat purchases

Revision Notes

Key Takeaways

  • 1. Company accounts group users under one organization
  • 2. Roles and permissions control user access
  • 3. Quick order enables fast SKU-based ordering
  • 4. Requisition lists save products for repeat orders
  • 5. Credit limits control company spending

Interview Tips

  • Explain the B2B company hierarchy
  • Discuss shared catalog vs default catalog
  • Describe quick order implementation
  • Talk about requisition list use cases

Cheat Sheet

B2B Features:
  Company → users, roles, credit
  Shared Catalog → custom pricing
  Quick Order → SKU-based ordering
  Requisition List → saved for reorder

Company:
  Admin → manages company
  Users → place orders
  Roles → permissions
  Credit Limit → spending cap