示例#1
0
 public function saveAction()
 {
     $_row = $this->_getAllParams();
     $model = Axis::model('cms/page');
     $modelContent = Axis::model('cms/page_content');
     $modelCategory = Axis::model('cms/page_category');
     $row = $model->save($_row);
     //save page content
     foreach ($_row['content'] as $languageId => $values) {
         if (empty($values['link'])) {
             $values['link'] = $row->name;
         }
         $modelContent->getRow($row->id, $languageId)->setFromArray($values)->save();
     }
     //save category relation
     $modelCategory->delete(Axis::db()->quoteInto('cms_page_id = ?', $row->id));
     $categories = array_filter(Zend_Json::decode($_row['category']));
     foreach ($categories as $categoryId) {
         $modelCategory->createRow(array('cms_category_id' => $categoryId, 'cms_page_id' => $row->id))->save();
     }
     if (!isset($_row['id']) || $_row['id'] != $row->id) {
         Axis::dispatch('cms_page_add_success', array('page_id' => $row->id));
     } else {
         Axis::dispatch('cms_page_update_success', array('page_id' => $row->id));
     }
     Axis::message()->addSuccess(Axis::translate('cms')->__('Page was saved successfully'));
     return $this->_helper->json->setData(array('id' => $row->id))->sendSuccess();
 }
 /**
  * Customer add new tag on product
  * @return void
  */
 public function addAction()
 {
     $tags = array_filter(explode(',', $this->_getParam('tags')));
     $productId = $this->_getParam('productId');
     $modelCustomer = Axis::model('tag/customer');
     $modelProduct = Axis::model('tag/product');
     $defaultStatus = $modelCustomer->getDefaultStatus();
     $customerId = Axis::getCustomerId();
     $siteId = Axis::getSiteId();
     $_row = array('customer_id' => $customerId, 'site_id' => $siteId, 'status' => $modelCustomer->getDefaultStatus());
     foreach ($tags as $tag) {
         $row = $modelCustomer->select()->where('name = ?', $tag)->where('customer_id = ?', $customerId)->where('site_id = ?', $siteId)->fetchRow();
         if (!$row) {
             $_row['name'] = $tag;
             $row = $modelCustomer->createRow($_row);
             $row->save();
             Axis::message()->addSuccess(Axis::translate('tag')->__("Tag '%s' was successfully added to product", $tag));
         } else {
             Axis::message()->addNotice(Axis::translate('tag')->__("Your tag '%s' is already added to this product", $tag));
         }
         // add to product relation
         $isExist = (bool) $modelProduct->select('id')->where('customer_tag_id = ?', $row->id)->where('product_id = ?', $productId)->fetchOne();
         if (!$isExist) {
             $modelProduct->createRow(array('customer_tag_id' => $row->id, 'product_id' => $productId))->save();
         }
         Axis::dispatch('tag_product_add_success', array('tag' => $tag, 'product_id' => $productId));
     }
     $this->_redirect($this->getRequest()->getServer('HTTP_REFERER'));
 }
示例#3
0
 protected function _beforeRender()
 {
     $this->_items = array();
     // forward fix
     Axis::dispatch('admin_box_navigation_prepare', $this);
     $this->menu = new Zend_Navigation($this->_items);
 }
示例#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
 protected function _beforeRender()
 {
     if ($this->identity = Axis::getCustomerId()) {
         Axis::dispatch('account_box_navigation_prepare', $this);
         ksort($this->_items);
         $this->items = $this->_items;
     }
 }
