Jigar KarangiyaJigar Karangiya

how to get shared catalog data by ID in Magento 2?

JK
Jigar Karangiya
· 1 min read
how to get shared catalog data by ID in Magento 2?

Magento gives you the ability to maintain shared catalogs with the custom pricing structure for different companies.

You can get Shared Catalog data by shared catalog id programmatically.
Magento\SharedCatalog\Api\SharedCatalogRepositoryInterface Interface used to get, delete and save Shared catalog related things.

php
<?php
class YourClass {
 
    public function __construct(
        \Magento\SharedCatalog\Api\SharedCatalogRepositoryInterface $sharedCatalogRepository
    ) {
        $this->sharedCatalogRepository = $sharedCatalogRepository;
    }
 
    public function getSharedCatalog()
    {
        $sharedCatalogId = 1;
        $sharedCatalog = $this->sharedCatalogRepository->get($sharedCatalogId);
        print_r($sharedCatalog->debug(),true); //to debug shared catalog data
        return $sharedCatalog;
    }
}

You can then use it using by calling function $this- >getSharedCatalog();

If you will print the output of the function it will return result like below.

Output :

javascript
[
    "entity_id" => "1",
    "name" => "Default (General)",
    "description" => "Default shared catalog",
    "customer_group_id" => "1",
    "type" => "1",
    "created_at" => "2023-05-16 11:55:38",
    "created_by" => "19",
    "store_id" => "0",
    "customer_group_code" => "Default (General)",
    "tax_class_id" => "3",
  ]

As you can see in the above result, you will get shared catalog-related data like Id, Name, Customer Group Id, etc.

You will also like this :

Get Company Admin using company ID programmatically Magento 2 B2B.

That’s it. Thanks for reading. Keep coding !!

Written by Jigar Karangiya, Adobe Commerce & Magento 2 developer.

More about me

Related posts