/**
  * @param Mage_Customer_Model_Customer $customer
  * @return bool
  * @throws Exception
  */
 public function isCustomerFacebookUser(Mage_Customer_Model_Customer $customer)
 {
     $customerEmail = $customer->getData('email');
     $facebookUser = $this->getFacebookUser()->setData('store_id', $customer->getStoreId());
     $facebookUser->loadByEmail($customerEmail);
     return (bool) $facebookUser->getId() && $customer->getStoreId() == $facebookUser->getData('store_id');
 }
Example #2
0
 /**
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param string $pointsString
  * @param type $date
  */
 public function systemLog($customer, $pointsString, $date)
 {
     $storeId = $customer->getStoreId();
     if ($this->_getHelper()->isLogBirthdayEnabled($storeId)) {
         $name = $customer->getName();
         $email = $customer->getEmail();
         $msg = $this->_getHelper()->__("Customer %s with the e-mail %s has a birthday on %s and been rewarded %s.", $name, $email, $date, $pointsString);
         Mage::log($msg, null, $this->getLogFileName());
     }
 }
Example #3
0
 protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             $address->delete();
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->save();
         }
     }
     return $this;
 }
Example #4
0
 /**
  * Send customer email
  *
  * @return bool
  */
 public function send()
 {
     if (is_null($this->_website) || is_null($this->_customer)) {
         return false;
     }
     if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) {
         return false;
     }
     if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) {
         return false;
     }
     $store = Mage::getModel('core/store')->load($this->_customer->getStoreId());
     $storeId = $store->getId();
     if ($this->_type == 'price' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId)) {
         return false;
     } elseif ($this->_type == 'stock' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId)) {
         return false;
     }
     if ($this->_type != 'price' && $this->_type != 'stock') {
         return false;
     }
     $appEmulation = Mage::getSingleton('core/app_emulation');
     $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
     Mage::app()->getTranslator()->init('frontend', true);
     if ($this->_type == 'price') {
         $this->_getPriceBlock()->setStore($store)->reset();
         foreach ($this->_priceProducts as $product) {
             $product->setCustomerGroupId($this->_customer->getGroupId());
             $this->_getPriceBlock()->addProduct($product);
         }
         $block = $this->_getPriceBlock()->toHtml();
         $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId);
     } else {
         $this->_getStockBlock()->setStore($store)->reset();
         foreach ($this->_stockProducts as $product) {
             $product->setCustomerGroupId($this->_customer->getGroupId());
             $this->_getStockBlock()->addProduct($product);
         }
         $block = $this->_getStockBlock()->toHtml();
         $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId);
     }
     $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
     Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional($templateId, Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId), $this->_customer->getEmail(), $this->_customer->getName(), array('customerName' => $this->_customer->getName(), 'alertGrid' => $block));
     return true;
 }
 /**
  * Create array of customer values for API
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return array
  */
 public function getCustomerData(Mage_Customer_Model_Customer $customer)
 {
     try {
         if ($primaryBillingAddress = $customer->getPrimaryBillingAddress()) {
             $address = implode(', ', $primaryBillingAddress->getStreet());
             $state = $customer->getPrimaryBillingAddress()->getRegion();
             $zipcode = $customer->getPrimaryBillingAddress()->getPostcode();
         } else {
             $address = '';
             $state = '';
             $zipcode = '';
         }
         $data = array('id' => $customer->getEmail(), 'key' => 'email', 'fields' => array('keys' => 1), 'keysconfict' => 'merge', 'vars' => array('id' => $customer->getId(), 'name' => $customer->getName(), 'suffix' => $customer->getSuffix() ? $customer->getSuffix() : '', 'prefix' => $customer->getPrefix() ? $customer->getPrefix() : '', 'firstName' => $customer->getFirstname(), 'middleName' => $customer->getMiddlename() ? $customer->getMiddlename() : '', 'lastName' => $customer->getLastname(), 'address' => $address, 'storeID' => $customer->getStoreId(), 'groupId' => $customer->getGroupId(), 'taxClassId' => $customer->getTaxClassId(), 'createdAt' => date("Y-m-d H:i:s", $customer->getCreatedAtTimestamp()), 'primaryBillingAddress' => $this->getAddress($customer->getPrimaryBillingAddress()), 'defaultBillingAddress' => $this->getAddress($customer->getDefaultBillingAddress()), 'defaultShippingAddress' => $this->getAddress($customer->getDefaultShippingAddress()), 'state' => $state, 'zipCode' => $zipcode), 'lists' => array(Mage::helper('sailthruemail')->getMasterList() => 1));
         return $data;
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Example #6
0
 public function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     $defaultPickupId = $customer->getData('default_pickup');
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             if ($address->getId() == $defaultPickupId) {
                 $customer->setData('default_pickup', null);
             }
             $address->delete();
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
             if (($address->getIsPrimaryPickup() || $address->getIsDefaultPickup()) && $address->getId() != $defaultPickupId) {
                 $customer->setData('default_pickup', $address->getId());
             }
         }
     }
     if ($customer->dataHasChangedFor('default_billing')) {
         $this->saveAttribute($customer, 'default_billing');
     }
     if ($customer->dataHasChangedFor('default_shipping')) {
         $this->saveAttribute($customer, 'default_shipping');
     }
     if ($customer->dataHasChangedFor('default_pickup')) {
         $this->saveAttribute($customer, 'default_pickup');
     }
     return $this;
 }