示例#6
0
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     Axis::model('core/site')->delete($this->db->quoteInto('id IN(?)', $data));
     Axis::dispatch('core_site_delete_success', array('site_ids' => $data));
     Axis::message()->addSuccess(Axis::translate('admin')->__('Site was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
 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');
 }
示例#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
 /**
  * Constructor. Overriden to add events after form initialization
  *
  * Registers form view helper as decorator
  *
  * @param mixed $options
  * @return void
  */
 public function __construct($options = null)
 {
     $this->setDefaultDisplayGroupClass('Axis_Form_DisplayGroup');
     $this->addPrefixPath('Axis_Form_Decorator', 'Axis/Form/Decorator', 'decorator');
     $this->setTranslator(Axis::translate($this->_translatorModule)->getAdapter());
     parent::__construct($options);
     Axis::dispatch('form_construct_after', $this);
     // global event for all forms
     if ($this->_eventPrefix) {
         Axis::dispatch($this->_eventPrefix . '_construct_after', $this);
     }
 }
示例#10
0
 public function render()
 {
     if (!($navigationHtml = Axis::cache()->load($this->getCacheKey()))) {
         $this->_items = array();
         // forward fix
         Axis::dispatch('admin_box_navigation_prepare', $this);
         $this->menu = new Zend_Navigation($this->_items);
         $navigationHtml = parent::render();
         Axis::cache()->save($navigationHtml, $this->getCacheKey(), array('modules'));
     }
     return $navigationHtml;
 }
示例#11
0
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     if (!count($data)) {
         Axis::message()->addError(Axis::translate('locale')->__('No language found to delete'));
         return $this->_helper->json->sendFailure();
     }
     Axis::single('locale/language')->delete($this->db->quoteInto('id IN(?)', $data));
     Axis::dispatch('locale_language_delete', $data);
     Axis::message()->addSuccess(Axis::translate('locale')->__('Language was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
示例#12
0
 /**
  * Sends catalog notifications:
  * - catalog_product_backorder
  * - catalog_product_in_stock
  * - catalog_product_low_stock
  * - catalog_product_out_of_stock
  *
  * @param array $data
  * - old_quantity   = float
  * - new_quantity   = float
  * - product        = Axis_Catalog_Model_Product_Row
  * - variation      = Axis_Db_Table_Row[optional]
  * - stock          = Axis_Catalog_Model_Product_Stock_Row
  * @return void
  */
 public function notifyQuantityUpdate($data)
 {
     if ($data['old_quantity'] <= $data['stock']->min_qty && $data['new_quantity'] > $data['stock']->min_qty && ($data['stock']->in_stock || $data['stock']->backorder)) {
         if ($data['stock']->in_stock) {
             Axis::dispatch('catalog_product_in_stock', $data);
         } else {
             Axis::dispatch('catalog_product_backorder', $data);
         }
     } elseif ($data['old_quantity'] > $data['stock']->notify_qty && $data['new_quantity'] <= $data['stock']->notify_qty) {
         Axis::dispatch('catalog_product_low_stock', $data);
     } elseif ($data['old_quantity'] > $data['stock']->min_qty && $data['new_quantity'] <= $data['stock']->min_qty) {
         Axis::dispatch('catalog_product_out_of_stock', $data);
     }
 }
示例#13
0
 protected function _addCommentForm($pageId)
 {
     $form = Axis::model('cms/form_comment', array('pageId' => $pageId));
     if ($this->_request->isPost()) {
         $data = $this->_getAllParams();
         if ($form->isValid($data)) {
             Axis::single('cms/page_comment')->insert(array('author' => $data['author'], 'email' => $data['email'], 'status' => 0, 'content' => $data['content'], 'created_on' => Axis_Date::now()->toSQLString(), 'cms_page_id' => $pageId));
             Axis::dispatch('cms_comment_add_success', $data);
             Axis::message()->addSuccess(Axis::translate('cms')->__('Comment successfully added'));
             $this->_redirect($this->getRequest()->getServer('HTTP_REFERER'));
         } else {
             $form->populate($data);
         }
     }
     $this->view->formComment = $form;
 }
示例#14
0
 public function loginAction()
 {
     $username = $this->_getParam('username');
     $password = $this->_getParam('password');
     $auth = Zend_Auth::getInstance();
     $authAdapter = new Axis_Auth_AdminAdapter($username, $password);
     $result = $auth->authenticate($authAdapter);
     if (!$result->isValid()) {
         Axis::dispatch('admin_user_login_failed', array('username' => $username));
         $this->_redirect($this->_getBackUrl());
     } else {
         Zend_Session::regenerateId();
         Axis::dispatch('admin_user_login_success', array('username' => $username));
         Axis::session()->roleId = Axis::single('admin/user')->select('role_id')->where('id = ?', $result->getIdentity())->fetchOne();
         $this->_redirect($this->_getBackUrl());
     }
 }
示例#15
0
 public function successAction()
 {
     $this->setTitle(Axis::translate('checkout')->__('Checkout Success'));
     Axis::config()->analytics->main->checkoutSuccess = true;
     $checkout = $this->_getCheckout();
     $orderId = $checkout->getOrderId();
     $order = Axis::model('sales/order')->find($orderId)->current();
     if (!$order instanceof Axis_Sales_Model_Order_Row) {
         $this->_redirect('checkout/onestep');
     }
     if (!($statusId = $checkout->payment()->config('orderStatusId'))) {
         $statusId = Axis::config('sales/order/defaultStatusId');
     }
     if ($statusId != $order->getStatus()) {
         $order->setStatus($statusId);
     }
     Axis::dispatch('sales_order_create_success', $order);
     $this->view->order = $order;
     $checkout->clean();
     $this->render();
 }
示例#16
0
 /**
  *
  * @param array $data
  * @return Axis_Db_Table_Row
  */
 public function save(array $data)
 {
     $row = false;
     if (isset($data['id'])) {
         $row = $this->find($data['id'])->current();
     }
     if (!$row) {
         unset($data['id']);
         $row = $this->createRow();
         $oldData = null;
     } else {
         $oldData = $row->toArray();
     }
     if (self::GROUP_GUEST_ID === $row->id && self::GROUP_ALL_ID === $row->id) {
         // disallow to change system groups
         return;
     }
     $row->setFromArray($data)->save();
     Axis::dispatch('account_group_save_after', array('old_data' => $oldData, 'group' => $row));
     return $row;
 }
示例#17
0
 public function saveAction()
 {
     $_row = $this->_getAllParams();
     $isNew = false;
     if (isset($_row['id']) && !$_row['id']) {
         unset($_row['id']);
         $isNew = true;
         $_row['created_on'] = Axis_Date::now()->toSQLString();
     } else {
         $_row['modified'] = Axis_Date::now()->toSQLString();
     }
     $row = Axis::model('cms/page_comment')->getRow($_row);
     $row->save();
     if ($isNew) {
         Axis::dispatch('cms_comment_add_success', $row);
     } else {
         Axis::dispatch('cms_comment_update_success', $row);
     }
     Axis::message()->addSuccess(Axis::translate('core')->__('Data was saved successfully'));
     return $this->_helper->json->setId($row->id)->sendSuccess();
 }
示例#18
0
 /**
  * Render a view script (optionally to a named response segment)
  * Overriden to add axis_controller_action_render_before event
  *
  * Sets the noRender flag to true when called.
  *
  * @param  string $script
  * @param  string $name
  * @return void
  */
 public function renderScript($script, $name = null)
 {
     if (null === $name) {
         $name = $this->getResponseSegment();
     }
     // before_render event
     $object = new Axis_Object(array('request' => $this->getRequest(), 'response' => $this->getResponse(), 'script' => $script, 'name' => $name));
     Axis::dispatch('axis_controller_action_render_before', $object);
     $prefix = $this->getRequest()->getModuleName() . '_' . $this->getRequest()->getControllerName() . '_' . $this->getRequest()->getActionName();
     Axis::dispatch(strtolower($prefix) . '_render_before', $object);
     $script = $object->getScript();
     $name = $object->getName();
     // end of before_render event
     $this->getResponse()->appendBody($this->view->render($script), $name);
     $this->setNoRender();
 }
示例#19
0
 public function productAction()
 {
     $productId = $this->hurl->getParamValue('product');
     if (!$productId) {
         $productId = $this->_getParam('product', 0);
     }
     /**
      * @var $product Axis_Catalog_Model_Product_Row
      */
     $product = Axis::single('catalog/product')->cache($productId)->find($productId)->current();
     if (!$product || !$product->is_active) {
         return $this->_forward('not-found', 'Error', 'Axis_Core');
     }
     $refCategory = false;
     if ($referer = $this->getRequest()->getServer('HTTP_REFERER')) {
         preg_match('/' . $this->view->catalogUrl . '\\/(.[^\\/]+)\\//', $referer, $categoryUrl);
         if (isset($categoryUrl[1])) {
             $refCategory = Axis::single('catalog/category')->getByUrl($categoryUrl[1]);
         }
     }
     if ($refCategory) {
         $pathItems = $product->getParentItems($refCategory->id);
     } else {
         $pathItems = $product->getParentItems();
     }
     $lastItem = null;
     foreach ($pathItems as $_category) {
         if ($_category['status'] != 'enabled') {
             return $this->_forward('not-found', 'Error', 'Axis_Core');
         }
         $_uri = $this->view->hurl(array('cat' => array('value' => $_category['id'], 'seo' => $_category['key_word'])), false, true);
         $this->_helper->breadcrumbs(array('label' => $_category['name'], 'uri' => $_uri));
         $lastItem = $_category;
     }
     $product->incViewed();
     Zend_Registry::set('catalog/current_product', $product);
     if (count($pathItems)) {
         if ($refCategory && $refCategory->id == $lastItem['id']) {
             $category = $refCategory;
         } else {
             $category = Axis::single('catalog/category')->find($lastItem['id'])->current();
         }
         Zend_Registry::set('catalog/current_category', $category);
     }
     $data = $product->toArray();
     $data['category'] = $lastItem;
     $data['images'] = Axis::single('catalog/product_image')->cache($productId)->getList($productId);
     $data['images'] = current($data['images']);
     $data['human_url'] = urlencode($this->hurl->getParamSeo('product'));
     $data['description'] = $product->cache($productId)->getDescription();
     $data['properties'] = $product->cache($productId)->getProperties();
     $data['modifiers'] = $product->cache($productId)->getModifiers();
     $data['manufacturer'] = $product->cache($productId)->getManufacturer();
     foreach ($product->cache()->getVariationAttributesData() as $key => $value) {
         $data[$key] = $value;
     }
     $data['stock'] = array();
     $data['stock']['quantity'] = $data['quantity'];
     $data['stock']['is_saleable'] = (int) $product->cache($productId)->isSaleable();
     $stock = Axis::single('catalog/product_stock')->cache($productId)->find($productId)->current()->toArray();
     $data['stock'] = array_merge($stock, $data['stock']);
     unset($data['quantity']);
     $data['price_discount'] = $product->getPrice();
     $data['price'] = $product->getPriceRules();
     $data['discount_rules'] = Axis::single('discount/discount')->cache($productId)->getRulesByProduct($productId);
     $data['price']['format'] = Axis::single('locale/currency')->getFormat();
     $this->view->product = $data;
     $this->view->pageTitle = $data['description']['name'];
     $metaTitle = trim($data['description']['meta_title']) == '' ? $data['description']['name'] : $data['description']['meta_title'];
     $metaDescription = trim($data['description']['meta_description']) == '' ? strip_tags($data['description']['description']) : strip_tags($data['description']['meta_description']);
     $this->view->meta()->setTitle($metaTitle, 'product', $productId)->setDescription($metaDescription)->setKeywords($data['description']['meta_keyword']);
     $_uri = $this->view->hurl(array('product' => array('value' => $data['id'], 'seo' => $product->getHumanUrl())), false, true);
     $this->_helper->breadcrumbs(array('label' => $data['description']['name'], 'uri' => $_uri));
     Axis::dispatch('catalog_product_view', array('product' => $product));
     $this->render('product');
 }
示例#20
0
 /**
  * Update product or variation quantity. Frontend method.
  * Called at Axis_Sales_Model_Order_Status_Run
  *
  * @param float $quantity
  * @param int $variationId [optional]
  * @return boolean
  */
 public function setQuantity($quantity, $variationId = null)
 {
     if (!$this->manage) {
         return true;
     }
     // if backorder quantity change on ship order
     if ($this->backorder && $quantity < $this->min_qty) {
         return true;
     }
     if ($this->decimal) {
         $quantity = floor($quantity);
     }
     $product = Axis::single('catalog/product')->find($this->product_id)->current();
     if ($variationId) {
         $variation = Axis::single('catalog/product_variation')->find($variationId)->current();
         if ($variation->product_id == $this->product_id) {
             $oldQuantity = $variation->quantity;
             $variation->quantity = $quantity;
             $variation->save();
             Axis::dispatch('catalog_product_update_quantity', array('new_quantity' => $variation->quantity, 'old_quantity' => $oldQuantity, 'variation' => $variation, 'product' => $product, 'stock' => $this));
             return true;
         }
         return false;
     }
     $oldQuantity = $product->quantity;
     $product->quantity = $quantity;
     $product->save();
     Axis::dispatch('catalog_product_update_quantity', array('new_quantity' => $product->quantity, 'old_quantity' => $oldQuantity, 'product' => $product, 'stock' => $this));
     return true;
 }
示例#21
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));
     }
 }
