예제 #1
0
파일: Data.php 프로젝트: jahvi/MinTotalQty
 /**
  * Check if quote meets the minimun quantity
  * of total items for a specific customer
  *
  * @todo   Change to more meaningful name
  *
  * @param  Mage_Sales_Model_Quote       $quote
  * @param  Mage_Customer_Model_Customer $customer
  * @return int|false
  */
 public function minimunOrderQty(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Customer $customer)
 {
     $minQtyForCustomer = $this->getConfigValue($customer->getGroupId());
     if ($quote->getItemsQty() < $minQtyForCustomer && $quote->getItemsQty() !== 0) {
         return $minQtyForCustomer;
     }
     return false;
 }
예제 #2
0
 /**
  * Sets API attributes on a customer object
  *
  * @param Mage_Customer_Model_Customer $customer Customer to work with
  *
  * @return void
  */
 public function setGroupNameAndGenderNameForCustomer($customer)
 {
     if ($this->_customerGroups == null) {
         $this->_customerGroups = array();
         /* @var Mage_Customer_Model_Resource_Group $customerGroups */
         $customerGroups = Mage::getModel('customer/group')->getCollection();
         foreach ($customerGroups as $group) {
             $groupId = $group['customer_group_id'];
             $groupCode = $group['customer_group_code'];
             $this->_customerGroups[$groupId] = $groupCode;
         }
     }
     if (array_key_exists($customer->getGroupId(), $this->_customerGroups)) {
         $customer->setGroupName($this->_customerGroups[$customer->getGroupId()]);
     }
     $customer->setGenderName(Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getOptionText($customer->getGender()));
 }
예제 #3
0
 /**
  * @param Mage_Customer_Model_Customer $customer
  * @param $subscriberId
  * @return $this
  */
 public function addSubscriberToSegment(Mage_Customer_Model_Customer $customer, $subscriberId)
 {
     $segments = Mage::helper('newsman_newsletter')->getSegments();
     if (!$segments) {
         return $this;
     }
     foreach ($segments as $segment) {
         if ($segment['customer_group_id'] == $customer->getGroupId()) {
             Mage::getModel('newsman_newsletter/api_segment')->addSubscriber($segment['segment'], $subscriberId);
         }
     }
     return $this;
 }
 /**
  * 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 = $this->_website->getDefaultStore();
     $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;
     }
     // set design parameters, required for email (remember current)
     $currentDesign = Mage::getDesign()->setAllGetOld(array('store' => $storeId, 'area' => 'frontend', 'package' => Mage::getStoreConfig('design/package/name', $storeId)));
     Mage::app()->getLocale()->emulate($storeId);
     $translate = Mage::getSingleton('core/translate');
     /* @var $translate Mage_Core_Model_Translate */
     $translate->setTranslateInline(false);
     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);
     } elseif ($this->_type == 'stock') {
         $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);
     } else {
         Mage::app()->getLocale()->revert();
         return false;
     }
     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));
     $translate->setTranslateInline(true);
     // revert current design
     Mage::getDesign()->setAllGetOld($currentDesign);
     Mage::app()->getLocale()->revert();
     return true;
 }
예제 #5
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;
     }
     $storeId = $this->_website->getDefaultGroup()->getDefaultStore()->getId();
     $storeCode = $this->_website->getDefaultGroup()->getDefaultStore()->getCode();
     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;
     }
     Mage::getDesign()->setStore($storeId);
     Mage::getDesign()->setArea('frontend');
     $translate = Mage::getSingleton('core/translate');
     /* @var $translate Mage_Core_Model_Translate */
     $translate->setTranslateInline(false);
     if ($this->_type == 'price') {
         $this->_getPriceBlock()->setStoreCode($storeCode);
         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);
     } elseif ($this->_type == 'stock') {
         $this->_getStockBlock()->setStoreCode($storeCode);
         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);
     } else {
         return false;
     }
     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));
     $translate->setTranslateInline(true);
     return true;
 }
예제 #6
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);
     }
 }
예제 #8
0
 /**
  * Gets group code by customer's groupId
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return string|null
  */
 protected function _getCustomerGroupCode($customer)
 {
     if (is_null($this->_customerGroups)) {
         $groups = Mage::getResourceModel('customer/group_collection')->load();
         foreach ($groups as $group) {
             $this->_customerGroups[$group->getId()] = $group->getData('customer_group_code');
         }
     }
     if (isset($this->_customerGroups[$customer->getGroupId()])) {
         return $this->_customerGroups[$customer->getGroupId()];
     } else {
         return null;
     }
 }
 /**
  * Setter.
  * Set customer id
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return Enterprise_Reward_Model_Reward
  */
 public function setCustomer($customer)
 {
     $this->setData('customer_id', $customer->getId());
     $this->setData('customer_group_id', $customer->getGroupId());
     $this->setData('customer', $customer);
     return $this;
 }
예제 #10
0
 /**
  * Define customer object
  *
  * @param   Mage_Customer_Model_Customer $customer
  * @return  Mage_Sales_Model_Quote
  */
 public function setCustomer(Mage_Customer_Model_Customer $customer)
 {
     $this->_customer = $customer;
     $this->setCustomerId($customer->getId());
     $this->setCustomerEmail($customer->getEmail());
     $this->setCustomerFirstname($customer->getFirstname());
     $this->setCustomerLastname($customer->getLastname());
     $this->setCustomerGroupId($customer->getGroupId());
     $this->setCustomerTaxClassId($customer->getTaxClassId());
     return $this;
 }
예제 #11
0
 /**
  * @param Mage_Customer_Model_Customer $magentoCustomer
  * @return array $collection
  */
 public function getShopgateCustomerGroups($magentoCustomer)
 {
     $collection = Mage::getModel('customer/group')->getCollection();
     if (!$magentoCustomer->getId()) {
         $collection->addFieldToFilter('customer_group_code', 'NOT LOGGED IN');
     } else {
         $collection->addFieldToFilter('customer_group_id', $magentoCustomer->getGroupId());
     }
     $groups = array();
     foreach ($collection->getItems() as $customerGroup) {
         $group = array();
         $group['id'] = $customerGroup->getCustomerGroupId();
         $group['name'] = $customerGroup->getCustomerGroupCode();
         $groups[] = $group;
     }
     return $groups;
 }
예제 #12
0
 /**
  * Check if customer is authorized to access store
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param Mage_Core_Model_Store $store
  * @return boolean
  */
 public function isAuthorized($customer, $store = null)
 {
     $groups = $this->getAllowedCustomerGroups($store);
     if (in_array(0, $groups) && !(bool) $customer->getId()) {
         // not logged in
         return true;
     } else {
         // logged in customers within the right group
         return (bool) $customer->getId() && in_array($customer->getGroupId(), $groups);
     }
 }