예제 #1
0
 protected function _beforeRender()
 {
     $visitor = Axis::model('log/visitor')->getVisitor();
     // select all viewed products by current visitor
     $selectInner = Axis::model('log/event')->select(array('id', 'object_id'))->order('le.id DESC');
     $customerId = $visitor->customer_id;
     if ($customerId && $customerId === Axis::getCustomerId()) {
         $selectInner->join('log_visitor', 'le.visitor_id = lv.id')->where('lv.customer_id = ?', $customerId);
     } else {
         $selectInner->where('visitor_id = ?', $visitor->id);
     }
     // filter unique product_ids from correctly ordered query
     // using adapter for specific from statement
     // this subquery is used to get the correct order for products
     // bigfix for not displayed product if the user viewed it some time ago and now opened it again
     // with single query this product will not outputted first in a row
     $adapter = Axis::model('log/event')->getAdapter();
     $select = $adapter->select()->from(array('le' => $selectInner), 'object_id')->group('le.object_id')->order('le.id DESC')->limit($this->getProductsCount());
     $productIds = $adapter->fetchCol($select);
     if (empty($productIds)) {
         return false;
     }
     $products = Axis::model('catalog/product')->select('*')->addFilterByAvailability()->addCommonFields()->addFinalPrice()->joinCategory()->where('cc.site_id = ?', Axis::getSiteId())->where('cp.id IN (?)', $productIds)->fetchProducts($productIds);
     if (empty($products)) {
         return false;
     }
     $this->products = $products;
     return $this->hasProducts();
 }
예제 #2
0
 public function init()
 {
     $product = $this->getAttrib('productId');
     $this->removeAttrib('productId');
     $this->addElement('hidden', 'product', array('value' => $product));
     // ratings
     $ratings = array();
     if (!Axis::single('community/review_mark')->isCustomerVoted(Axis::getCustomerId(), $product)) {
         $marks = array('0.5' => 0.5, '1' => 1, '1.5' => 1.5, 2 => 2, '2.5' => 2.5, '3' => 3, '3.5' => 3.5, '4' => 4, '4.5' => 4.5, '5' => 5);
         //@todo make configurable
         foreach (Axis::single('community/review_rating')->getList() as $rating) {
             $this->addElement('select', 'rating_' . $rating['id'], array('required' => true, 'id' => $rating['name'], 'label' => $rating['title'], 'class' => 'required review-rating'));
             $this->getElement('rating_' . $rating['id'])->addMultiOptions($marks)->addDecorator('Label', array('tag' => '', 'class' => 'rating-title', 'placement' => 'prepend', 'separator' => ''))->setDisableTranslator(true);
             $ratings[] = 'rating_' . $rating['id'];
         }
     }
     $this->addElement('text', 'author', array('required' => true, 'label' => 'Nickname', 'value' => Axis::single('community/common')->getNickname(), 'class' => 'input-text required', 'description' => 'Your nickname. All users will be able to see it', 'validators' => array(new Axis_Community_Validate_Nickname())));
     $this->addElement('text', 'title', array('required' => true, 'label' => 'One-line summary', 'class' => 'input-text required', 'description' => 'Summarize your review in one line. up to 55 characters', 'minlength' => '10', 'maxlength' => '55', 'validators' => array(new Zend_Validate_StringLength(10, 55, 'utf-8'))));
     $this->addElement('textarea', 'pros', array('required' => true, 'label' => Axis::translate('community')->__('Pros'), 'class' => 'input-text required', 'description' => 'Tell us what you like about this product. up to 250 characters', 'rows' => '2', 'cols' => '50', 'minlength' => '10', 'maxlength' => '250', 'validators' => array(new Zend_Validate_StringLength(10, 250, 'utf-8'))));
     $this->addElement('textarea', 'cons', array('required' => true, 'label' => 'Cons', 'class' => 'input-text required', 'description' => "Tell us what you don't like about this product. up to 250 characters", 'rows' => '2', 'cols' => '50', 'minlength' => '10', 'maxlength' => '250', 'validators' => array(new Zend_Validate_StringLength(10, 250, 'utf-8'))));
     $this->addElement('textarea', 'summary', array('label' => 'Summary', 'class' => 'input-text', 'description' => "Explain to us in detail why you like or dislike the product, focusing your comments on the product's features and functionality, and your experience using the product. This field is optional.", 'rows' => '3', 'cols' => '50', 'minlength' => '10', 'validators' => array(new Zend_Validate_StringLength(10, null, 'utf-8'))));
     $this->addDisplayGroup($this->getElements(), 'review');
     if (Axis::single('community/review')->canAdd()) {
         $this->addElement('button', 'submit', array('type' => 'submit', 'class' => 'button', 'label' => 'Add Review'));
         $this->addActionBar(array('submit'));
     }
 }