示例#22
0
 public function removeAction()
 {
     $ids = Zend_Json::decode($this->_getParam('data'));
     $model = Axis::model('discount/discount');
     $discounts = $model->find($ids);
     foreach ($discounts as $discount) {
         $discountData = $discount->toArray();
         $discountData['products'] = $discount->getApplicableProducts();
         $discount->delete();
         Axis::dispatch('discount_delete_after', array('discount_data' => $discountData));
     }
     return $this->_helper->json->sendSuccess();
 }
示例#23
0
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     $model = Axis::model('catalog/category');
     foreach ($data as $categoryId) {
         $model->deleteItem($categoryId);
         Axis::dispatch('catalog_category_remove_success', array('category_id' => $categoryId));
     }
     return $this->_helper->json->sendSuccess();
 }
示例#24
0
 /**
  * Update product_stock table
  *
  * @param array $data
  * @return Axis_Catalog_Model_Product_Row
  */
 public function setStock($data = null)
 {
     if (null === $data) {
         return $this;
     }
     foreach ($data as $col => $val) {
         if (empty($val)) {
             $data[$col] = intval($data[$col]);
         }
     }
     $row = $this->getStockRow();
     $oldStockData = $row->toArray();
     $row->setFromArray($data);
     $row->save();
     Axis::dispatch('catalog_product_update_stock', array('product' => $this, 'old_data' => $oldStockData, 'stock' => $row));
     return $this;
 }
