public static function getCustomerDealerCostPercent() { if (null === self::$_customerCostPercent) { self::$_customerCostPercent = floatval(self::getCustomer()->getData(self::ATTR_DEALER_COST)); if (!self::$_customerCostPercent) { self::$_customerCostPercent = self::getCustomerGroupCostPercent(); } } return self::$_customerCostPercent; }
public function indexAction() { $session = Mage::getSingleton('customer/session'); if (!$session->authenticate($this, Mage::getUrl('*/*/login'))) { return; } if (!Vikont_Wholesale_Helper_Data::isActiveDealer()) { $this->getResponse()->setRedirect(Mage::getUrl('wholesale/dealer/corner')); return; } $this->loadLayout()->renderLayout(); }
protected function _authenticate() { $session = Mage::getSingleton('customer/session'); if (!$session->authenticate($this, Mage::getUrl('*/dealer/login'))) { return false; } if (!Vikont_Wholesale_Helper_Data::isActiveDealer()) { $this->getResponse()->setRedirect(Mage::getUrl('wholesale/dealer/corner')); return false; } return true; }
public function loginAction() { $session = Mage::getSingleton('customer/session'); if (!$session->isLoggedIn()) { if (!$session->getBeforeAuthUrl()) { $session->setBeforeAuthUrl(Mage::getUrl('*/*/corner')); } $this->loadLayout()->_initLayoutMessages('customer/session')->_initLayoutMessages('catalog/session')->renderLayout(); return; } if (Vikont_Wholesale_Helper_Data::isActiveDealer()) { $this->getResponse()->setRedirect(Mage::getUrl('wholesale')); return; } if (!Vikont_Wholesale_Helper_Data::isApplicationSent()) { $this->getResponse()->setRedirect(Mage::getUrl('wholesale/application')); return; } }
protected function prepareCustomerEmailData($customerId) { $customer = Mage::getModel('customer/customer')->load($customerId); $data = array(); $data['customer'] = $customer; $data['application'] = $customer->getData(Vikont_Wholesale_Helper_Data::ATTR_APPLICATION_DATA); $data['address'] = Mage::getModel('customer/address'); if ($data['application']) { $data['address']->load($data['application']->getData('address_id')); } else { $data['application'] = new Varien_Object(array('full_name' => $customer->getName(), 'date_sent' => Vikont_Wholesale_Helper_Data::getDateFormatted(time(), 'MMMM d, YYYY'))); if ($primaryBillingAddress = $customer->getPrimaryBillingAddress()) { $data['address'] = $primaryBillingAddress; } } $data['address_html'] = $data['address']->format('html'); $data['view_profile_url'] = Mage::getUrl('customer/account'); return $data; }
public function prepareCatalogProductCollectionPrices(Varien_Event_Observer $observer) { // @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection = $observer->getEvent()->getCollection(); $productIds = array(); $costPlus = (int) (100 * Vikont_Wholesale_Helper_Data::getCustomerDealerCostPercent()); foreach ($collection as $product) { $key = implode('|', array($costPlus, $product->getId())); if (!isset($this->_dealerPrices[$key])) { $productIds[] = $product->getId(); } } if ($productIds) { $dealerPrices = array(); foreach ($productIds as $productId) { $key = implode('|', array($costPlus, $productId)); $this->_dealerPrices[$key] = isset($dealerPrices[$productId]) ? $dealerPrices[$productId] : false; } } }
public function postApplicationAction() { if (!$this->_validateFormKey() || !$this->getRequest()->isPost()) { return $this->_redirect('*/*/'); } $data = $this->getRequest()->getPost(); Mage::helper('wholesale')->checkLogin(Mage::getUrl('*/*/index'), $data); $response = array('errorMessage' => '', 'errorMessages' => array(), 'messages' => array()); $session = Mage::getSingleton('customer/session'); $customer = $session->getCustomer(); $storeId = Mage::app()->getStore()->getId(); try { if ('exists' == $data['address_source']) { $address = $customer->getAddressById($data['address_id']); if (!$address->getId() || $address->getCustomerId() != $customer->getId()) { Mage::throwException('Invalid address ID'); } } else { $errors = array(); $address = Mage::getModel('customer/address'); $addressForm = Mage::getModel('customer/form')->setFormCode('customer_address_edit')->setEntity($address); $addressData = $addressForm->extractData($this->getRequest()); $addressErrors = $addressForm->validateData($addressData); if ($addressErrors !== true) { $errors = $addressErrors; } $addressForm->compactData($addressData); $address->setCustomerId($customer->getId())->setIsDefaultBilling(@$data['default_billing'])->setIsDefaultShipping(@$data['default_shipping']); $addressErrors = $address->validate(); if ($addressErrors !== true) { $errors = array_merge($errors, $addressErrors); } if (!count($errors)) { $address->save(); $data['address_id'] = $address->getId(); $response['messages'][] = $this->__('The address has been saved'); } else { $this->_getSession()->setAddressFormData($data); $response['errorMessages'] = array(); foreach ($errors as $errorMessage) { $response['errorMessages'][] = $errorMessage; } } } // cleaning the data by removing address fields from there foreach (array('firstname', 'lastname', 'company', 'telephone', 'fax', 'street', 'city', 'region_id', 'region', 'postcode', 'country_id', 'default_billing', 'default_shipping', 'form_key', 'i_confirm', 'address_source') as $fieldName) { unset($data[$fieldName]); } $contactEmail = isset($data['email']) && $data['email'] ? $data['email'] : $customer->getEmail(); $application = new Varien_Object($data); $application->setData('date_sent', Vikont_Wholesale_Helper_Data::getDateFormatted(time(), 'MMMM d, YYYY')); $authKey = md5(rand(10000, 10000000)); $application->setData('auth_key', $authKey); // $customerGroup = Mage::getModel('customer/group')->load($customer->getGroupId()); $customer->setData(Vikont_Wholesale_Helper_Data::ATTR_DEALER_STATUS, Vikont_Wholesale_Model_Source_Dealer_Status::CANDIDATE)->setData(Vikont_Wholesale_Helper_Data::ATTR_APPLICATION_DATA, $application)->save(); // sending a notification to admin $adminEmailTemplate = Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'adminhtml', 'store' => Mage_Core_Model_App::ADMIN_STORE_ID))->sendTransactional(Mage::getStoreConfig('wholesale/email/admin_notify_template'), Mage::getStoreConfig('wholesale/email/sender_email_identity'), Mage::getStoreConfig('wholesale/email/admin_notify_email'), $this->__('Dealer Application'), array('application' => $application, 'address' => $address, 'customer' => $customer, 'address_html' => $address->format('html'), 'approve_url' => Mage::getUrl('*/*/status', array('action' => Vikont_Wholesale_Model_Source_Dealer_Status::APPROVED, 'id' => $customer->getId(), 'key' => $authKey)), 'decline_url' => Mage::getUrl('*/*/status', array('action' => Vikont_Wholesale_Model_Source_Dealer_Status::DECLINED, 'id' => $customer->getId(), 'key' => $authKey))), $storeId); if (!$adminEmailTemplate->getSentSuccess()) { Mage::log($this->__('Error sending dealer application admin notification email, customer: %s', Mage::getStoreConfig('wholesale/email/admin_notify_email'))); } // sending a notification to customer $dealerEmailTemplate = Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->setReplyTo(Mage::getStoreConfig('wholesale/email/sender_email_identity'))->sendTransactional(Mage::getStoreConfig('wholesale/email/customer_notify_template'), Mage::getStoreConfig('wholesale/email/sender_email_identity'), $contactEmail, $customer->getName(), array('application' => $application, 'address' => $address, 'customer' => $customer, 'address_html' => $address->format('html')), $storeId); $dealerNotificationEmailSent = $dealerEmailTemplate->getSentSuccess(); if (!$dealerNotificationEmailSent) { Mage::log($this->__('Error sending dealer application confirmation email to %s', $customer->getName() . ' <' . $contactEmail . '>')); } // responding to AJAX request $response['html'] = $this->getLayout()->createBlock('core/template')->setTemplate('vk_wholesale/application/success.phtml')->setApplication($application)->setAddress($address)->setCustomer($customer)->setEmailSent($dealerNotificationEmailSent)->toHtml(); } catch (Exception $e) { Mage::logException($e); $response['errorMessage'] = $e->getMessage(); } $this->getResponse()->setBody(json_encode($response)); }
public function isCustomerWholesale() { return Vikont_Wholesale_Helper_Data::isActiveDealer(); }