Ejemplo n.º 1
0
 /**
  * Checks the legal age
  *
  * @param   array $data
  * @param   int $customerAddressId
  * @return  Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     $result = parent::saveBilling($data, $customerAddressId);
     if (isset($result['error'])) {
         return $result;
     }
     $dobIso = $this->getQuote()->getCustomerDob();
     $dob = new Zend_Date($dobIso, Zend_Date::ISO_8601);
     $legalBirthDay = $dob->add(self::LIMITED_AGE, Zend_Date::YEAR);
     $legal1 = Zend_Date::now()->isLater($legalBirthDay);
     if (!$legal1) {
         // not even limited legal
         $result['error'] = 1;
         $result['message'] = Mage::helper('n98legalage')->__('You are not yet limited contractually capable. You can ask your legal guardian to purchase.');
         return $result;
     }
     $dob = new Zend_Date($dobIso, Zend_Date::ISO_8601);
     $legalBirthDay = $dob->add(self::LEGAL_AGE, Zend_Date::YEAR);
     $legal2 = Zend_Date::now()->isLater($legalBirthDay);
     if (!$legal2) {
         $result['error'] = 1;
         $result['message'] = Mage::helper('n98legalage')->__('You are not yet contractually capable. You can ask your legal guardian to purchase on your behalf.');
         return $result;
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['is_subscribed']) && !empty($data['is_subscribed'])) {
         Mage::getSingleton('customer/session')->setCustomerIsSubscribed(1);
     } else {
         Mage::getSingleton('customer/session')->setCustomerIsSubscribed(0);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 3
0
 /**
  * @param array $data
  * @param int $customerAddressId
  * @return Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['is_subscribed']) && !empty($data['is_subscribed'])) {
         $this->getCheckout()->setCustomerIsSubscribed(1);
     } else {
         $this->getCheckout()->setCustomerIsSubscribed(0);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 4
0
 public function saveBilling($data, $customerAddressId)
 {
     if (empty($data)) {
         return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
     }
     if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
         if ($this->_customerMobileExists($data['telephone'], Mage::app()->getWebsite()->getId())) {
             return array('error' => 1, 'message' => $this->_customerMobileExistsMessage);
         }
     }
     return parent::saveBilling($data, $customerAddressId);
 }
 /**
  * Save billing address information to quote
  * This method is called by One Page Checkout JS (AJAX) while saving the billing information.
  *
  * @param   array $data
  * @param   int $customerAddressId
  * @return  Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     //$session = $this->getCustomerSession();
     //$customer = $session->getCustomer();
     $quote = $this->getQuote();
     $email = !empty($data['email']) ? $data['email'] : null;
     try {
         //Mage::getModel('icc_purchases/link_purchases')->canBuy($quote, $email);
     } catch (Exception $e) {
         return array('error' => -1, 'message' => $e->getMessage());
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 6
0
 public function saveBilling($data, $customerAddressId)
 {
     $active = Mage::getStoreConfig('j2tonecheckout/default/active', Mage::app()->getStore()->getStoreId());
     if ($active) {
         if (isset($data['is_subscribed']) && !empty($data['is_subscribed'])) {
             //$this->getCheckout()->setCustomerIsSubscribed(1);
             //j2tonecheckout
             Mage::getSingleton('j2tonecheckout/session')->setCustomerIsSubscribed(1);
         } else {
             //$this->getCheckout()->setCustomerIsSubscribed(0);
             Mage::getSingleton('j2tonecheckout/session')->setCustomerIsSubscribed(0);
         }
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 7
0
 /**
  * Save billing address information to quote
  * This method is called by One Page Checkout JS (AJAX) while saving the billing information.
  *
  * @param   array $data
  * @param   int $customerAddressId
  * @return  Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     if (empty($data)) {
         return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
     }
     Mage::getSingleton('core/session')->setRegistry('');
     if (isset($_POST['fm_fields'])) {
         foreach ($_POST['fm_fields'] as $key => $value) {
             if (substr($key, 0, 3) == 'fm_') {
                 Mage::getModel('fieldsmanager/fieldsmanager')->SaveFieldsdata(substr($key, 3), $value);
             }
         }
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 8
0
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['amcustomerattr'])) {
         // checking unique attributes
         $checkUnique = array();
         $collection = Mage::getModel('eav/entity_attribute')->getCollection();
         $collection->addFieldToFilter('is_user_defined', 1);
         $collection->addFieldToFilter('entity_type_id', Mage::getModel('eav/entity')->setType('customer')->getTypeId());
         foreach ($collection as $attribute) {
             if ($attribute->getIsUnique()) {
                 $translations = $attribute->getStoreLabels();
                 if (isset($translations[Mage::app()->getStore()->getId()])) {
                     $attributeLabel = $translations[Mage::app()->getStore()->getId()];
                 } else {
                     $attributeLabel = $attribute->getFrontend()->getLabel();
                 }
                 $checkUnique[$attribute->getAttributeCode()] = $attributeLabel;
             }
         }
         if ($checkUnique) {
             foreach ($checkUnique as $attributeCode => $attributeLabel) {
                 $customerCollection = Mage::getResourceModel('customer/customer_collection');
                 $customerCollection->addAttributeToSelect($attributeCode);
                 if ($customerCollection->getSize() > 0) {
                     foreach ($customerCollection as $customerWithAttribute) {
                         if ($data['amcustomerattr'][$attributeCode] == $customerWithAttribute->getData($attributeCode)) {
                             $result = array('error' => 1, 'message' => Mage::helper('amcustomerattr')->__('Please specify different value for "%s" attribute. Customer with such value already exists.', $attributeLabel));
                             return $result;
                         }
                     }
                 }
             }
         }
         Mage::getSingleton('checkout/session')->setAmcustomerattr($data['amcustomerattr']);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 9
0
 public function saveBilling($data, $customerAddressId)
 {
     if (!isset($data['amcustomerattr'])) {
         return parent::saveBilling($data, $customerAddressId);
     }
     // checking unique attributes
     $checkUnique = array();
     $nameGroupAttribute = '';
     $idGroupSelect = '';
     $collection = Mage::getModel('eav/entity_attribute')->getCollection();
     $filters = array("is_user_defined = 1", "entity_type_id  = " . Mage::getModel('eav/entity')->setType('customer')->getTypeId());
     $collection = Mage::helper('amcustomerattr')->addFilters($collection, 'eav_attribute', $filters);
     /* @
      * setup $checkUnique array('attribute_code','attribute_label')
      */
     foreach ($collection as $attribute) {
         if ($attribute->getIsUnique()) {
             $translations = $attribute->getStoreLabels();
             $storeId = Mage::app()->getStore()->getId();
             $checkUnique[$attribute->getAttributeCode()] = isset($translations[$storeId]) ? $translations[$storeId] : $attribute->getFrontend()->getLabel();
         }
     }
     /* @
      * get attribute code for last attribute with type_internal == 'selectgroup'
      */
     $collection = Mage::getModel('customer/attribute')->getCollection();
     $filters = array("is_user_defined = 1", "entity_type_id  = " . Mage::getModel('eav/entity')->setType('customer')->getTypeId());
     $collection = Mage::helper('amcustomerattr')->addFilters($collection, 'eav_attribute', $filters);
     foreach ($collection as $attribute) {
         if ('selectgroup' == $attribute->getTypeInternal()) {
             $nameGroupAttribute = $attribute->getAttributeCode();
         }
     }
     foreach ($data['amcustomerattr'] as $attributeCode => $attributeValue) {
         if ($attributeCode == $nameGroupAttribute) {
             $idGroupSelect = $attributeValue;
         }
     }
     if ($idGroupSelect) {
         $option = Mage::getModel('eav/entity_attribute_option')->load($idGroupSelect);
         if ($option && $option->getGroupId()) {
             $customer = Mage::getModel('customer/customer');
             $customer->setGroupId($option->getGroupId());
         }
     }
     if (!empty($checkUnique)) {
         foreach ($checkUnique as $attributeCode => $attributeLabel) {
             //skip empty values
             if (!array_key_exists($attributeCode, $data['amcustomerattr']) || !$data['amcustomerattr'][$attributeCode]) {
                 continue;
             }
             $customerCollection = Mage::getResourceModel('customer/customer_collection');
             $customerCollection->addAttributeToFilter($attributeCode, array('eq' => $data['amcustomerattr'][$attributeCode]));
             if ($customerId = Mage::getSingleton('customer/session')->getCustomer()->getId()) {
                 $mainAlias = false !== strpos($customerCollection->getSelect()->__toString(), 'AS `e') ? 'e' : 'main_table';
                 $customerCollection->getSelect()->where($mainAlias . '.entity_id != ?', $customerId);
             }
             if ($customerCollection->getSize() > 0) {
                 $result = array('error' => 1, 'message' => Mage::helper('amcustomerattr')->__('Please specify different value for "%s" attribute. Customer with such value already exists.', $attributeLabel));
                 return $result;
             }
         }
     }
     Mage::getSingleton('checkout/session')->setAmcustomerattr($data['amcustomerattr']);
     return parent::saveBilling($data, $customerAddressId);
 }