Example #7
0
 /**
  * Save customer
  *
  * @deprecated after 1.4.0.0.
  * @param Mage_Customer_Model_Customer $order
  */
 protected function _saveCustomerAfterOrder($order)
 {
     if ($this->_customer) {
         if (!$this->_customer->getId()) {
             $billing = $this->getBillingAddress();
             $customerBilling = $billing->exportCustomerAddress();
             $shipping = $this->getShippingAddress();
             $customerShipping = $shipping->exportCustomerAddress();
             $this->_customer->addAddress($customerBilling);
             if (!$shipping->getSameAsBilling()) {
                 $this->_customer->addAddress($customerShipping);
             }
             // preliminary save to find addresses id
             $this->_customer->save();
             // setting default addresses id
             $defShipping = $shipping->getSameAsBilling() ? $customerBilling->getId() : $customerShipping->getId();
             $this->_customer->setDefaultBilling($customerBilling->getId())->setDefaultShipping($defShipping)->save();
             $order->setCustomerId($this->_customer->getId());
             $billing->setCustomerId($this->_customer->getId());
             $shipping->setCustomerId($this->_customer->getId());
             $this->_customer->sendNewAccountEmail('registered', '', $order->getStoreId());
         } else {
             $saveCusstomerAddress = false;
             if ($this->getBillingAddress()->getSaveInAddressBook()) {
                 $billingAddress = $this->getBillingAddress()->exportCustomerAddress();
                 if ($this->getBillingAddress()->getCustomerAddressId()) {
                     $billingAddress->setId($this->getBillingAddress()->getCustomerAddressId());
                 }
                 $this->_customer->addAddress($billingAddress);
                 $saveCusstomerAddress = true;
             }
             if ($this->getShippingAddress()->getSaveInAddressBook()) {
                 $shippingAddress = $this->getShippingAddress()->exportCustomerAddress();
                 if ($this->getShippingAddress()->getCustomerAddressId()) {
                     $shippingAddress->setId($this->getShippingAddress()->getCustomerAddressId());
                 }
                 $this->_customer->addAddress($shippingAddress);
                 $saveCusstomerAddress = true;
             }
             if ($saveCusstomerAddress) {
                 $this->_customer->save();
             }
         }
     }
 }