예제 #3
0
 public function init()
 {
     $configOptions = Axis::config('account/address_form')->toArray();
     $this->_fieldConfig = array_merge(array('firstname_sort_order' => -20, 'firstname_status' => 'required', 'lastname_sort_order' => -19, 'lastname_status' => 'required'), $configOptions);
     $form = $this;
     if ($subform = $this->getAttrib('subform')) {
         $form = new Axis_Form();
         // makes possible to use brackets in field names
         $form->setIsArray(true);
         $form->removeDecorator('Form');
         $this->addSubForm($form, $subform);
     }
     $countries = Axis_Collect_Country::collect();
     if (isset($countries['0']) && 'ALL WORLD COUNTRY' === $countries['0']) {
         unset($countries['0']);
     }
     $allowedCountries = $configOptions['country_id_allow'];
     if (!in_array(0, $allowedCountries)) {
         // ALL WORLD COUNTRIES is not selected
         $countries = array_intersect_key($countries, array_flip($allowedCountries));
     }
     $countryIds = array_keys($countries);
     $defaultCountry = current($countryIds);
     $zones = Axis_Collect_Zone::collect();
     $this->_zones = $zones;
     if ('billing_address' == $subform && !($customerId = Axis::getCustomerId())) {
         $form->addElement('text', 'email', array('required' => true, 'label' => 'Email', 'class' => 'input-text required email', 'validators' => array('EmailAddress')));
     }
     foreach ($this->_fields as $name => $values) {
         $status = $this->_fieldConfig[$name . '_status'];
         if ('disabled' == $status) {
             continue;
         }
         $fieldOptions = array('required' => 'required' === $status, 'label' => $values['label'], 'class' => $values['class'] . ('required' === $status ? ' required' : ''));
         if (isset($this->_fieldConfig[$name . '_sort_order'])) {
             $fieldOptions['order'] = $this->_fieldConfig[$name . '_sort_order'];
         }
         if ('country_id' == $name) {
             $fieldOptions['validators'] = array(new Zend_Validate_InArray(array_keys($countries)));
             $values['type'] = new Zend_Form_Element_Select($name, $fieldOptions);
             $values['type']->removeDecorator('HtmlTag')->addDecorator('HtmlTag', array('tag' => 'li', 'id' => "{$subform}-{$name}-row", 'class' => 'element-row'));
             $values['type']->options = $countries;
         } else {
             if ('zone_id' == $name) {
                 $values['type'] = new Zend_Form_Element_Select($name, $fieldOptions);
                 $values['type']->removeDecorator('HtmlTag')->addDecorator('HtmlTag', array('tag' => 'li', 'id' => "{$subform}-{$name}-row", 'class' => 'element-row'));
                 if (isset($zones[$defaultCountry]) && count($countries)) {
                     $values['type']->options = $zones[$defaultCountry];
                 }
                 // zone name field
                 $zoneNameOptions = $fieldOptions;
                 $zoneNameOptions['order']++;
                 $zoneNameOptions['class'] .= ' input-text';
                 $form->addElement('text', 'state', $zoneNameOptions);
             }
         }
         $form->addElement($values['type'], $name, $fieldOptions);
     }
     $form->addDisplayGroup($form->getElements(), $subform);
 }
예제 #4
0
 public function registerAction()
 {
     if (Axis::getCustomerId()) {
         $this->_redirect('account');
     }
     $this->setTitle(Axis::translate('account')->__('Create an Account'));
     $form = Axis::single('account/form_signup');
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($form->isValid($data)) {
             $model = Axis::single('account/customer');
             $data['site_id'] = Axis::getSiteId();
             $data['is_active'] = 1;
             list($row, $password) = $model->create($data);
             $row->setDetails($data);
             Axis::dispatch('account_customer_register_success', array('customer' => $row, 'password' => $password));
             $model->login($data['email'], $password);
             return $this->_redirect('account');
         } else {
             $form->populate($data);
         }
     }
     $this->view->formSignup = $form;
     $this->render();
 }