示例#25
0
 public function saveAction()
 {
     $_row = $this->_getParam('customer');
     $details = $this->_getParam('custom_fields', array());
     if (!$this->_isEmailValid($_row['email'], $_row['site_id'], $_row['id'])) {
         return $this->_helper->json->sendFailure();
     }
     $model = Axis::single('account/customer');
     $row = $model->find($_row['id'])->current();
     $event = false;
     if (!$row) {
         list($row, $password) = $model->create($_row);
         $event = true;
         Axis::message()->addSuccess(Axis::translate('Axis_Account')->__('Customer account was created successfully'));
     } else {
         if (empty($_row['password'])) {
             unset($_row['password']);
         } else {
             $_row['password'] = md5($_row['password']);
         }
         $row->setFromArray($_row);
         $row->modified_at = Axis_Date::now()->toSQLString();
         $row->save();
         Axis::message()->addSuccess(Axis::translate('Axis_Core')->__('Data was saved successfully'));
     }
     $row->setDetails($details);
     // address
     if ($this->_hasParam('address')) {
         $addresses = Zend_Json::decode($this->_getParam('address'));
         $modelAddress = Axis::single('account/customer_address');
         foreach ($addresses as $address) {
             if (!empty($address['id']) && $address['remove']) {
                 $modelAddress->delete(Axis::db()->quoteInto('id = ?', $address['id']));
             } else {
                 $row->setAddress($address);
             }
         }
     }
     if ($event) {
         Axis::dispatch('account_customer_register_success', array('customer' => $row, 'password' => $password));
     }
     return $this->_helper->json->setData(array('customer_id' => $row->id))->sendSuccess();
 }
