public function recover($visitorId) { $oldQuote = Mage::getModel('sales/quote')->load($visitorId, 'jirafe_visitor_id'); if ($oldQuote->getId()) { $customerSession = Mage::getSingleton('customer/session'); if ($oldQuote->getConvertedAt()) { $customerSession->addNotice(Mage::helper('foomanjirafe')->__('This basket has been ordered already.')); return false; } if ($oldQuote->getCustomerId()) { $customer = Mage::getModel('customer/customer')->load($oldQuote->getCustomerId()); if ($customerSession->isLoggedIn()) { $customerSession->logout(); } $customerSession->setCustomerAsLoggedIn($customer); } Mage::getSingleton('checkout/session')->replaceQuote($oldQuote); $oldQuote->setJirafeOrigVisitorId($visitorId)->save(); $siteId = Mage::helper('foomanjirafe')->getStoreConfig('site_id', $oldQuote->getStoreId()); $jirafePiwikUrl = 'http://' . Mage::getModel('foomanjirafe/jirafe')->getPiwikBaseUrl(); $piwikTracker = new Fooman_Jirafe_Model_JirafeTracker($siteId, $jirafePiwikUrl); $piwikTracker->doRecoveryEmailUpdate($visitorId, 3); return true; } return false; }
/** * add all visible items from a quote as tracked ecommerce items * * @param Fooman_Jirafe_Model_JirafeTracker $piwikTracker * @param Mage_Sales_Model_Quote $quote */ protected function _addEcommerceItems($piwikTracker, $quote) { foreach ($quote->getAllVisibleItems() as $item) { if ($item->getName()) { //we only want to track the main configurable item //but not the subitem if ($item->getParentItem()) { if ($item->getParentItem()->getProductType() == 'configurable') { continue; } } $itemPrice = $item->getBasePrice(); // This is inconsistent behaviour from Magento // base_price should be item price in base currency // TODO: add test so we don't get caught out when this is fixed in a future release if (!$itemPrice || $itemPrice < 1.0E-5) { $itemPrice = $item->getPrice(); } $piwikTracker->addEcommerceItem($item->getProduct()->getData('sku'), $item->getName(), Mage::helper('foomanjirafe')->getCategory($item->getProduct()), $itemPrice, $item->getQty()); } } }