예제 #5
0
 /**
  *
  * @param string $nickname
  * @return bool
  */
 public function isExistNickname($nickname)
 {
     $select = $this->select('id')->join('account_customer_field', 'acf.id = acd.customer_field_id')->where('acf.name = ?', 'nickname')->where('acd.data = ?', $nickname);
     if ($customerId = Axis::getCustomerId()) {
         $select->where('acd.customer_id <> ?', $customerId);
     }
     return (bool) $select->fetchOne();
 }
예제 #6
0
 protected function _beforeRender()
 {
     if ($this->identity = Axis::getCustomerId()) {
         Axis::dispatch('account_box_navigation_prepare', $this);
         ksort($this->_items);
         $this->items = $this->_items;
     }
 }
예제 #7
0
 protected function _beforeRender()
 {
     $orders = Axis::model('sales/order')->getOrdersByCustomer(Axis::getCustomerId());
     if (!count($orders)) {
         return false;
     }
     $this->orders = $orders;
 }
예제 #8
0
 public function init()
 {
     if ($this->identity = Axis::getCustomerId()) {
         Axis::dispatch('account_box_navigation_prepare', $this);
         ksort($this->_items);
         $this->items = $this->_items;
     }
     return true;
 }
예제 #9
0
 public function init()
 {
     $orders = Axis::single('sales/order')->getOrdersByCustomer(Axis::getCustomerId());
     if (!count($orders)) {
         return false;
     }
     $this->orders = $orders;
     return true;
 }
예제 #10
0
 public function removeAction()
 {
     $this->_helper->layout->disableLayout();
     $productId = $this->_getParam('id');
     $customerId = Axis::getCustomerId();
     Axis::single('account/wishlist')->delete(array($this->db->quoteInto('id = ?', $productId), $this->db->quoteInto('customer_id = ?', $customerId)));
     Axis::dispatch('account_whishlist_remove_product_success', array('customer_id' => $customerId, 'product_id' => $productId));
     $this->_redirect('/account/wishlist');
 }
예제 #11
0
 /**
  * Return visitor row
  *
  * @return Zend_Db_Table_Row_Abstract
  */
 public function getVisitor()
 {
     if (!isset(Axis::session()->visitorId) || !($row = $this->find(Axis::session()->visitorId)->current())) {
         $row = $this->createRow(array('session_id' => Zend_Session::getId(), 'customer_id' => Axis::getCustomerId() ? Axis::getCustomerId() : new Zend_Db_Expr('NULL')));
         $row->save();
         Axis::session()->visitorId = $row->id;
         //unset only on logout
     }
     return $row;
 }
예제 #12
0
파일: Log.php 프로젝트: baisoo/axiscommerce
 /**
  * @param array $data
  * @return mixed
  */
 public function logging(array $data = array())
 {
     $pdata = array('num_results' => $data['num_results'], 'created_at' => Axis_Date::now()->toSQLString(), 'visitor_id' => Axis::single('log/visitor')->getVisitor()->id, 'customer_id' => Axis::getCustomerId(), 'site_id' => Axis::getSiteId());
     $query = Axis::single('search/log_query')->getQuery($data['query']);
     $query->hit++;
     $query->save();
     $pdata['query_id'] = $query->id;
     /* @todo analize search query */
     return parent::insert($pdata);
 }
예제 #13
0
 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'));
 }
예제 #14
0
 protected function _beforeRender()
 {
     if (!($customerId = Axis::getCustomerId())) {
         return false;
     }
     $result = Axis::single('account/wishlist')->findByCustomerId($customerId);
     if (!$result) {
         return false;
     }
     $this->wishlist = $result;
 }
예제 #15
0
 public function isValid($addressId)
 {
     $row = Axis::single('account/customer_address')->find($addressId)->current();
     if (!$row instanceof Axis_Db_Table_Row) {
         return true;
     }
     if ($row->customer_id == Axis::getCustomerId()) {
         return true;
     }
     $this->_messages[] = Axis::translate('account')->__('Invalid address data. Try again.');
     return false;
 }