示例#26
0
 /**
  * Post-dispatch routines
  *
  * Called after action method execution. If using class with
  * {@link Zend_Controller_Front}, it may modify the
  * {@link $_request Request object} and reset its dispatched flag in order
  * to process an additional action.
  *
  * Common usages for postDispatch() include rendering content in a sitewide
  * template, link url correction, setting headers, etc.
  *
  * @return void
  */
 public function postDispatch()
 {
     $observer = new Axis_Object();
     $observer->controller = $this;
     Axis::dispatch('controller_action_postdispatch', $observer);
 }
示例#27
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();
 }
示例#28
0
 /**
  * Updates quantity of cart product row.
  * !$itemId in not a product_id!
  *
  * @param int $itemId Id of cart product row
  * @param int $quantity
  * @return mixed bool|void
  */
 public function updateItem($itemId, $quantity)
 {
     $item = Axis::single('checkout/cart_product')->find($itemId)->current();
     if (!$item || $item->shopping_cart_id != $this->getCartId()) {
         return;
     }
     if (!($product = Axis::single('catalog/product')->find($item->product_id)->current())) {
         $item->delete();
         Axis::message()->addError(Axis::translate('checkout')->__("Product '%s' is not found in stock. product_id = %s", $product->sku, $item->product_id));
         return false;
     }
     if ($quantity == 0) {
         $item->delete();
         return true;
     }
     $stockRow = $product->getStockRow();
     if (!$stockRow->canAddToCart($quantity, $item->variation_id)) {
         if ($stockRow->in_stock && ($quantityAvailable = $stockRow->getQuantity($item->variation_id, true)) && $quantityAvailable >= $stockRow->min_qty_allowed) {
             $item->quantity = $quantityAvailable;
             if ($quantity < $stockRow->min_qty_allowed) {
                 $item->quantity = $stockRow->min_qty_allowed;
             }
             if ($stockRow->max_qty_allowed > 0 && $quantity > $stockRow->max_qty_allowed) {
                 if ($quantityAvailable > $stockRow->max_qty_allowed) {
                     $item->quantity = $stockRow->max_qty_allowed;
                 } else {
                     $item->quantity = $quantityAvailable;
                 }
             }
             $item->save();
             if ($quantity > $quantityAvailable) {
                 Axis::message()->addError(Axis::translate('checkout')->__("Only %s item(s) of '%s' are available", $quantityAvailable, $product->sku));
             }
         } else {
             $item->delete();
             Axis::message()->addError(Axis::translate('checkout')->__("Product '%s' is out of stock", $product->sku));
         }
         return false;
     }
     if (!$stockRow->decimal) {
         $quantity = floor($quantity);
     }
     Axis::dispatch('checkout_cart_update_product_success', array('product' => $product, 'quantity' => $quantity, 'cart_product_id' => $itemId));
     $item->quantity = $quantity;
     $item->save();
 }
