/** * * @return type */ public function getAttributes() { $attributes = parent::getAttributes(); if (Mage::app()->getRequest()->getRouteName() == 'adminhtml') { if (Mage::app()->getRequest()->isPost()) { $data = Mage::app()->getRequest()->getParam('tabCustomerattribute'); $customerTypeValue = $data['select_customer_type']; $customerTypeText = Mage::helper('idpas400')->getAttributeOptionText($customerTypeValue); $attributes = Mage::helper('idpas400')->filterAttributesArray($attributes, $customerTypeText); } // Filter the attributes if this is a post on the front controller } elseif (Mage::app()->getRequest()->isPost()) { $customerTypeValue = Mage::app()->getRequest()->getParam('select_customer_type'); $customerTypeText = Mage::helper('idpas400')->getAttributeOptionText($customerTypeValue); $attributes = Mage::helper('idpas400')->filterAttributesArray($attributes, $customerTypeText); // if the user is logged in, then we're looking at their account page // } elseif (Mage::helper('customer')->isLoggedIn()) { // $_attr = array(); // foreach ($attributes as $code => $attribute) { // if ($code == 'select_customer_type') { // $attribute->setData('is_visible',0); // $attribute->setData('is_required',0); // continue; // } // $_attr[$code] = $attribute; // } // $attributes = $_attr; } return $attributes; }
protected function _isAttributeOmitted($attribute) { $res = parent::_isAttributeOmitted($attribute); if (!Mage::app()->getStore()->isAdmin() && $attribute->getIsUserDefined() && $attribute->getEntityTypeId() == Mage::getModel('eav/entity')->setType('customer')->getTypeId()) { // will skip all user-defined (created with the extension) attributes, to avoid errors on checkout for registered customer $res = true; } $storeAttribute = $attribute->getStoreIds(); if ($storeAttribute) { $customer = Mage::getModel('customer/customer'); $customerId = Mage::app()->getRequest()->getParam('id'); if ($customerId) { $customer->load($customerId); $storeId = $customer->getStoreId(); if (is_numeric($storeAttribute)) { if ($storeId != $storeAttribute) { $res = true; } } else { $res = true; $storeAttribute = explode(',', $storeAttribute); foreach ($storeAttribute as $attr) { if ($attr == $storeId) { $res = false; break; } } } } // else { // if required error when save customer in backend // $res = true; //} } return $res; }
protected function _isAttributeOmitted($attribute) { $res = parent::_isAttributeOmitted($attribute); if (!Mage::app()->getStore()->isAdmin() && $attribute->getIsUserDefined()) { // will skip all user-defined (created with the extension) attributes, to avoid errors on checkout for registered customer $res = true; } return $res; }
/** * Return Customer Form instance * * @return Mage_Customer_Model_Form */ public function getForm() { if (is_null($this->_form)) { $this->_form = Mage::getModel('customer/form')->setFormCode($this->_formCode)->setEntity($this->getEntity()); if ($this->_entityType) { $this->_form->setEntityType($this->_entityType); } $this->_form->initDefaultValues(); } return $this->_form; }
/** * Restore entity data from session * Entity and form code must be defined for the form * * @param Mage_Customer_Model_Form $form * @return Mage_Customer_Block_Form_Register */ public function restoreSessionData(Mage_Customer_Model_Form $form, $scope = null) { if ($this->getFormData()->getCustomerData()) { $request = $form->prepareRequest($this->getFormData()->getData()); $data = $form->extractData($request, $scope, false); $form->restoreData($data); } return $this; }
public function testGetAttributes() { $attributes = $this->_model->getAttributes(); $this->assertInternalType('array', $attributes); $this->assertNotEmpty($attributes); }
/** * Initialize attribute set * * @param Mage_Customer_Model_Form $customerFor * @return Mage_Eav_Model_Entity_Attribute[] */ protected function _initCustomerAttributes(Mage_Customer_Model_Form $customerForm) { $attributes = $customerForm->getAttributes(); foreach ($attributes as $attribute) { /* @var $attribute Mage_Eav_Model_Entity_Attribute */ $attributeLabel = Mage::helper('Mage_Customer_Helper_Data')->__($attribute->getFrontend()->getLabel()); $attribute->setFrontendLabel($attributeLabel); $attribute->unsIsVisible(); } return $attributes; }
/** * Validate Data * * @param array $data Data * @return array|bool * @throws Mage_Core_Exception */ public function validateData(array $data) { $errors = parent::validateData($data); // Prevent to change/save the username if it is not allowed on the frontend to change the username if (!Mage::getStoreConfigFlag('username/general/frontend') && !Mage::app()->getStore()->isAdmin()) { return $errors; } if (!empty($data['username'])) { $model = Mage::getModel('customer/customer'); $customerId = Mage::app()->getFrontController()->getRequest()->getParam('customer_id'); if (!$customerId) { $customerId = Mage::app()->getFrontController()->getRequest()->getParam('id'); } if (!$customerId && !Mage::app()->getStore()->isAdmin()) { $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId(); } // Prevent possible errors if (empty($customerId)) { return $errors; } if (isset($data['website_id']) && $data['website_id'] !== false) { $websiteId = $data['website_id']; } elseif ($customerId) { $customer = $model->load($customerId); $websiteId = $customer->getWebsiteId(); // don't make any test if the user has already a username if ($customer->getUsername() == $data['username']) { return $errors; } } else { $websiteId = Mage::app()->getWebsite()->getId(); } if (!is_array($errors)) { $errors = array(); } $isCheckoutAsGuest = Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod(); if ($isCheckoutAsGuest != Mage_Checkout_Model_Type_Onepage::METHOD_GUEST && empty($data['username'])) { $message = Mage::helper('username')->__('Username is a required field.'); $errors = array_merge($errors, array($message)); } // Other rules are validated by the parent class because they are basic rules provided by Magento Core $inputValidation = Mage::getStoreConfig('username/general/input_validation'); $useInputValidation = $inputValidation == 'default' || $inputValidation == 'custom' ? true : false; if ($useInputValidation) { $validate = '/^*$/'; switch ($inputValidation) { case 'default': $validate = '/^[\\w-]*$/'; break; case 'custom': $validate = Mage::getStoreConfig('username/general/input_validation_custom'); break; } $validate = new Zend_Validate_Regex($validate); if (!$validate->isValid($data['username'])) { if ($inputValidation == 'custom') { $message = Mage::getStoreConfig('username/general/input_validation_custom_message'); } else { $message = Mage::helper('username')->__('Username is invalid! Only letters, digits and \'_-\' values are accepted.'); } $errors = array_merge($errors, array($message)); } } $result = $model->customerUsernameExists($data['username'], $websiteId); if ($result && $result->getId() != $customerId) { $message = Mage::helper('username')->__('Username already exists'); $errors = array_merge($errors, array($message)); } } if (count($errors) == 0) { return true; } return $errors; }