예제 #16
0
 public function init()
 {
     if (!($customerId = Axis::getCustomerId())) {
         return false;
     }
     $result = Axis::single('account/wishlist')->findByCustomerId($customerId);
     if (!$result) {
         return false;
     }
     $this->wishlist = $result;
     return true;
 }
예제 #17
0
 /**
  *
  * @param array $comments
  * @return bool
  */
 public function updateComments($comments)
 {
     $rowset = $this->find(array_keys($comments));
     foreach ($rowset as $row) {
         if ($row->customer_id != Axis::getCustomerId()) {
             continue;
         }
         $row->wish_comment = $comments[$row->id];
         $row->save();
     }
     return true;
 }
예제 #18
0
 public function indexAction()
 {
     $this->_validateCart();
     $title = Axis::translate('checkout')->__('Checkout Process');
     $this->setTitle($title, $title, false);
     $checkout = $this->_getCheckout()->applyDefaults();
     $formBillingAddress = $checkout->getAddressForm('billing');
     if (!Axis::getCustomerId()) {
         $formBillingAddress->addRegistrationFields();
     }
     $this->view->checkout = array('form_billing_address' => $formBillingAddress, 'form_delivery_address' => $checkout->getAddressForm('delivery'), 'address_list' => Axis::model('account/customer_address')->getSortListByCustomerId(), 'delivery_address' => $checkout->getDelivery(), 'billing_address' => $checkout->getBilling(), 'shipping_methods' => Axis_Shipping::getAllowedMethods($checkout->getShippingRequest()), 'payment_methods' => Axis_Payment::getAllowedMethods($checkout->getPaymentRequest()), 'products' => $checkout->getCart()->getProducts(), 'totals' => $checkout->getTotal()->getCollects(), 'total' => $checkout->getTotal()->getTotal());
     $this->_helper->layout->setLayout('layout_1column');
     $this->render();
 }
예제 #19
0
 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();
 }
예제 #20
0
 public function showProductsAction()
 {
     $integer = new Zend_Filter_Int();
     $tagIds = array();
     $productIds = array();
     $tagItems = array();
     $tagName = '';
     if ($this->_hasParam('tag')) {
         $tagName = $this->_getParam('tag');
         foreach (Axis::single('tag/customer')->findByTag($tagName) as $tag) {
             $tagIds[] = $tag['id'];
         }
         $this->setCanonicalUrl($this->view->url(array('tag' => $tagName), 'tag_products'));
         $this->view->showRemove = false;
     } else {
         $tagId = $integer->filter($this->_getParam('tagId', 0));
         if (!$tagId) {
             $this->_redirect('/tag');
             return;
         }
         $tagIds[] = $tagId;
         $this->view->showRemove = (bool) Axis::getCustomerId();
         if (!($row = Axis::single('tag/customer')->find($tagId)->current())) {
             return $this->_forward('not-found', 'Error', 'Axis_Core');
         }
         $tagName = $row->name;
     }
     $this->setTitle(Axis::translate('tag')->__("Products associated with tag '%s'", $tagName));
     foreach ($tagIds as $tagId) {
         $rowset = Axis::single('tag/customer')->findProductsByTagId($tagId);
         $items = array();
         foreach ($rowset->toArray() as $item) {
             $productIds[] = $item['product_id'];
             $items[$item['product_id']] = $item;
         }
         $tagItems = $items + $tagItems;
     }
     $this->view->tagItems = $tagItems;
     if (count($productIds)) {
         $products = Axis::single('catalog/product')->select('*')->addCommonFields()->addFinalPrice()->where('cp.id IN (?)', $productIds)->fetchProducts($productIds);
         $this->view->products = $products;
     }
     $this->render();
 }
