skip to Main Content

Given that I have multiple websites in my Magento instance, how do I identify the website where a particular event happened? For example, observing the checkout_cart_add_product_complete event lets me catch all Add to Cart events. Let’s say I wanted to get the website Id of the website where this Add to Cart event happened, how do you I do that?

public function addToCart(Varien_Event_Observer $observer) {
    $product = $observer->getEvent()->getProduct();
    $websiteId = $observer->getEvent()->get ??? ();
}

I know that I can get the websiteIds of the product that was added to the cart, by doing the following

$websiteIds = $observer->getEvent()->getProduct()->getWebsiteIds();

But that is not what I want, because if the product belongs to more than one website, it will give me all the websites and not the one where the Add to Cart event happened.

Thanks

2

Answers


  1. Have you tried:

    Mage::app()->getStore()->getId()
    

    within your observer? That should give you the current store id..

    Login or Signup to reply.
  2. You can directly get the StoreId from Mage, not from the observer object.

    StoreId:
    Mage::app()->getStore()->getStoreId();

    WebsiteId:
    Mage::app()->getStore()->getWebsiteId();

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search