public function indexAction() { $title = Axis::translate('account')->__('My Account'); $this->setTitle($title, $title, false); $customer = Axis::getCustomer(); $this->view->customerName = $customer->firstname . ' ' . $customer->lastname; $this->view->customerEmail = $customer->email; $this->render(); }
public function getNickname() { if (!($customer = Axis::getCustomer())) { return 'Guest'; } $nickname = $customer->getExtraField('nickname'); if (!$nickname) { $nickname = $customer->firstname; } if (!$nickname) { $nickname = 'Community member'; } return $nickname; }
public function getNickname() { if (!($customer = Axis::getCustomer())) { return Axis::translate('community')->__('Guest'); } $nickname = $customer->getExtraField('nickname'); if (!$nickname) { $nickname = $customer->firstname; } if (!$nickname) { $nickname = Axis::translate('community')->__('Community member'); } return $nickname; }
public function changeAction() { $this->setTitle(Axis::translate('account')->__('Change Info')); $form = Axis::single('account/Form_ChangeInfo'); if ($this->_request->isPost()) { $data = $this->_request->getPost(); if ($data['change_password_toggle'] == 0) { $form->getElement('password_current')->clearValidators(); // removeValidator('NotEmpty'); $form->getElement('password')->clearValidators(); //removeValidator('NotEmpty'); $form->getElement('password_confirm')->clearValidators(); //removeValidator('NotEmpty'); } if ($form->isValid($data)) { $model = Axis::single('account/customer'); $row = $model->find(Axis::getCustomerId())->current(); if (empty($data['password'])) { unset($data['password']); } else { $data['password'] = md5($data['password']); } $row->setFromArray($data); $row->modified_at = Axis_Date::now()->toSQLString(); $row->save(); $row->setDetails($data); Axis::message()->addSuccess(Axis::translate('Axis_Core')->__('Data was saved successfully')); } } else { $data = array(); $customer = Axis::getCustomer(); $extraInfo = $customer->findDependentRowset('Axis_Account_Model_Customer_Detail'); $data = $customer->toArray(); foreach ($extraInfo as $row) { $value = empty($row->data) ? $row->customer_valueset_value_id : $row->data; $isMulti = isset($data['field_' . $row->customer_field_id]); if ($isMulti && is_array($data['field_' . $row->customer_field_id])) { $data['field_' . $row->customer_field_id][] = $value; } elseif ($isMulti) { $data['field_' . $row->customer_field_id] = array($data['field_' . $row->customer_field_id], $value); } else { $data['field_' . $row->customer_field_id] = $value; } } } $form->populate($data); $this->view->form = $form; $this->render(); }
protected function _beforeRender() { if (!($customerId = Axis::getCustomerId())) { return false; } $addressList = Axis::single('account/customer_address')->getSortListByCustomerId($customerId); if (!count($addressList)) { return false; } $customer = Axis::getCustomer(); $data = array(); foreach ($addressList as $address) { if ($address->id == $customer->default_shipping_address_id) { $data['delivery'] = $address; } if ($address->id == $customer->default_billing_address_id) { $data['billing'] = $address; } } $this->setFromArray($data); }
public function indexAction() { $this->setTitle(Axis::translate('contacts')->__('Contact Us')); $form = Axis::model('contacts/form_message'); if ($this->_request->isPost()) { $data = $this->_request->getPost(); if ($form->isValid($data)) { $custom = array(); foreach ($form->getElements() as $element) { $elementsToSkip = array('email', 'subject', 'department_id', 'message', 'submit'); if (in_array($element->getName(), $elementsToSkip)) { continue; } $custom[$element->getLabel()] = $element->getValue(); } $data['custom_info'] = Zend_Json::encode($custom); $data['site_id'] = Axis::getSiteId(); Axis::model('contacts/message')->save($data); $department = Axis::single('contacts/department')->find($data['department_id'])->current(); if ($department) { try { $mail = new Axis_Mail(); $mail->setLocale(Axis::config('locale/main/language_admin')); $mail->setConfig(array('event' => 'contact_us', 'subject' => $data['subject'], 'data' => $data, 'to' => $department->email, 'from' => array('name' => $data['name'], 'email' => $data['email']))); $mail->send(); } catch (Zend_Mail_Exception $e) { } } Axis::message()->addSuccess(Axis::translate('contacts')->__('Your message was successfully added')); $this->_redirect($this->_getBackUrl()); } else { $form->populate($data); } } elseif ($customer = Axis::getCustomer()) { $form->getElement('email')->setValue($customer->email); $form->getElement('name')->setValue($customer->firstname . ' ' . $customer->lastname); } $this->view->form = $form; $this->render(); }
public function init() { $page = $this->getAttrib('pageId'); $this->removeAttrib('pageId'); $customer = Axis::getCustomer(); if ($customer) { $name = $customer->firstname . ' ' . $customer->lastname; $email = $customer->email; $name = $name ? $name : ''; $email = $email ? $email : ''; } else { $name = 'Guest'; $email = ''; } $this->addElement('hidden', 'page', array('value' => $page)); $this->addElement('text', 'author', array('required' => true, 'label' => 'Name', 'value' => $name, 'class' => 'input-text required')); $this->addElement('text', 'email', array('required' => true, 'label' => 'Email address', 'value' => $email, 'class' => 'input-text required', 'validators' => array(new Zend_Validate_EmailAddress()))); $this->addElement('textarea', 'content', array('required' => true, 'label' => 'Comment', 'class' => 'input-text required', 'rows' => '7', 'cols' => '50')); $this->addDisplayGroup($this->getElements(), 'comment'); $this->addElement('button', 'submit', array('type' => 'submit', 'class' => 'button', 'label' => 'Save')); $this->addActionBar(array('submit')); }
/** * Register new customer, fill the customer_id in order * and save the customer addresses * * @param Axis_Sales_Model_Order_Row $order * @return void */ public function saveCustomerAfterPlaceOrder(Axis_Sales_Model_Order_Row $order) { $checkout = Axis::single('checkout/checkout'); $billing = $checkout->getBilling()->toFlatArray(); $delivery = $checkout->getDelivery()->toFlatArray(); $newCustomer = false; if (!empty($billing['register']) && !Axis::getCustomerId()) { $modelCustomer = Axis::model('account/customer'); $userData = $billing; $userData['site_id'] = Axis::getSiteId(); $userData['is_active'] = 1; unset($userData['id']); list($customer, $password) = $modelCustomer->create($userData); $customer->setDetails($userData); $modelCustomer->login($userData['email'], $password); $newCustomer = true; $order->customer_id = $customer->id; $order->save(); } // save address if needed if ($customer = Axis::getCustomer()) { if (empty($billing['id'])) { $customer->setAddress($billing); } if (empty($delivery['id']) && empty($billing['use_for_delivery'])) { $customer->setAddress($delivery); } } if ($newCustomer) { Axis::dispatch('account_customer_register_success', array('customer' => $customer, 'password' => $password)); } }
public function editAction() { $this->setTitle(Axis::translate('account')->__('Edit address')); $addressId = $this->_getParam('id'); $address = Axis::single('account/customer_address')->select()->where('id = ?', $addressId)->where('customer_id = ?', $this->_customerId)->fetchRow(); if (!$address instanceof Axis_Db_Table_Row) { Axis::message()->addError(Axis::translate('account')->__('Address not found')); if ($this->getRequest()->isXmlHttpRequest()) { return $this->_helper->json->sendFailure(); } $this->_redirect('account/address-book'); return; } if ($this->getRequest()->isXmlHttpRequest()) { return $this->_helper->json->sendSuccess(array('data' => $address->toArray())); } $form = Axis::model('account/form_address'); $customer = Axis::getCustomer(); $form->populate($address->toArray()); if ($customer->default_shipping_address_id == $addressId) { $form->getElement('default_shipping')->setOptions(array('value' => 1)); } if ($customer->default_billing_address_id == $addressId) { $form->getElement('default_billing')->setOptions(array('value' => 1)); } $this->view->form = $form; $this->render('form-address'); }
public function init() { $this->addElement('text', 'email', array('required' => true, 'label' => 'Email', 'class' => 'input-text required email', 'validators' => array('EmailAddress', new Axis_Validate_Exists(Axis::single('account/customer'), 'email', "id <> " . Axis::getCustomerId() . " AND site_id = " . Axis::getSiteId())))); $this->addElement('text', 'firstname', array('required' => true, 'label' => 'Firstname', 'class' => 'input-text required')); $this->addElement('text', 'lastname', array('required' => true, 'label' => 'Lastname', 'class' => 'input-text required')); $this->addDisplayGroup(array('email', 'firstname', 'lastname'), 'login', array('legend' => 'General information')); $rows = Axis::single('account/customer_field')->getFields(); $groupsFields = array(); foreach ($rows as $row) { $field = 'field_' . $row['id']; $config = array('id' => 'field_' . $row['name'], 'required' => (bool) $row['required'], 'label' => $row['field_label'], 'class' => in_array($row['field_type'], array('textarea', 'text')) ? 'input-text' : ''); if ($row['field_type'] == 'textarea') { $config['rows'] = 6; $config['cols'] = 60; } $this->addElement($row['field_type'], $field, $config); $el = $this->getElement($field); if ($row['required']) { $el->addValidator('NotEmpty')->setAttrib('class', $el->getAttrib('class') . ' required'); } if (!empty($row['validator'])) { if ($row['validator'] == 'Date') { $el->addValidator($row['validator'], false, array('format' => 'yyyy-MM-dd')); $el->setAttrib('class', $el->getAttrib('class') . ' input-date'); } else { $el->addValidator($row['validator']); } } if (!empty($row['axis_validator'])) { $el->addValidator(new $row['axis_validator']()); } if (isset($row['customer_valueset_id'])) { $values = Axis::single('account/Customer_ValueSet_Value')->getCustomValues($row['customer_valueset_id'], Axis_Locale::getLanguageId()); if (method_exists($el, 'setMultiOptions')) { $el->setMultiOptions($values); } } $groupsFields[$row['customer_field_group_id']][$row['id']] = $field; } /* add field groups */ if (count($groupsFields)) { $groups = Axis::single('account/customer_fieldGroup')->getCustomGroups(array_keys($groupsFields), Axis_Locale::getLanguageId()); foreach ($groups as $row) { $this->addDisplayGroup(array_values($groupsFields[$row['id']]), empty($row['name']) ? $row['id'] : $row['name'], array('legend' => $row['group_label'])); $this->getDisplayGroup(empty($row['name']) ? $row['id'] : $row['name'])->setDisableTranslator(true); } } $this->addElement('checkbox', 'change_password_toggle', array('label' => 'Change password', 'onchange' => "togglePasswordForm(this.checked)")); $this->addElement('password', 'password', array('disabled' => 'disabled', 'label' => 'New password', 'class' => 'input-text required password', 'validators' => array('NotEmpty', new Axis_Validate_PasswordConfirmation()))); $this->addElement('password', 'password_confirm', array('disabled' => 'disabled', 'label' => 'Confirm new password', 'class' => 'input-text required password')); $this->addElement('password', 'password_current', array('disabled' => 'disabled', 'label' => 'Current password', 'class' => 'input-text required password', 'validators' => array('NotEmpty', new Axis_Validate_PasswordEqual(Axis::getCustomer()->password)))); $this->addDisplayGroup(array('password_current', 'password', 'password_confirm'), 'change_password', array('legend' => 'Change password', 'style' => 'display: none;')); $this->addElement('button', 'submit', array('type' => 'submit', 'class' => 'button', 'label' => 'Save')); $this->addActionBar(array('submit')); }
/** * * @param int $customerId [optional] * @return int|null */ public function getGroupId($customerId = null) { $customerGroupId = null; if (!$customerId && ($row = Axis::getCustomer())) { $customerGroupId = $row->group_id; } else { if ($customerId && ($row = $this->find($customerId)->current())) { $customerGroupId = $row->group_id; //parent::getGroupId() } } if (null === $customerGroupId) { $customerGroupId = Axis_Account_Model_Customer_Group::GROUP_GUEST_ID; } return $customerGroupId; }
/** * Create order, and clears shopping cart after that * * @return Axis_Sales_Model_Order_Row * @throws Axis_Exception */ public function createFromCheckout() { /** * @var Axis_Checkout_Model_Checkout $checkout */ $checkout = Axis::single('checkout/checkout'); if (!$checkout->getCart()->validateContent()) { throw new Axis_Exception(); } $orderRow = $this->createRow(); $storage = $checkout->getStorage(); if ($customer = Axis::getCustomer()) { $orderRow->customer_id = $customer->id; $orderRow->customer_email = $customer->email; } else { $orderRow->customer_email = $checkout->getBilling()->email; } $orderRow->site_id = Axis::getSiteId(); $orderRow->payment_method = $checkout->payment()->getTitle(); $orderRow->payment_method_code = $checkout->payment()->getCode(); $orderRow->shipping_method = $checkout->shipping()->getTitle(); $orderRow->shipping_method_code = $checkout->shipping()->getCode(); $orderRow->date_purchased_on = Axis_Date::now()->toSQLString(); $orderRow->currency = Axis::single('locale/currency')->getCode(); $orderRow->currency_rate = Axis::single('locale/currency')->getData($orderRow->currency, 'rate'); $orderRow->order_total = $checkout->getTotal()->getTotal(); $orderRow->txn_id = 0; //@todo $orderRow->order_status_id = 0; $orderRow->ip_address = $_SERVER['REMOTE_ADDR']; $orderRow->customer_comment = $storage->customer_comment; $orderRow->locale = Axis_Locale::getLocale()->toString(); /* build delivery & billing arrays */ $addressFormatId = Axis::config('core/store/addressFormat'); $delivery = $checkout->getDelivery()->toArray(); $delivery['country'] = isset($delivery['country']['name']) ? $delivery['country']['name'] : ''; if (isset($delivery['zone']['name'])) { $delivery['state'] = $delivery['zone']['name']; } $delivery['address_format_id'] = $addressFormatId; $billing = $checkout->getBilling()->toArray(); $billing['country'] = isset($billing['country']['name']) ? $billing['country']['name'] : ''; if (isset($billing['zone']['name'])) { $billing['state'] = $billing['zone']['name']; } $billing['address_format_id'] = $addressFormatId; unset($billing['id'], $delivery['id']); foreach ($delivery as $key => $value) { $delivery['delivery_' . $key] = $value; } foreach ($billing as $key => $value) { $billing['billing_' . $key] = $value; } $orderRow->setFromArray($delivery); $orderRow->setFromArray($billing); /* Save order (auto generate number ) */ $orderRow->save(); /* Add products to order and change quantity */ $modelOrderProduct = Axis::single('sales/order_product'); foreach ($checkout->getCart()->getProducts() as $product) { $modelOrderProduct->add($product, $orderRow->id); } /* Add total info */ $total = $checkout->getTotal(); $orderTotal = Axis::single('sales/order_total'); foreach ($total->getCollects() as $collect) { $orderTotal->insert(array('order_id' => $orderRow->id, 'code' => $collect['code'], 'title' => $collect['title'], 'value' => $collect['total'])); } // update product stock $orderRow->setStatus('pending'); return $orderRow; }
/** * Create order action */ public function processAction() { $this->_helper->layout->disableLayout(); $checkout = $this->_getCheckout(); $billing = $this->_getParam('billing_address'); $delivery = $this->_getParam('delivery_address'); try { $checkout->setBillingAddress($billing); if (!$billing['use_for_delivery']) { $checkout->setDeliveryAddress($delivery); } $checkout->setShippingMethod($this->_getParam('shipping')); $checkout->setPaymentMethod($this->_getParam('payment')); $storage = $checkout->getStorage(); $storage->customer_comment = $this->_getParam('comment'); // place order $preProcess = (array) $checkout->payment()->preProcess(); $order = Axis::single('sales/order')->createFromCheckout(); $checkout->setOrderId($order->id); $postProcess = (array) $checkout->payment()->postProcess($order); // register customer if required $event = false; if (!empty($billing['register']) && !Axis::getCustomerId()) { $modelCustomer = Axis::model('account/customer'); $userData = $billing; $userData['site_id'] = Axis::getSiteId(); $userData['is_active'] = 1; list($customer, $password) = $modelCustomer->create($userData); $event = true; $customer->setDetails($userData); $order->customer_id = $customer->id; $order->save(); $modelCustomer->login($userData['email'], $password); } // save address if needed if ($customer = Axis::getCustomer()) { if (empty($billing['id'])) { $customer->setAddress($billing); } if (empty($delivery['id']) && !$billing['use_for_delivery']) { $customer->setAddress($delivery); } } if ($event) { Axis::dispatch('account_customer_register_success', array('customer' => $customer, 'password' => $password)); } $result = array_merge($preProcess, $postProcess); } catch (Exception $e) { Axis::dispatch('sales_order_create_failed', array('exception' => $e)); $message = $e->getMessage(); if (!empty($message)) { Axis::message()->addError($message); } return $this->_helper->json->sendFailure(); } if (empty($result['redirect'])) { $result['redirect'] = $this->view->href('checkout/success', true); } $this->_helper->json->sendJson(array('redirect' => $result['redirect'], 'success' => true), false, false); }
/** * Retrieve the default address data from checkout/address_form config * * @return array * <pre> * :id => 0, * :country_id => int * :zone_id => int * :postcode => string * :firstname => string * :lastname => string * </pre> */ public function getDefaultAddress() { $defaults = Axis::model('account/customer_address')->getDefaultValues(); $customer = Axis::getCustomer(); return array_merge($defaults, array('id' => 0, 'firstname' => $customer ? $customer->firstname : '', 'lastname' => $customer ? $customer->lastname : '')); }