예제 #21
0
 /**
  *
  * @param int $customerId
  * @return array of Axis_Address object
  */
 public function getSortListByCustomerId($customerId = null)
 {
     if (null === $customerId) {
         $customerId = Axis::getCustomerId();
     }
     if (null === $customerId) {
         return array();
     }
     $addressList = $this->select()->from('account_customer_address')->where('customer_id = ?', $customerId)->addCountry()->addZone()->fetchAll();
     foreach ($addressList as &$address) {
         foreach ($address as $key => $value) {
             list($prefix, ) = explode('_', $key, 2);
             if ($key === $prefix || !in_array($prefix, array('country', 'zone'))) {
                 continue;
             }
             $address[$prefix][str_replace($prefix . '_', '', $key)] = $value;
             unset($address[$key]);
         }
     }
     $defaultBillingId = false;
     $defaultShippingId = false;
     if ($customer = Axis::single('account/customer')->find($customerId)->current()) {
         $defaultBillingId = $customer->default_billing_address_id;
         $defaultShippingId = $customer->default_shipping_address_id;
     }
     $j = 0;
     for ($i = 0, $n = count($addressList); $i < $n; $i++) {
         if ($addressList[$i]['id'] != $defaultBillingId && $addressList[$i]['id'] != $defaultShippingId) {
             continue;
         }
         if ($addressList[$i]['id'] == $defaultShippingId) {
             $addressList[$i]['default_shipping'] = 1;
         }
         if ($addressList[$i]['id'] == $defaultBillingId) {
             $addressList[$i]['default_billing'] = 1;
         }
         list($addressList[$i], $addressList[$j]) = array($addressList[$j], $addressList[$i]);
         ++$j;
     }
     foreach ($addressList as &$address) {
         $address = new Axis_Address($address);
     }
     return $addressList;
 }
예제 #22
0
 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);
 }
예제 #23
0
 protected function _beforeRender()
 {
     $visitor = Axis::model('log/visitor')->getVisitor();
     $select = Axis::model('log/event')->select('object_id')->distinct()->limit($this->getProductsCount())->order('le.id DESC');
     $customerId = $visitor->customer_id;
     if ($customerId && $customerId === Axis::getCustomerId()) {
         $select->join('log_visitor', 'le.visitor_id = lv.id')->where('lv.customer_id = ?', $customerId);
     } else {
         $select->where('visitor_id = ?', $visitor->id);
     }
     $productIds = $select->fetchCol();
     if (empty($productIds)) {
         return false;
     }
     $products = Axis::model('catalog/product')->select('*')->addFilterByAvailability()->addCommonFields()->addFinalPrice()->joinCategory()->where('cc.site_id = ?', Axis::getSiteId())->where('cp.id IN (?)', $productIds)->fetchProducts($productIds);
     if (empty($products)) {
         return false;
     }
     $this->products = $products;
     return $this->hasProducts();
 }
예제 #24
0
 public function addAction()
 {
     $this->_helper->layout->disableLayout();
     $productId = $this->_getParam('productId', 0);
     $quantity = $this->_getParam('quantity', false);
     $modifierOptions = $this->_getParam('modifier', array());
     $variationOptions = $this->_getParam('attribute', array());
     Axis::session()->lastUrl = $this->getRequest()->getServer('HTTP_REFERER');
     $result = Axis::single('checkout/cart')->add($productId, $modifierOptions, $variationOptions, $quantity);
     if ($this->_hasParam('clean-wishlist')) {
         Axis::single('account/wishlist')->delete(array($this->db->quoteInto('customer_id = ?', Axis::getCustomerId()), $this->db->quoteInto('product_id = ?', $productId)));
     }
     if ($result) {
         $location = Axis::config('checkout/cart/redirect');
         if ('referer' == $location) {
             $location = $this->getRequest()->getServer('HTTP_REFERER');
         }
         return $this->_redirect($location);
     }
     $keyword = Axis::single('catalog/hurl')->getProductUrl($productId);
     $this->_redirect('/' . $this->view->catalogUrl . '/' . $keyword);
 }