Example #8
0
 /**
  * Return the Store Id to read configuration settings for this customer from
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return int
  */
 public function getCustomerStoreId(Mage_Customer_Model_Customer $customer)
 {
     /*
      * Only set in Adminhtml UI
      */
     if (!($storeId = $customer->getSendemailStoreId())) {
         /*
          * store_id might be zero if the account was created in the admin interface
          */
         $storeId = $customer->getStoreId();
         if (!$storeId && $customer->getWebsiteId()) {
             /*
              * Use the default store groups store of the customers website
              */
             if ($store = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()) {
                 $storeId = $store->getId();
             }
         }
         // In case the website_id is not yet set on the customer, and the
         // current store is a frontend store, use the current store ID
         if (!$storeId && !Mage::app()->getStore()->isAdmin()) {
             $storeId = Mage::app()->getStore()->getId();
         }
     }
     return $storeId;
 }
Example #9
0
 /**
  * Save/delete customer address
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return Mage_Customer_Model_Entity_Customer
  */
 protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $customer->getData('default_billing')) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $customer->getData('default_shipping')) {
                 $customer->setData('default_shipping', null);
             }
             $address->delete();
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->save();
             if ($address->getIsPrimaryBilling() && $address->getId() != $customer->getData('default_billing')) {
                 $customer->setData('default_billing', $address->getId());
             }
             if ($address->getIsPrimaryShipping() && $address->getId() != $customer->getData('default_shipping')) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
         if ($customer->dataHasChangedFor('default_billing')) {
             $this->saveAttribute($customer, 'default_billing');
         }
         if ($customer->dataHasChangedFor('default_shipping')) {
             $this->saveAttribute($customer, 'default_shipping');
         }
     }
     return $this;
 }
Example #10
0
 /**
  * Check to see if the user has been created via the admin section
  *
  * @param Mage_Customer_Model_Customer $oCustomer
  * @return bool
  */
 private function isCustomerAdminCreation(Mage_Customer_Model_Customer $oCustomer)
 {
     return $oCustomer->getStoreId() === Mage_Core_Model_App::ADMIN_STORE_ID;
 }
Example #11
0
 /**
  * Save/delete customer address
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return Mage_Customer_Model_Resource_Customer
  */
 protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var Mage_Customer_Model_Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     if ($customer->dataHasChangedFor('default_billing')) {
         $this->saveAttribute($customer, 'default_billing');
     }
     if ($customer->dataHasChangedFor('default_shipping')) {
         $this->saveAttribute($customer, 'default_shipping');
     }
     return $this;
 }
 /**
  * Send email with new release information.
  *
  * @param Mage_Customer_Model_Customer $customer
  * 		Customer to send the mail to
  * @param Faett_Package_Model_Link_Purchased $linkPurchased
  * 		The data about when the product has been purchased
  * @param Faett_Package_Model_Link $link
  * 		Data previously created link
  * @return Faett_Package_Model_Mysql4_Link
  * 		The instance
  */
 protected function _sendNewReleaseEmail(Mage_Customer_Model_Customer $customer, Faett_Package_Model_Link_Purchased $linkPurchased, Faett_Package_Model_Link $link)
 {
     try {
         // load the translation model
         $translate = Mage::getSingleton('core/translate');
         $translate->setTranslateInline(false);
         // initialize the store ID necessary for the translation
         $storeId = $customer->getStoreId();
         if ($customer->getWebsiteId() != '0' && $storeId == '0') {
             $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
             reset($storeIds);
             $storeId = current($storeIds);
         }
         // load the email template, generate and send the mail
         Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional(Mage::getStoreConfig(Faett_Channel_Model_Service::XML_PATH_EMAILS_RELEASE_NEW), Mage::getStoreConfig(Mage_Customer_Model_Customer::XML_PATH_REGISTER_EMAIL_IDENTITY), $customer->getEmail(), $customer->getName(), array('customer' => $customer, 'linkPurchased' => $linkPurchased, 'link' => $link));
         // close the translation model
         $translate->setTranslateInline(true);
     } catch (Exception $e) {
         Mage::logException($e);
     }
     // return the instance itself
     return $this;
 }