Magento 2 get Store Id of a coupon code programmatically

I am using multiple stores, I wanted to get all the coupon code of a particular store.

In Magento 2 database, salesrule_website table have stores related information, but their is no model/collection to get the data from this table.

Please guide me how to get store information of a coupon code, or I need to create my own model for salesrule_website table.

Solutions

As we know, Magento is not providing any Model or Collection for salesrule_website table.

So what I did to solve this issue is, I used mysql to get collection from that table.

Code:

$stringId = '10';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('salesrule_website');
$sql = "Select website_id FROM " . $tableName ." Where rule_id IN ('".$stringId."')";
$result = $connection->fetchAll($sql);
if($result)
{
  // Your code goes here
}

Similar questions

how to apply only 1 coupon code when there are multiples coupon codes
I am running magento 1.9 and i have multiple coupon codes on site. how to make that only 1 coupon code apply on cart? any body know how to apply on 1 coupon on cart?
Get store code, not store view code
Using the StoreManagerInterface I am getting the current store via $store = $this->storeManager->getStore(). I then want to get the code of the store. However, when using $store->getCode() I get the code of the store view, not the store. Is there any way to just get the code of the store, not the store view?
How to get store information (e.g Store Base Url) of another store in a multi-store setup for Magento 2
I have multiple stores on my Magento 2 installation. So I have store 1 base url as http://mystore1.com and store 2 base url as http://mystore2.com. How do i get the base url of store 2 dynamically on a phtml file in store 1. Note: $block->getBaseUrl() will only return the current store url. Is there a function like getBaseUrl of store id = 2 ?
Create coupon code programmatically (in Magento 2.x)
I'm trying to port over tens of thousands of coupons from a custom e-commerce website into Magento 2.0.8 and I'm having a hard time getting it to work. These are simple coupons either fixed $ or % off of the carts subtotal. I have been unable to get it to save from the command line. I have a command called coupons:migrate that I'm running this code...
How to apply an existing coupon code programmatically in Magento 2
I try to apply an existing coupon code programmatically in a controller by coupon id. The only thing I found these code lines for Magento 1. Does anyone know how can I do this in magento 2?
Magento 2: Apply coupon code programmatically
I want to apply coupon code programmatically when the condition is true. If condition false coupon code should be not applied. Please help me.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.