Hot answers tagged

22

Mage::getModel('core/store')->load($storeCode, 'code')->getId() Isn't this the simplest way to do?


20

Like this: Mage::getModel('core/store')->load($storeId)->getWebsiteId() Or do a direct database lookup on the core_store table.


17

you need to use the instance of \Magento\Framework\App\Config\ScopeConfigInterface in your block: Create the method getStoreName() public function getStoreName() { return $this->_scopeConfig->getValue( 'general/store_information/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } and call in your template echo $this-&...


17

Try the below code - <?php namespace Custom\Module\Controller\Index; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; class Index extends \Magento\Framework\App\Action\Action { protected $request; protected $scopeConfig; public function __construct( \Magento\Framework\App\Action\Context $...


17

I just recently came across this same situation after migrating from Magento 1.6.1.0 to 2.1.4 and hope my answer can be of assistance. The problem came from deleting multiple stores 96 of them to be exact. I tried all the other answers here but was still getting the same error. The fix for me was removing the old store data from inside of the "...


15

To add a store use the code below: //#addWebsite /** @var $website Mage_Core_Model_Website */ $website = Mage::getModel('core/website'); $website->setCode('<your_website_code_here>') ->setName('<your_website_name>') ->save(); //#addStoreGroup /** @var $storeGroup Mage_Core_Model_Store_Group */ $storeGroup = Mage::getModel('core/...


14

You can use \Magento\Store\Api\Data\StoreInterface or Magento\Framework\Locale\Resolver class to get store language. 1) BY USING \Magento\Store\Api\Data\StoreInterface CLASS With objectManager $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $store = $objectManager->get('Magento\Store\Api\Data\StoreInterface'); echo $store->...


13

You need to run following query in your database, and then try to open website. SET FOREIGN_KEY_CHECKS=0; UPDATE `store` SET store_id = 0 WHERE code='admin'; UPDATE `store_group` SET group_id = 0 WHERE name='Default'; UPDATE `store_website` SET website_id = 0 WHERE code='admin'; UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='...


12

Just for completeness: From the current store you're in, you could retrieve the websiteId as follows: Mage::app()->getStore()->getWebsiteId();


12

I was struggling with the same problem for some time and finally managed to solve it. Maybe you already solved it by now, but it can definitely be useful for others. Summary The needed code can be found at the end of this post. create all missing folders on this path: /var/www/magento/app/design/frontend/{namespace}/{name}/Magento_Store/templates/switch ...


10

Haven't tested this but I seem to remember you can get the ID by using the method loadConfig in the model Mage_Core_Model_Store After that you can get the ID by calling getId() on the model. The loadConfig method uses the loaded configuration to retrieve store data $store = Mage::getConfig()->getNode()->stores->{$code}; Which gives you the ...


9

Use store manager, which holds information about active store. If custom block is not inherited from Template block, inject dependency on \Magento\Store\Model\StoreManagerInterface in construct. <?php namespace VendorName\ModuleName\Block; class CustomBlock extends \Magento\Framework\View\Element\Template { /** * Get current store name. * ...


8

you can get it like that... $websiteId=1; $website = Mage::getModel('core/website')->load($websiteId); foreach ($website->getGroups() as $group) { $stores = $group->getStores(); foreach ($stores as $store) { echo $store->getId() ." ".$store->getName()."<br/>"; } }


6

Fabian is right, you have to provide the correct store, because by default it is admin. The search engines are throwing out this result: Mage::app()->getStore()->getRootCategoryId() which is not good enough for you, because you will have to provide the store's code also: Mage::app()->getStore("default")->getRootCategoryId() The default store'...


5

What you are describing is no standard behaviour of magento, so depending on how this is all implemented, we might help you. Can you describe how the users are connected with the stores? If you know the user, then you know the store. Just to make sure we are talking about the Same things where: Website -> Store -> StoreView (I'll use this ...


5

I don't know if this is something that's peculiar to 1.9.0.0 but I couldn't get either Mage::getConfig()->getNode()->stores->{$code} or Mage::getModel('core/store')->loadConfig($code) (which in fact calls Mage::getConfig()->getNode()->stores->{$code}) to return anything. The first was close... with a subtle change in form, this gets a ...


5

Following blog could help you: http://www.blog.magepsycho.com/how-to-filter-shipping-method-in-onepage-checkout/


5

Just incase the site given in another answer goes down for some reason. You may want to filter shipping method in onepage checkout for one of the following cases: Filter shipping method based on Customer Group Filter Shipping method based on Country, State, Zipcode etc Filter Shipping method based on products etc. Unlike event: ‘payment_method_is_active’ ...


5

Try this $websiteIds = array(Mage::app()->getStore()->getWebsiteId()); $storeId = Mage::app()->getStore()->getStoreId(); $collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*'); $collection->addStoreFilter($storeId); $collection->addWebsiteFilter($websiteIds);


5

You can get current locale by using below way, Use of Directly Objectmanager in phtml file is not perfect way for magento 2 standard, $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $getLocale = $objectManager->get('Magento\Framework\Locale\Resolver'); $haystack = $getLocale->getLocale(); $lang = strstr($haystack, '_', ...


4

There are some methods that require an admin level to perform properly as they will be applied across all store views. By default the store ID will always be set as 1 if not specified, causing some methods to fail or odd behaviour. An example would be needing to apply a scripted change across all store views, for example product Images or such. https://...


4

$category = Mage::getModel('catalog/category')->load($categoryId); $collection = Mage::getModel('catalog/product')->getCollection() ->addCategoryFilter($category); //you can use the next lines to add some minimal information about the products to the collection //thanks @DavidManners $collection->addAttributeToSelect(Mage::...


4

In Magento 2 to you can find the Website Id using store id like this: $this->_storeManager->getStore($storeID)->getWebsiteId();


4

The following should work: <?php echo Mage::getModel('core/store')->loadConfig($code)->getId(); ?>


4

You could get the product id from the core_url_rewrite table using the url for this, try this: $url = Mage::helper->getURL(); $rewrite = Mage::getModel('core/url_rewrite') ->setStoreId(Mage::app()->getStore()->getId()) ->loadByRequestPath($url); $productId = $rewrite->getProductId(); $product = Mage::getModel('catalog/product')-&...


4

To get a store configuration value like general/store_information/name you can use the following $config = new \Magento\Framework\App\Config\ScopeConfigInterface(); echo $config->getValue('general/store_information/name'); However, doing this from a block or helper would be cleaner. Below is a helper class that would exist in your own custom module ...


4

You need to set store id when you load product object, Your final code look like this $storeId = '1'; //Store ID $product_id = 7878; $price = "3.99"; $productFactory = $objectManager->get('\Magento\Catalog\Model\ProductFactory'); $product = $productFactory->create()->setStoreId($storeId)->load($product_id); $product->setPrice($price); $...


4

Step 1: Create websites In your Magento backend, go to Stores > Settings > All Stores On the Stores page, click Create Website. Name: Enter a name to identify the website. Code: Enter a unique code; for example, if you have a French store, you can enter french Sort Order: Enter an optional numerical sort order. Click Save Web Site. Repeat these tasks ...


4

Here is an work around for you. Inorder to change default association of customer you have to do some manual stuffs in database[Make sure you do backup of database before performing any database operations directly]. Go to database table customer_entity, find the customer entry by customer id. Change the website_id column to the new website where you want ...


3

As the answer in this stackoverflow question says you need some another node surrounding your code. When you wrap your code with <stores> and then it will work. <default> <some> <config> <value>default</value> </config> </some> </default> <stores> <...


Only top voted, non community-wiki answers of a minimum length are eligible