示例#29
0
 /**
  * Update price indexes for recieved products
  *
  * @param array $products Keys are the product id
  * @return void
  */
 public function updateIndexesByProducts(array $products)
 {
     if (!count($products)) {
         return;
     }
     $ids = array_keys($products);
     $oldPricesTemp = $this->select('*')->where('product_id IN (?)', $ids)->fetchAll();
     $oldPrices = array();
     foreach ($oldPricesTemp as $oldPrice) {
         $oldPrices[$oldPrice['product_id']][] = $oldPrice;
     }
     $variationsTemp = Axis::model('catalog/product_variation')->select()->where('product_id IN (?)', $ids)->fetchAll();
     $variations = array();
     foreach ($variationsTemp as $variation) {
         $variations[$variation['product_id']][] = $variation;
     }
     foreach ($products as $product) {
         $variations[$product['id']][] = array('id' => 0, 'product_id' => $product['id'], 'quantity' => 0, 'price' => 0, 'price_type' => 'by', 'weight' => 0, 'weight_type' => 'by');
     }
     $modifiersTemp = Axis::model('catalog/product_attribute')->select('*')->joinInner('catalog_product_option', 'cpo.id = cpa.option_id', 'input_type')->where('cpa.product_id IN (?)', $ids)->where('cpa.modifier = 1')->where('cpa.variation_id = 0')->fetchAll();
     $modifiers = array();
     foreach ($modifiersTemp as $modifier) {
         $modifiers[$modifier['product_id']][] = $modifier;
     }
     $productToSites = Axis::model('catalog/product_category')->getSitesByProductIds($ids);
     $mDiscount = Axis::model('discount/discount');
     $discounts = $mDiscount->getApplicableDiscounts($ids, $mDiscount->getAllRules(true, false));
     $customerGroups = array_filter(array_keys(Axis_Collect_CustomerGroup::collect()));
     foreach ($products as $product) {
         if (!isset($productToSites[$product['id']])) {
             $this->delete('product_id = ' . $product['id']);
             continue;
         }
         $newPrices = $this->setProductData(array('id' => $product['id'], 'price' => $product['price'], 'site_ids' => $productToSites[$product['id']], 'customer_group_ids' => $customerGroups, 'modifiers' => isset($modifiers[$product['id']]) ? $modifiers[$product['id']] : array(), 'variations' => $variations[$product['id']], 'discounts' => isset($discounts[$product['id']]) ? $discounts[$product['id']] : array()))->getPriceIndexes();
         $oldAssocPrices = array();
         if (isset($oldPrices[$product['id']]) && count($oldPrices[$product['id']])) {
             foreach ($oldPrices[$product['id']] as $oldPrice) {
                 $oldAssocPrices[$oldPrice['id']] = $oldPrice;
             }
             $this->delete(Axis::db()->quoteInto('id IN (?)', array_keys($oldAssocPrices)));
         }
         foreach ($newPrices as $price) {
             $this->insert($price);
         }
         Axis::dispatch('catalog_product_price_update_after', array('product_data' => $product, 'new_price' => $newPrices, 'old_price' => $oldAssocPrices));
     }
 }