Ejemplo n.º 10
0
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['amcustomerattr'])) {
         // checking unique attributes
         $checkUnique = array();
         $nameGroupAttribute = '';
         $idGroupSelect = '';
         $collection = Mage::getModel('eav/entity_attribute')->getCollection();
         $alias = Mage::helper('amcustomerattr')->getProperAlias($collection->getSelect()->getPart('from'), 'eav_attribute');
         $collection->addFieldToFilter($alias . 'is_user_defined', 1);
         $collection->addFieldToFilter($alias . 'entity_type_id', Mage::getModel('eav/entity')->setType('customer')->getTypeId());
         foreach ($collection as $attribute) {
             if ($attribute->getIsUnique()) {
                 $translations = $attribute->getStoreLabels();
                 if (isset($translations[Mage::app()->getStore()->getId()])) {
                     $attributeLabel = $translations[Mage::app()->getStore()->getId()];
                 } else {
                     $attributeLabel = $attribute->getFrontend()->getLabel();
                 }
                 $checkUnique[$attribute->getAttributeCode()] = $attributeLabel;
             }
         }
         $collection = Mage::getModel('customer/attribute')->getCollection();
         $alias = Mage::helper('amcustomerattr')->getProperAlias($collection->getSelect()->getPart('from'), 'eav_attribute');
         $collection->addFieldToFilter($alias . 'is_user_defined', 1);
         $collection->addFieldToFilter($alias . 'entity_type_id', Mage::getModel('eav/entity')->setType('customer')->getTypeId());
         foreach ($collection as $attribute) {
             if ('selectgroup' == $attribute->getTypeInternal()) {
                 $nameGroupAttribute = $attribute->getAttributeCode();
             }
         }
         foreach ($data['amcustomerattr'] as $attributeCode => $attributeValue) {
             if ($attributeCode == $nameGroupAttribute) {
                 $idGroupSelect = $attributeValue;
             }
         }
         if ($idGroupSelect) {
             $option = Mage::getModel('eav/entity_attribute_option')->load($idGroupSelect);
             if ($option && $option->getGroupId()) {
                 $customer = Mage::getModel('customer/customer');
                 $customer->setGroupId($option->getGroupId());
             }
         }
         if ($checkUnique) {
             foreach ($checkUnique as $attributeCode => $attributeLabel) {
                 //skip empty values
                 if (!$data['amcustomerattr'][$attributeCode]) {
                     continue;
                 }
                 $customerCollection = Mage::getResourceModel('customer/customer_collection');
                 $customerCollection->addAttributeToFilter($attributeCode, array('eq' => $data['amcustomerattr'][$attributeCode]));
                 if ($customerId = Mage::getSingleton('customer/session')->getCustomer()->getId()) {
                     $mainAlias = false !== strpos($customerCollection->getSelect()->__toString(), 'AS `e') ? 'e' : 'main_table';
                     $customerCollection->getSelect()->where($mainAlias . '.entity_id != ?', $customerId);
                 }
                 if ($customerCollection->getSize() > 0) {
                     $result = array('error' => 1, 'message' => Mage::helper('amcustomerattr')->__('Please specify different value for "%s" attribute. Customer with such value already exists.', $attributeLabel));
                     return $result;
                 }
             }
         }
         Mage::getSingleton('checkout/session')->setAmcustomerattr($data['amcustomerattr']);
     }
     return parent::saveBilling($data, $customerAddressId);
 }