0

I have a multi-store setup with Magento 2.1.7 CE on the domain a, domain b, domain c. I want to apply images to some products programmatically. When I make an API call on any domain with the "all" path:

(index.php/rest/**all**/V1/my/apply/images. instead of index.php/rest/V1/my/apply/images)

The store is 0 - that's what I want. The api calls a helper method in this case.

But I do not want to call the REST API but do this by CLI to avoid timeouts. So I wrote a command and this is calling the same helper method as the REST API call does. So I wonder how to set the store. It's running the default store only.

Using the storeManager->setCurrentStore(0) before calling the helper method doesn't have any effects.

Do you have any suggestions?

0

As I can see in \Magento\Store\Model\StoreManagerInterface, the method setCurrentStore expects a string as single argument, but when using a string, this doesn't work either.

But it works when using \Magento\Store\Api\Data\StoreInterface as an argument ($this->_storeManager is the injected \Magento\Store\Model\StoreManagerInterface in this example):

$this->_storeManager->setCurrentStore($this->_storeManager->getStore(0));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.