예제 #25
0
 public function preDispatch()
 {
     $request = $this->getRequest();
     if (Axis_Area::isFrontend()) {
         if (!Axis::getCustomerId() && $this->getActionController() instanceof Axis_Account_Controller_Abstract) {
             $request->setModuleName('Axis_Account')->setControllerName('auth')->setActionName('index')->setDispatched(false);
         }
         return;
     }
     if (!Axis_Area::isBackend()) {
         return;
     }
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('admin'));
     if (in_array($request->getControllerName(), array('auth', 'forgot')) && 'Axis_Admin' === $request->getModuleName()) {
         return;
     }
     if (!$auth->hasIdentity()) {
         if ($request->isXmlHttpRequest()) {
             Axis::message()->addError(Axis::translate('admin')->__('Your session has been expired. Please relogin'));
             $jsonHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
             $jsonHelper->sendFailure();
             return;
         }
         $request->setModuleName('Axis_Admin')->setControllerName('auth')->setActionName('index')->setDispatched(false);
         return;
     }
     $user = Axis::single('admin/user')->find($auth->getIdentity())->current();
     if (!$user) {
         $request->setModuleName('Axis_Admin')->setControllerName('auth')->setActionName('logout')->setDispatched(false);
         return;
     }
     $acl = new Zend_Acl();
     // add resources
     $resources = Axis::model('admin/acl_resource')->toFlatTree();
     foreach ($resources as $resource) {
         $parent = $resource['parent'];
         try {
             $acl->addResource($resource['id'], $parent);
         } catch (Zend_Acl_Exception $e) {
             Axis::message()->addError($e->getMessage());
         }
     }
     //add role(s)
     $role = (string) $user->role_id;
     $acl->addRole($role);
     //add permission
     $rowset = Axis::single('admin/acl_rule')->select('*')->where('role_id = ?', $role)->fetchRowset();
     foreach ($rowset as $row) {
         if (!$acl->has($row->resource_id)) {
             // $row->delete(); // remove invalid rule
             continue;
         }
         $action = 'deny';
         if ('allow' === $row->permission) {
             $action = 'allow';
         }
         try {
             $acl->{$action}($row->role_id, $row->resource_id);
         } catch (Zend_Acl_Exception $e) {
             Axis::message()->addError($e->getMessage());
         }
     }
     Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);
     Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole($role);
     if (in_array($request->getControllerName(), array('error')) && 'Axis_Admin' === $request->getModuleName()) {
         return;
     }
     //get current resource by request
     $request = $this->getRequest();
     $inflector = new Zend_Filter_Inflector();
     $resource = $inflector->addRules(array(':module' => array('Word_CamelCaseToDash', new Zend_Filter_Word_UnderscoreToSeparator('/'), 'StringToLower'), ':controller' => array('Word_CamelCaseToDash', 'StringToLower', new Zend_Filter_PregReplace('/admin_/', '')), ':action' => array('Word_CamelCaseToDash', 'StringToLower')))->setTarget('admin/:module/:controller/:action')->filter($request->getParams());
     if (!$acl->has($resource) || $acl->isAllowed($role, $resource)) {
         return;
     }
     if ($request->isXmlHttpRequest()) {
         Axis::message()->addError(Axis::translate('admin')->__('You have no permission for this operation'));
         $jsonHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
         $jsonHelper->sendFailure();
         return;
     }
     $request->setModuleName('Axis_Admin')->setControllerName('error')->setActionName('access-denied')->setDispatched(false);
 }
예제 #26
0
 /**
  * Remove tag item for current user
  * @return void
  */
 public function removeItemAction()
 {
     $model = Axis::single('tag/product');
     $integer = new Zend_Filter_Int();
     $id = $integer->filter($this->_getParam('itemId'));
     $row = $model->find($id)->current();
     if (!$row) {
         return $this->_redirect('account/tag');
     }
     $rowCustomer = $row->findParentRow('Axis_Tag_Model_Customer');
     if ($rowCustomer->customer_id != Axis::getCustomerId() || $rowCustomer->site_id != Axis::getSiteId()) {
         return $this->_redirect('account/tag');
     }
     $row->delete();
     if (!$model->weightTag($rowCustomer->id)) {
         $rowCustomer->delete();
         return $this->_redirect('account/tag');
     }
     $this->_redirect('tag/index/show-products/tagId/' . $rowCustomer->id);
 }
