Shared Catalog is the native functionality of B2B Magento Commerce. Magento gives you the ability to maintain shared catalogs with the custom pricing structure for different companies. A Public Default(General) Catalog will be available native with Magento B2B.
You can get Shared Catalog data by Customer group id programmatically using
Magento\SharedCatalog\Api\SharedCatalogRepositoryInterface.
Interface used to get, delete and save catalog data related stuff.
Get Shared Catalog Data by id Magento 2 B2B
You need to filter customer_group_id using SearchCriteriaBuilder Interface and assigned searchCriteria object to sharedCatalogRepository getList() method.
<?php
public function __construct(
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\SharedCatalog\Api\SharedCatalogRepositoryInterface $sharedCatalogRepository
) {
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->sharedCatalogRepository = $sharedCatalogRepository;
}
public function getSharedCatalog()
{
$customerGroupId = 1; //assigned customer group id
$this->searchCriteriaBuilder->addFilter("customer_group_id", $customerGroupId);
$searchCriteria = $this->searchCriteriaBuilder->create();
$sharedCatalog = $this->sharedCatalogRepository->getList($searchCriteria);
return $sharedCatalog;;
}
Call function like,
$sharedCatalog = $this->getSharedCatalog();
if($sharedCatalog->getTotalCount() > 0) {
foreach($sharedCatalog->getItems() as $item) {
echo "<pre>";print_r($item->getData());
}
}
You can get the result of shared catalog data by customer_group_id in the above loop.