示例#30
0
 public function saveAction()
 {
     $params = $this->_getAllParams();
     $params['products'] = Zend_Json::decode($params['products']);
     ////////////////////////////////////////////////////////////////////////
     //add new customer
     $isNewBillingAddress = $params['order']['billing_address_type'] == 0;
     $isNewDeliveryAddress = $params['order']['delivery_address_type'] == 0;
     $event = false;
     if (-2 == $params['order']['customer_id']) {
         $customerRawData = array_merge($params['customer'], array('email' => $params['order']['customer_email'], 'is_active' => true, 'site_id' => $params['order']['site_id']));
         list($customer, $password) = Axis::single('account/customer')->create($customerRawData);
         $event = true;
         $customer->setDetails($customerRawData);
         $params['order']['customer_id'] = $customer->id;
         $isNewBillingAddress = $isNewDeliveryAddress = true;
     }
     if ($params['order']['customer_id'] < 0) {
         $params['order']['customer_id'] = 0;
     }
     ////////////////////////////////////////////////////////////////////////
     // save new customer addresses
     $customerRow = null;
     if ($params['order']['customer_id'] && ($isNewBillingAddress || $isNewDeliveryAddress)) {
         $customerRow = Axis::single('account/customer')->find($params['order']['customer_id'])->current();
     }
     if ($customerRow instanceof Axis_Db_Table_Row) {
         $o = $params['order'];
         if ($isNewBillingAddress) {
             $address = array('firstname' => $o['billing_firstname'], 'lastname' => $o['billing_lastname'], 'phone' => $o['billing_phone'], 'fax' => $o['billing_fax'], 'company' => $o['billing_company'], 'street_address' => $o['billing_street_address'], 'suburb' => $o['billing_suburb'], 'city' => $o['billing_city'], 'postcode' => $o['billing_postcode'], 'country_id' => $o['billing_country']);
             if (!is_numeric($o['billing_state'])) {
                 $address['state'] = $o['billing_state'];
             } else {
                 $address['zone_id'] = $o['billing_state'];
             }
             $customerRow->setAddress($address);
         }
         if ($isNewDeliveryAddress) {
             $address = array('firstname' => $o['delivery_firstname'], 'lastname' => $o['delivery_lastname'], 'phone' => $o['delivery_phone'], 'fax' => $o['delivery_fax'], 'company' => $o['delivery_company'], 'street_address' => $o['delivery_street_address'], 'suburb' => $o['delivery_suburb'], 'city' => $o['delivery_city'], 'postcode' => $o['delivery_postcode'], 'country_id' => $o['delivery_country']);
             if (!is_numeric($o['delivery_state'])) {
                 $address['state'] = $o['delivery_state'];
             } else {
                 $address['zone_id'] = $o['delivery_state'];
             }
             $customerRow->setAddress($address);
         }
     }
     if ($event) {
         Axis::dispatch('account_customer_register_success', array('customer' => $customer, 'password' => $password));
     }
     ////////////////////////////////////////////////////////////////////////
     //prepare order data
     $params['order']['currency_rate'] = Axis::single('locale/currency')->getRateByCode($params['order']['currency']);
     $params['order']['billing_country'] = Axis::single('location/country')->getName($params['order']['billing_country']);
     if (is_numeric($params['order']['billing_state']) && ($name = Axis::single('location/zone')->getName($params['order']['billing_state']))) {
         $params['order']['billing_state'] = $name;
     }
     $params['order']['delivery_country'] = Axis::single('location/country')->getName($params['order']['delivery_country']);
     if (is_numeric($params['order']['delivery_state']) && ($name = Axis::single('location/zone')->getName($params['order']['delivery_state']))) {
         $params['order']['delivery_state'] = $name;
     }
     if (empty($params['order']['order_status_id'])) {
         $params['order']['order_status_id'] = 0;
     }
     if (empty($params['order']['ip_address'])) {
         $params['order']['ip_address'] = '127.0.0.1';
     }
     $orderRow = Axis::single('sales/order')->find($params['order']['id'])->current();
     if (!$orderRow instanceof Axis_Sales_Model_Order_Row) {
         unset($params['order']['id']);
         $params['order']['locale'] = Axis::config('locale/main/locale');
         $orderRow = Axis::single('sales/order')->createRow($params['order']);
     } else {
         // Unset updated currency rate.
         // It cannot be changed in already placed order.
         if ($params['order']['currency'] === $orderRow->currency) {
             unset($params['order']['currency_rate']);
         }
         $orderRow->setFromArray($params['order']);
     }
     $orderRow->save();
     ////////////////////////////////////////
     // update products
     $modelOrderProduct = Axis::single('sales/order_product');
     $modelOrderProduct->delete(Axis::db()->quoteInto('order_id = ?', $orderRow->id));
     foreach ($params['products'] as $product) {
         $modelOrderProduct->add($product, $orderRow->id);
     }
     ////////////////////////////////////////
     //update totals
     $modelOrderTotal = Axis::single('sales/order_total');
     $modelTotal = Axis::single('checkout/total');
     $modelOrderTotal->delete(Axis::db()->quoteInto('order_id = ?', $orderRow->id));
     foreach ($params['totals'] as $totalCode => $total) {
         $method = $modelTotal->getMethod($totalCode);
         $modelOrderTotal->insert(array('order_id' => $orderRow->id, 'code' => $totalCode, 'title' => $method->getTitle(), 'value' => $total));
     }
     ////////////////////////////////////////
     // STATUS UPDATE
     if (!empty($params['history']['order_status_id'])) {
         $orderRow->setStatus($params['history']['order_status_id'], $params['history']['comments'], isset($params['history']['notified']));
     } elseif (!empty($params['history']['comments'])) {
         $orderRow->addComment($params['history']['comments'], isset($params['history']['notified']));
     }
     return $this->_helper->json->setData(array('order_id' => $orderRow->id))->sendSuccess();
 }