예제 #27
0
 /**
  * Merge shopping carts
  *
  * @return bool
  */
 public function merge()
 {
     if (!($customerId = Axis::getCustomerId())) {
         return false;
     }
     $adapter = $this->getAdapter();
     $previousCartRow = $this->select()->where('customer_id = ?', $customerId)->fetchRow();
     if ($previousCartRow && $previousCartRow->id != $this->getCartId()) {
         $previousCartProducts = Axis::model('checkout/cart_product')->select(array('*', 'checkout_cart_product_id' => 'id'))->joinLeft('checkout_cart_product_attribute', 'ccp.id = ccpa.shopping_cart_product_id', '*')->where('ccp.shopping_cart_id = ?', $previousCartRow->id)->fetchAll();
         $result = array();
         foreach ($previousCartProducts as $p) {
             if (!isset($result[$p['checkout_cart_product_id']])) {
                 $result[$p['checkout_cart_product_id']] = array('product_id' => $p['product_id'], 'quantity' => $p['quantity']);
             }
             $productAttributeId = $p['product_attribute_id'];
             if (!empty($productAttributeId)) {
                 $result[$p['checkout_cart_product_id']]['attributes'][$productAttributeId] = $p['product_attribute_value'];
             }
         }
         $removedShoppingProductIds = array();
         foreach ($result as $shopppingCartProductId => $product) {
             $attributes = isset($product['attributes']) ? $product['attributes'] : array();
             $clon = $this->_getClon($product['product_id'], $attributes);
             if (!$clon) {
                 continue;
             }
             $this->updateItem($clon['id'], $clon['quantity'] + $product['quantity']);
             $removedShoppingProductIds[] = $shopppingCartProductId;
         }
         if (count($removedShoppingProductIds)) {
             Axis::single('checkout/cart_product')->delete($adapter->quoteInto('id IN (?)', $removedShoppingProductIds));
         }
         Axis::single('checkout/cart_product')->update(array('shopping_cart_id' => $this->getCartId()), $adapter->quoteInto('shopping_cart_id = ?', $previousCartRow->id));
         $this->delete($adapter->quoteInto('customer_id = ?', $customerId));
     }
     $this->update(array('customer_id' => $customerId), $adapter->quoteInto('id = ?', $this->getCartId()));
     return true;
 }
예제 #28
0
 public function addAction()
 {
     $productId = $this->_getParam('product');
     $form = Axis::model('community/form_review', array('productId' => $productId));
     if (!($product = Axis::single('catalog/product')->find($productId)->current())) {
         $productName = Axis::translate('catalog')->__('Product not found');
     } else {
         $description = $product->getDescription();
         $productName = $description['name'];
         $this->view->productId = $product->id;
         $this->view->hurl = $product->getHumanUrl();
     }
     $title = Axis::translate('community')->__('Add review for the %s', $productName);
     $this->setTitle($title, false, $productName);
     $this->view->meta()->setTitle($title)->setKeywords($productName)->setDescription();
     if ($this->_request->isPost()) {
         $ratings = $this->_getRatings();
         $data = array('customer_id' => Axis::getCustomerId(), 'product_id' => $this->_getParam('product'), 'summary' => $this->_getParam('summary'), 'author' => $this->_getParam('author'), 'title' => $this->_getParam('title'), 'pros' => $this->_getParam('pros'), 'cons' => $this->_getParam('cons'), 'ratings' => $ratings);
         if ($form->isValid($this->_request->getPost())) {
             $review = Axis::single('community/review')->save($data);
             if ('approved' !== $review->status) {
                 Axis::message()->addSuccess(Axis::translate('community')->__('Review has been accepted for moderation'));
             }
             Axis::message()->addSuccess(Axis::translate('community')->__('Review was successfully saved'));
             $review->setRating($ratings);
             Axis::dispatch('community_review_add_success', $data);
             $this->_redirect($this->getRequest()->getServer('HTTP_REFERER'));
         } else {
             $form->populate($data);
         }
     }
     $this->view->formReview = $form;
     $this->render();
 }
예제 #29
0
 /**
  * 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));
     }
 }
예제 #30
0
 public function printAction()
 {
     if ($this->_hasParam('orderId')) {
         $orderId = $this->_getParam('orderId');
     } else {
         $this->_redirect('/account/order');
     }
     $order = Axis::single('sales/order')->fetchAll(array($this->db->quoteInto('customer_id = ?', Axis::getCustomerId()), $this->db->quoteInto('site_id = ?', Axis::getSiteId()), $this->db->quoteInto('id = ?', intval($orderId))));
     if (!sizeof($order)) {
         $this->_redirect('/account/order');
     }
     $order = $order->current();
     $this->view->order = $order->toArray();
     $this->view->order['products'] = $order->getProducts();
     $this->view->order['totals'] = $order->getTotals();
     $this->view->order['billing'] = $order->getBilling();
     $this->view->order['delivery'] = $order->getDelivery();
     $this->_helper->layout->setLayout('layout_print');
     $this->render();
 }