예제 #1
0
 public function init()
 {
     $date = new Axis_Date();
     $todayDate = $date->toString();
     $date = $date->addDay(-1)->toString('YYYY-MM-dd');
     $mailCount = Axis::single('contacts/message')->select()->where('created_at > ?', $date)->count();
     $orderTotal = (double) Axis::single('sales/order')->select('SUM(order_total)')->where('date_purchased_on > ?', $date)->fetchOne();
     $orderTotal = Axis::single('locale/currency')->getCurrency(Axis::config()->locale->main->currency)->toCurrency($orderTotal ? $orderTotal : 0);
     $orderCount = Axis::single('sales/order')->select()->where('date_purchased_on > ?', $date)->count();
     $userId = Zend_Auth::getInstance()->getIdentity();
     $this->setFromArray(array('today_date' => $todayDate, 'mail_count' => $mailCount, 'order_total' => $orderTotal, 'order_count' => $orderCount, 'user_info' => Axis::single('admin/user')->find($userId)->current()));
     return true;
 }
예제 #2
0
 /**
  *
  * @param array $data
  * @return mixed
  */
 public function insert(array $data)
 {
     if (empty($data['created_on'])) {
         $data['created_on'] = Axis_Date::now()->toSQLString();
     }
     return parent::insert($data);
 }
예제 #3
0
 /**
  * Update or insert product.
  * Returns last saved product
  *
  * @param array $data
  * @return Axis_Catalog_Model_Product_Row
  */
 public function save(array $data)
 {
     $row = $this->getRow($data);
     //before save
     $isExist = (bool) $this->select()->where('sku = ?', $row->sku)->where('id <> ?', (int) $row->id)->fetchOne();
     if ($isExist) {
         throw new Axis_Exception(Axis::translate('catalog')->__('Product sku must be unique value'));
     }
     if (empty($row->new_from)) {
         $row->new_from = new Zend_Db_Expr('NULL');
     }
     if (empty($row->new_to)) {
         $row->new_to = new Zend_Db_Expr('NULL');
     }
     if (empty($row->featured_from)) {
         $row->featured_from = new Zend_Db_Expr('NULL');
     }
     if (empty($row->featured_to)) {
         $row->featured_to = new Zend_Db_Expr('NULL');
     }
     if (empty($row->weight)) {
         $row->weight = 0;
     }
     if (empty($row->cost)) {
         $row->cost = 0;
     }
     $row->modified_on = Axis_Date::now()->toSQLString();
     if (empty($row->created_on)) {
         $row->created_on = $row->modified_on;
     }
     $row->save();
     return $row;
 }
예제 #4
0
 public function batchSaveAction()
 {
     $dataset = Zend_Json::decode($this->_getParam('data'));
     if (!sizeof($dataset)) {
         Axis::message()->addError(Axis::translate('core')->__('No data to save'));
         return $this->_helper->json->sendFailure();
     }
     $model = Axis::model('admin/user');
     foreach ($dataset as $data) {
         if (!empty($data['password'])) {
             $data['password'] = md5($data['password']);
         } else {
             unset($data['password']);
         }
         $row = $model->getRow($data);
         $row->is_active = false;
         $row->is_active = !empty($data['is_active']);
         $row->modified = Axis_Date::now()->toSQLString();
         if (empty($row->created)) {
             $row->created = $row->modified;
         }
         $row->save();
     }
     Axis::message()->addSuccess(Axis::translate('admin')->__('User was saved successfully'));
     return $this->_helper->json->sendSuccess();
 }
예제 #5
0
 public function log($observer)
 {
     if (!Axis::config('log/main/enabled')) {
         return false;
     }
     /**
      * @var $request Zend_Controller_Request_Abstract
      */
     $request = $observer->getController()->getRequest();
     $url = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri();
     $refer = $request->getServer('HTTP_REFERER', '');
     $timestamp = Axis_Date::now()->toSQLString();
     $siteId = Axis::getSiteId();
     // add new url request
     $modelUrlInfo = Axis::single('log/url_info');
     $rowUrlInfo = $modelUrlInfo->select()->where('url = ?', $url)->where('refer = ?', $refer)->fetchRow();
     if (!$rowUrlInfo) {
         $rowUrlInfo = $modelUrlInfo->createRow(array('url' => $url, 'refer' => $refer));
         $rowUrlInfo->save();
     }
     //add/update visitor
     $visitor = Axis::single('log/visitor')->getVisitor();
     //add/update visitor info
     Axis::single('log/visitor_info')->getRow(array('visitor_id' => $visitor->id, 'user_agent' => $request->getServer('HTTP_USER_AGENT', ''), 'http_accept_charset' => $request->getServer('HTTP_ACCEPT_CHARSET', ''), 'http_accept_language' => $request->getServer('HTTP_ACCEPT_LANGUAGE', ''), 'server_addr' => $request->getServer('SERVER_ADDR', ''), 'remote_addr' => $request->getServer('REMOTE_ADDR', '')))->save();
     Axis::single('log/url')->insert(array('url_id' => $rowUrlInfo->id, 'visitor_id' => $visitor->id, 'visit_at' => $timestamp, 'site_id' => $siteId));
 }
예제 #6
0
 /**
  *
  * @param Axis_Date $date
  * @return Axis_Discount_Model_Discount_Select 
  */
 public function addDateFilter($date = null)
 {
     if (null === $date) {
         $date = Axis_Date::now();
     }
     $date = $date->toPhpString("Y-m-d");
     return $this->where('d.from_date <= ? OR d.from_date IS NULL', $date)->where('? <= d.to_date OR d.to_date IS NULL', $date);
 }
예제 #7
0
 /**
  * Adds message to database
  *
  * @param array $data 
  * @return Axis_Db_Table_Row
  */
 public function save(array $data)
 {
     $row = $this->createRow($data);
     //before save
     $row->created_at = Axis_Date::now()->toSQLString();
     $row->save();
     return $row;
 }
예제 #8
0
 /**
  *
  * @param string $hash
  * @param string $email
  * @return bool
  */
 public function isValid($hash, $email = null)
 {
     $date = Axis_Date::now()->addDay(-1)->toSQLString();
     $select = $this->select('*')->joinLeft('account_customer', 'ac.id = acf.customer_id')->where('acf.hash = ?', $hash)->where('ac.site_id = ?', Axis::getSiteId())->where('acf.created_at > ?', $date);
     if (null !== $email) {
         $select->where('ac.email = ?', $email);
     }
     return (bool) $select->count();
 }
예제 #9
0
 public function isValid($hash, $username = null)
 {
     $date = Axis_Date::now()->addDay(-1)->toSQLString();
     $select = $this->select('*')->joinLeft('admin_user', 'au.id = auf.user_id')->where('auf.hash = ?', $hash)->where('auf.created_at > ?', $date);
     if ($username) {
         $select->where('au.username = ?', $username);
     }
     return (bool) $select->count();
 }
예제 #10
0
 /**
  * Save data call backend
  * @param array $data
  * @return Axis_Db_Table_Row
  */
 public function save(array $data)
 {
     $row = $this->getRow($data);
     $row->modified_on = Axis_Date::now()->toSQLString();
     if (empty($row->created_on)) {
         $row->created_on = $row->modified_on;
     }
     $row->save();
     return $row;
 }
예제 #11
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);
 }
예제 #12
0
 /**
  *
  * @param array $data
  * @return Axis_Db_Table_Row  
  */
 public function save(array $data)
 {
     $row = $this->getRow($data);
     //before save
     $row->updated_at = Axis_Date::now()->toSQLString();
     if (empty($row->created_at)) {
         $row->created_at = $row->updated_at;
     }
     $row->save();
     return $row;
 }
예제 #13
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();
 }
예제 #14
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;
 }
예제 #15
0
 /**
  *
  * @param array $data
  * @return type 
  */
 public function create(array $data)
 {
     $row = $this->createRow($data);
     if (empty($row->password)) {
         $row->password = $this->generatePassword();
     }
     $password = $row->password;
     $row->password = md5($password);
     $row->modified_at = Axis_Date::now()->toSQLString();
     if (empty($row->created_at)) {
         $row->created_at = $row->modified_at;
     }
     if (empty($row->locale)) {
         $row->locale = Axis_Locale::getLocale()->toString();
     }
     $row->save();
     return array($row, $password);
 }
예제 #16
0
 /**
  *
  * @return Zend_Auth_Result 
  */
 public function authenticate()
 {
     $row = Axis::single('admin/user')->select()->where('username = ?', $this->_username)->fetchRow();
     if (!$row) {
         $code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
         Axis::message()->addError(Axis::translate('admin')->__('Such user does not exists'));
         return new Zend_Auth_Result($code, null);
     }
     if ($row->password != md5($this->_password)) {
         $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
         Axis::message()->addError(Axis::translate('admin')->__('Wrong password'));
         return new Zend_Auth_Result($code, null);
     }
     $code = Zend_Auth_Result::SUCCESS;
     $row->lastlogin = Axis_Date::now()->toSQLString();
     $row->save();
     return new Zend_Auth_Result($code, $row->id);
 }
예제 #17
0
 /**
  *
  * @param int $discountId
  * @return array
  */
 public function getRulesByDiscountId($discountId)
 {
     $rowset = $this->select()->where('discount_id = ?', $discountId)->fetchAll();
     $result = array();
     foreach ($rowset as $row) {
         if (strstr($row['entity'], '_')) {
             list($entity, $etype) = explode('_', $row['entity'], 2);
             $result['conditions'][$entity]['e-type'][] = $etype;
             $value = $row['value'];
             if (substr($entity, 0, strlen('date')) === 'date') {
                 $value = Axis_Date::timestamp($row['value'])->toPhpString("Y-m-d");
             }
             $result['conditions'][$entity]['value'][] = $value;
         } else {
             $result[$row['entity']][] = intval($row['value']);
         }
     }
     return $result;
 }
예제 #18
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();
 }
예제 #19
0
파일: Row.php 프로젝트: baisoo/axiscommerce
 public function save()
 {
     //before save
     if (empty($this->created_on)) {
         $this->created_on = Axis_Date::now()->toSQLString();
     }
     $this->modified_on = Axis_Date::now()->toSQLString();
     if (empty($this->date_available)) {
         $this->date_available = new Zend_Db_Expr('NULL');
     }
     if (empty($this->manufacturer_id)) {
         $this->manufacturer_id = new Zend_Db_Expr('NULL');
     }
     if (empty($this->ordered)) {
         $this->ordered = 0;
     }
     if (empty($this->viewed)) {
         $this->viewed = 0;
     }
     if (empty($this->tax_class_id)) {
         $this->tax_class_id = new Zend_Db_Expr('NULL');
     }
     return parent::save();
 }
예제 #20
0
 /**
  *
  * @param Axis_Db_Table_Row $site
  * @return Axis_Db_Table_Row 
  */
 public function addNewRootCategory(Axis_Db_Table_Row $site)
 {
     $modelDescription = Axis::model('catalog/category_description');
     $languageIds = array_keys(Axis_Collect_Language::collect());
     $timestamp = Axis_Date::now()->toSQLString();
     $row = $this->createRow(array('site_id' => $site->id, 'lft' => 1, 'rgt' => 2, 'lvl' => 0, 'created_on' => $timestamp, 'modified_on' => $timestamp, 'status' => 'enabled'));
     $row->save();
     foreach ($languageIds as $languageId) {
         $modelDescription->createRow(array('category_id' => $row->id, 'language_id' => $languageId, 'name' => $site->name, 'description' => 'Root Category'))->save();
     }
     return $row;
 }
예제 #21
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();
 }
예제 #22
0
 private function addCustomer($entry)
 {
     $date = Axis_Date::now()->toPhpString("Y-m-d H:i:s");
     $duplicate = Axis::db()->fetchOne("SELECT c.id\n            FROM " . parent::$_db_prefix . parent::CUSTOMER . " AS c\n            WHERE c.email = ?", $entry['customer']['customers_email_address']);
     if (!$duplicate) {
         $customer = array('email' => $entry['customer']['customers_email_address'], 'password' => $entry['customer']['customers_password'], 'site_id' => $this->_site, 'is_active' => 1, 'default_shipping_address_id' => '', 'default_billing_address_id' => '', 'created_at' => $date, 'modified_at' => $date, 'group_id' => 1);
         Axis::db()->insert(parent::$_db_prefix . parent::CUSTOMER, $customer);
         $customer_id = Axis::db()->lastInsertId(parent::$_db_prefix . parent::CUSTOMER);
         $_SESSION['imported_count']++;
         $_SESSION['customer_relations_array'][$entry['customer']['customers_id']] = $customer_id;
         $_SESSION['message_stack']['successfully imported'][] = $entry['customer']['customers_email_address'];
         $address_relations_array = array();
         foreach ($entry['addresses'] as $address) {
             $data = array('customer_id' => $customer_id, 'gender' => $address['entry_gender'], 'company' => $address['entry_company'], 'phone' => $address['entry_telephone'], 'fax' => $address['entry_fax'], 'firstname' => $address['entry_firstname'], 'lastname' => $address['entry_lastname'], 'street_address' => $address['entry_street_address'], 'suburb' => $address['entry_suburb'], 'postcode' => $address['entry_postcode'], 'city' => $address['entry_city'], 'state' => $address['entry_state'], 'country_id' => $address['entry_country_id'], 'zone_id' => $address['entry_zone_id']);
             Axis::db()->insert(parent::$_db_prefix . parent::CUSTOMER_ADDRESS, $data);
             $address_id = Axis::db()->lastInsertId(parent::$_db_prefix . parent::CUSTOMER_ADDRESS);
             $address_relations_array[$address['address_book_id']] = $address_id;
         }
         Axis::db()->update(parent::$_db_prefix . parent::CUSTOMER, array('default_shipping_address_id' => $address_relations_array[$entry['customer']['customers_default_address_id']], 'default_billing_address_id' => $address_relations_array[$entry['customer']['customers_default_address_id']]));
     } else {
         if (isset($_SESSION['customer_relations_array'][$entry['customer']['customers_id']])) {
             unset($_SESSION['customer_relations_array'][$entry['customer']['customers_id']]);
         }
         $_SESSION['message_stack']['skipped (duplicate entry)'][] = $entry['customer']['customers_email_address'];
     }
     $_SESSION['processed_count']++;
 }
예제 #23
0
 /**
  * Retrieve the dynamic parameters from discount.
  * Customer group, Site, Date from and Date to
  * If false is returned - discount can't be applied
  *
  * @param array $discount
  * @return array
  */
 protected function _getDiscountRules(array $discount)
 {
     $rules = array();
     $rulesMapping = array('group' => 'customer_group_id', 'site' => 'site_id', 'from_date' => 'time_from', 'to_date' => 'time_to');
     foreach ($rulesMapping as $discountKey => $ruleKey) {
         if (!isset($discount[$discountKey])) {
             switch ($ruleKey) {
                 case 'customer_group_id':
                     $rules[$ruleKey] = $this->getProductData('customer_group_ids');
                     break;
                 case 'site_id':
                     $rules[$ruleKey] = $this->getProductData('site_ids');
                     break;
                 case 'time_from':
                     $rules[$ruleKey] = array(Axis_Date::now()->getDate()->getTimestamp());
                     break;
                 case 'time_to':
                     $rules[$ruleKey] = array(Axis_Date::now()->getDate()->addYear(5)->getTimestamp());
                     break;
             }
             continue;
         }
         if (!is_array($discount[$discountKey])) {
             // time_from and time_to filters
             $date = new Axis_Date($discount[$discountKey], 'yyyy-MM-dd');
             if ('time_to' === $ruleKey) {
                 $date->set('23:59:59', Zend_Date::TIMES);
             }
             $discount[$discountKey] = array($date->getTimestamp());
         }
         if ('customer_group_id' === $ruleKey) {
             if (in_array(0, $discount[$discountKey])) {
                 // All groups value support
                 $customerGroupIds = $this->getProductData('customer_group_ids');
             } else {
                 $customerGroupIds = array_intersect($discount[$discountKey], $this->getProductData('customer_group_ids'));
             }
             $rules[$ruleKey] = $customerGroupIds;
         } else {
             $rules[$ruleKey] = $discount[$discountKey];
         }
     }
     return $rules;
 }
예제 #24
0
 private function _importProducts($preferences, $filters)
 {
     $this->_helper->layout->disableLayout();
     $createOptions = true;
     $path = Axis::config()->system->path . '/' . $preferences['file_path'];
     if (@(!($fp = fopen($path . '/' . $preferences['file_name'], 'r')))) {
         Axis::message()->addError(Axis::translate('admin')->__('Cannot open file with read permissions'));
         return $this->_helper->json->sendFailure();
     }
     $titles = fgetcsv($fp, 2048, ',', "'");
     $rowSize = count($titles);
     $optionsIndexStartFrom = array_search('variations', $titles) + 1;
     $optionTypes = Axis_Catalog_Model_Product_Option::getTypes();
     $filter_sites = explode(',', trim($filters['site'], ', '));
     $mManufacturer = Axis::single('catalog/product_manufacturer');
     $mManufacturerTitle = Axis::single('catalog/product_manufacturer_description');
     $manufacturers = $mManufacturer->select(array('name', 'id'))->fetchPairs();
     $languages = Axis::single('locale/language')->select(array('locale', 'id'))->fetchPairs();
     $mProduct = Axis::single('catalog/product');
     $log['skipped'] = array();
     $log['imported'] = array();
     $log['skipped']['count'] = 0;
     $log['imported']['count'] = 0;
     while (!feof($fp)) {
         $data = fgetcsv($fp, 2048, ',', "'");
         if (!is_array($data)) {
             continue;
         }
         $data = array_pad($data, $rowSize, '');
         $data = array_combine($titles, $data);
         if (empty($data['sku'])) {
             continue;
         }
         $log['imported']['count']++;
         if (!empty($data['manufacturer']) && !isset($manufacturers[$data['manufacturer']])) {
             if (!($manufacturerId = $mManufacturer->select('id')->where('cpm.name = ?', $data['manufacturer'])->fetchOne())) {
                 $manufacturerId = $mManufacturer->insert(array('name' => $data['manufacturer']));
                 foreach ($languages as $langId) {
                     $mManufacturerTitle->insert(array('manufacturer_id' => $manufacturerId, 'language_id' => $langId, 'title' => $data['manufacturer']));
                 }
                 $url = $data['manufacturer'] = preg_replace('/[^a-zA-Z0-9]/', '-', $data['manufacturer']);
                 foreach ($filter_sites as $siteId) {
                     $i = 0;
                     while (Axis::single('catalog/hurl')->hasDuplicate($url, $siteId)) {
                         $url = $data['manufacturer'] . '-' . ++$i;
                     }
                     Axis::single('catalog/hurl')->insert(array('key_word' => $url, 'site_id' => $siteId, 'key_type' => 'm', 'key_id' => $manufacturerId));
                 }
             }
             $manufacturers[$data['manufacturer']] = $manufacturerId;
         }
         $product = $mProduct->select()->where('sku = ?', $data['sku'])->fetchRow();
         if (!$product) {
             $product = $mProduct->createRow();
             $product->viewed = 0;
             $product->tax_class_id = 1;
         }
         if (!empty($data['manufacturer']) && isset($manufacturers[$data['manufacturer']])) {
             $product->manufacturer_id = $manufacturers[$data['manufacturer']];
         }
         $product->setFromArray($data);
         // will set correct values for the images later
         foreach (array('image_base', 'image_listing', 'image_thumbnail') as $imageType) {
             if (!isset($data[$imageType])) {
                 // data[imageType] is a string (path to image) not id
                 continue;
             }
             $product->{$imageType} = null;
         }
         $viewed = Zend_Json_Decoder::decode($data['viewed']);
         if (is_array($viewed)) {
             foreach ($viewed as $viewedPerLanguage) {
                 $product->viewed += current($viewedPerLanguage);
             }
         } else {
             $product->viewed += (int) $viewed;
         }
         $productId = $product->save();
         // human url
         $urlModel = Axis::single('catalog/hurl');
         $data['hurl'] = str_replace(array('\\', '/', ' '), '-', $data['hurl']);
         foreach ($filter_sites as $siteId) {
             $urlModel->delete("key_type = 'p' AND key_id = {$product->id}");
             $i = 0;
             $url = $data['hurl'];
             while ($urlModel->hasDuplicate($url, $siteId)) {
                 $url = $data['hurl'] . '-' . ++$i;
             }
             $urlModel->save(array('key_word' => $url, 'site_id' => $siteId, 'key_type' => 'p', 'key_id' => $product->id));
         }
         // create categories if not exist
         if (isset($data['path'])) {
             $paths = explode(',', trim($data['path'], ', '));
             $modelCategory = Axis::single('catalog/category');
             $mProductCategory = Axis::single('catalog/product_category');
             $mProductCategory->delete('product_id = ' . $product->id);
             $catData = array('status' => 'enabled', 'modified_on' => Axis_Date::now()->toSQLString(), 'created_on' => Axis_Date::now()->toSQLString());
             foreach ($paths as $path) {
                 $cleanPath = trim($path, "/\n ");
                 $path = explode('/', $cleanPath);
                 foreach ($filter_sites as $siteId) {
                     $i = 0;
                     $categoryId = 0;
                     $rootCategory = $modelCategory->getRoot($siteId);
                     foreach ($path as $catUrl) {
                         if (!($category = $modelCategory->getByUrl($catUrl, $siteId))) {
                             if ($i == 0) {
                                 $categoryId = $modelCategory->insertItem($catData, $rootCategory->id);
                             } else {
                                 $categoryId = $modelCategory->insertItem($catData, $modelCategory->getByUrl($path[$i - 1], $siteId)->id);
                             }
                             // description
                             foreach ($languages as $langId) {
                                 Axis::single('catalog/category_description')->save(array('category_id' => $categoryId, 'language_id' => $langId, 'name' => $catUrl, 'description' => '', 'meta_title' => $catUrl, 'meta_description' => '', 'meta_keyword' => $catUrl));
                             }
                             // human url
                             Axis::single('catalog/hurl')->save(array('key_word' => $catUrl, 'site_id' => $siteId, 'key_type' => 'c', 'key_id' => $categoryId));
                         } else {
                             $categoryId = $category->id;
                         }
                         $i++;
                     }
                     // product to category linking
                     $assignment = $mProductCategory->select()->where('category_id = ?', $categoryId)->where('product_id = ?', $product->id)->fetchRow();
                     if (!$assignment) {
                         $mProductCategory->insert(array('category_id' => $categoryId, 'product_id' => $productId));
                     }
                 }
             }
         }
         // Gallery
         if (isset($data['product_gallery'])) {
             $imagePathToId = array();
             $images = explode(',', $data['product_gallery']);
             $modelImage = Axis::single('catalog/product_image');
             $modelImage->delete('product_id = ' . $product->id);
             foreach ($images as $image) {
                 $image = trim($image);
                 // remove line-breaks
                 $imageId = $modelImage->insert(array('product_id' => $product->id, 'path' => $image));
                 $imagePathToId[$image] = $imageId;
             }
             if (isset($imagePathToId[$data['image_base']])) {
                 $product->image_base = $imagePathToId[$data['image_base']];
             }
             if (isset($imagePathToId[$data['image_listing']])) {
                 $product->image_listing = $imagePathToId[$data['image_listing']];
             }
             if (isset($imagePathToId[$data['image_thumbnail']])) {
                 $product->image_thumbnail = $imagePathToId[$data['image_thumbnail']];
             }
             $product->save();
         }
         // Description
         $descriptions = array();
         foreach ($this->_getCsvProductTitles('description') as $field) {
             $fieldValues = Zend_Json_Decoder::decode($data[$field]);
             if (!is_array($fieldValues)) {
                 continue;
             }
             foreach ($fieldValues as $value) {
                 $langCode = key($value);
                 $value = current($value);
                 if (!isset($languages[$langCode])) {
                     continue;
                 }
                 $descriptions[$languages[$langCode]][$field] = $value;
             }
         }
         $product->setDescription($descriptions);
         // stock
         $stock = Axis::single('catalog/product_stock')->getRow($product->id);
         $stock->in_stock = $data['in_stock'];
         $stock->save();
         // Attributes
         $mAttribute = Axis::single('catalog/product_attribute');
         // Variations
         if (!empty($data['variations'])) {
             $variations = Zend_Json_Decoder::decode($data['variations']);
             $mVariation = Axis::single('catalog/product_variation');
             $mVariation->delete('product_id = ' . $product->id);
             foreach ($variations as &$variation) {
                 $pVariation = $mVariation->createRow();
                 $pVariation->product_id = $product->id;
                 $pVariation->sku = $variation['sku'];
                 list($pVariation->price, $pVariation->price_type) = $this->_valueToModifier($variation['price']);
                 list($pVariation->weight, $pVariation->weight_type) = $this->_valueToModifier($variation['weight']);
                 $variation['id'] = $pVariation->save();
                 // insert new attributes
                 foreach (array_slice($variation, 3) as $optionName => $valueText) {
                     $option = $this->_getCreateOption($optionName, $createOptions);
                     // if option does not exists or valueset is empty then skip this attribute
                     // because variation can contain only selectable options
                     if (!$option || !$option->valueset_id) {
                         continue;
                     }
                     // the same, values
                     $value = $this->_getCreateValue($valueText, $option->valueset_id, $createOptions);
                     if (!$value) {
                         continue;
                     }
                     $mAttribute->insert(array('product_id' => $productId, 'variation_id' => $variation['id'], 'option_id' => $option->id, 'option_value_id' => $value->id));
                 }
             }
         }
         $optionValues = array_slice($data, $optionsIndexStartFrom);
         $i = 0;
         // used as key for creating new attributes-modifiers
         $mAttribute->delete('variation_id = 0 AND product_id = ' . $productId);
         while (list($optionName, $optionValue) = each($optionValues)) {
             if (is_array($optionValue)) {
                 $modifier = $optionValue;
                 $optionValue = $modifier['value'];
                 $optionName = $modifier['optionName'];
             } else {
                 $modifier = false;
             }
             $optionValue = trim($optionValue);
             $option = $this->_getCreateOption($optionName, $createOptions);
             if (!$option || $optionTypes[$option->input_type] != $this->_optionNameToType($optionName) || empty($optionValue)) {
                 // if option not exists or type is wrong then skip this option
                 continue;
             }
             /* check is this modifier json data */
             if (false !== strpos($optionValue, '[{"') && false !== strpos($optionValue, '"}]')) {
                 $modifiers = Zend_Json_Decoder::decode($optionValue);
                 foreach ($modifiers as $modifier) {
                     $modifier['optionName'] = $optionName;
                     if (empty($modifier['value'])) {
                         $modifier['value'] = current(explode(',', $optionName));
                     }
                     $optionValues['modifier_' . $i++] = $modifier;
                 }
                 continue;
             }
             if (!$option->isInputable() && $option->valueset_id) {
                 if (!($value = $this->_getCreateValue($optionValue, $option->valueset_id, $createOptions))) {
                     continue;
                 }
                 $valueId = $value->id;
             } else {
                 $valueId = new Zend_Db_Expr('NULL');
             }
             $attribute = $mAttribute->createRow();
             $attribute->product_id = $product->id;
             $attribute->option_id = $option->id;
             $attribute->option_value_id = $valueId;
             if ($modifier) {
                 list($attribute->price, $attribute->price_type) = $this->_valueToModifier($modifier['price']);
                 list($attribute->weight, $attribute->weight_type) = $this->_valueToModifier($modifier['weight']);
                 $attribute->modifier = 1;
             }
             $attribute->save();
         }
     }
     return $log;
 }
예제 #25
0
 /**
  * Save product category
  */
 public function saveAction()
 {
     $success = true;
     $modelCategory = Axis::model('catalog/category');
     /* @var $modelCategory Axis_Catalog_Model_Category */
     $parentId = $this->_getParam('parent_id', 0);
     $categoryId = $this->_getParam('id', 0);
     $catKeyWord = $this->_getParam('key_word');
     $siteId = $this->_getParam('site_id');
     /* if human url already exist */
     $modelHurl = Axis::model('catalog/hurl');
     if (!empty($catKeyWord) && $modelHurl->hasDuplicate($catKeyWord, $siteId, $categoryId)) {
         Axis::message()->addError(Axis::translate('catalog')->__('Duplicate entry (url)'));
         return $this->_helper->json->sendFailure();
     }
     $image = $this->_getParam('image');
     // unlink images if requested
     foreach ($image as $imageType => $values) {
         if (isset($image[$imageType]['delete']) && !empty($image[$imageType]['src'])) {
             $categoryDir = realpath(Axis::config()->system->path . '/media/category');
             $src = realpath($categoryDir . $image[$imageType]['src']);
             if (!$src) {
                 continue;
             }
             if (0 !== strpos($src, $categoryDir) || strlen($src) <= strlen($categoryDir)) {
                 continue;
             }
             @unlink($src);
             $image[$imageType]['src'] = '';
         }
     }
     // save category
     $data = array('status' => $this->_getParam('status', 'enabled'), 'image_base' => $image['base']['src'], 'image_listing' => $image['listing']['src']);
     if ($categoryId) {
         $data['modified_on'] = Axis_Date::now()->toSQLString();
         $modelCategory->update($data, array($this->db->quoteInto('id = ?', $categoryId)));
         $event = 'catalog_category_update_success';
     } else {
         $data['created_on'] = Axis_Date::now()->toSQLString();
         $categoryId = $modelCategory->insertItem($data, $parentId);
         $event = 'catalog_category_add_success';
     }
     Axis::dispatch($event, array('category_id' => $categoryId, 'data' => $data));
     if (!$categoryId) {
         Axis::message()->addError('Unable to save category');
         return $this->_helper->json->sendFailure();
     }
     /* Save category description */
     $categoryName = $this->_getParam('name');
     $categoryDescription = $this->_getParam('description');
     $metaTitle = $this->_getParam('meta_title');
     $metaDescription = $this->_getParam('meta_description');
     $metaKeyword = $this->_getParam('meta_keyword');
     $mCategoryDescription = Axis::model('catalog/category_description');
     foreach (Axis::model('locale/option_language') as $languageId => $_n) {
         if (!isset($categoryName[$languageId])) {
             continue;
         }
         $row = $mCategoryDescription->save(array('category_id' => $categoryId, 'language_id' => $languageId, 'name' => $categoryName[$languageId], 'description' => $categoryDescription[$languageId], 'meta_title' => $metaTitle[$languageId], 'meta_description' => $metaDescription[$languageId], 'meta_keyword' => $metaKeyword[$languageId], 'image_base_title' => $image['base']['title'][$languageId], 'image_listing_title' => $image['listing']['title'][$languageId]));
         if (!$row) {
             return $this->_helper->json->sendFailure();
         }
     }
     /* Save Human Url */
     $modelHurl->delete(array($this->db->quoteInto('key_id = ?', $categoryId), $this->db->quoteInto('key_type = ?', 'c')));
     if (!empty($catKeyWord)) {
         $hurlSuccess = $modelHurl->save(array('key_word' => $catKeyWord, 'key_type' => 'c', 'site_id' => $siteId, 'key_id' => $categoryId));
         if (!$hurlSuccess) {
             return $this->_helper->json->sendFailure();
         }
     }
     Axis::message()->addSuccess(Axis::translate('catalog')->__('Category successfully saved'));
     return $this->_helper->json->setData(array('category_id' => $categoryId))->sendSuccess();
 }
예제 #26
0
 /**
  *
  * @param int $categoryId
  * @param int $limit
  * @param string $date
  * @param int $siteId
  * @return array of int
  */
 public function getSpecialProducts($categoryId = null, $limit = 1, $date = null, $siteId = null)
 {
     if (null === $siteId) {
         $siteId = Axis::getSiteId();
     }
     if (null === $date) {
         $date = Axis_Date::now()->toPhpString("Y-m-d");
     }
     $select = $this->select('de2.value')->distinct()->join('discount_eav', "de.discount_id = d.id AND de.entity = 'special' AND de.value = '1'")->join('discount_eav', "de2.discount_id = d.id AND de2.entity = 'productId'")->where('d.is_active = 1')->where('d.from_date <= ? OR d.from_date IS NULL', $date)->where('? <= d.to_date OR d.to_date IS NULL', $date)->order(array('d.from_date DESC', 'cp.id DESC'))->limit($limit)->join('catalog_product_category', 'de2.value = cpc.product_id')->join('catalog_category', 'cpc.category_id = cc.id')->where('cc.site_id = ?', $siteId)->join('catalog_product', 'de2.value = cp.id');
     if ($disabledCategories = Axis::single('catalog/category')->getDisabledIds()) {
         $select->where('cc.id NOT IN (?)', $disabledCategories);
     }
     if (null != $categoryId) {
         $select->where('cpc.category_id = ? ', $categoryId);
     }
     return $select->fetchCol();
 }
예제 #27
0
 /**
  * Add or update customers review
  *
  * @param array $data
  *  (
  *    product_id => int,    required
  *    title => string,      required
  *    pros => string,       required
  *    cons => string,       required
  *    summary => string,    optional
  *    id => int             optional,
  *    status => (pending|approved|disapproved) optional
  *    ratings => array(     optional
  *      [1] => double,      rating_id => rating_mark pair
  *      ...
  *    )
  *  )
  * @return Axis_Db_Table_Row
  */
 public function save(array $data)
 {
     $row = $this->getRow($data);
     $customer = null;
     if (!empty($row->customer_id)) {
         $customer = Axis::single('account/customer')->find($row->customer_id)->current();
     }
     if (!$customer) {
         $row->customer_id = new Zend_Db_Expr('NULL');
     }
     if (empty($row->status)) {
         $row->status = $this->getDefaultStatus();
     }
     if (empty($row->date_created)) {
         $row->date_created = Axis_Date::now()->toSQLString();
     }
     $row->save();
     return $row;
 }
예제 #28
0
 public function saveAction()
 {
     $this->_helper->layout->disableLayout();
     $quistionIds = $this->_getParam('questionId');
     $questionId = current($quistionIds);
     $modelPollVote = Axis::single('poll/vote');
     $oldCookieValues = $modelPollVote->getQuestionIdsFromCookie();
     $inCookie = in_array($questionId, $oldCookieValues);
     if (!$inCookie) {
         $modelPollVote->addToCookie($questionId, $this->view->baseUrl());
     }
     if ($inCookie || $modelPollVote->hasVoteInTable($questionId)) {
         Axis::message()->addError(Axis::translate('poll')->__('You have voted in this poll already'));
         if ($this->_request->isXmlHttpRequest()) {
             return $this->_ajaxSaveResponse($questionId);
         }
         $this->_redirect($this->getRequest()->getServer('HTTP_REFERER'));
     }
     $customerId = Axis::getCustomerId();
     $data = array('ip' => ip2long($this->getRequest()->getServer('REMOTE_ADDR')), 'created_at' => Axis_Date::now()->toSQLString(), 'visitor_id' => Axis::single('log/visitor')->getVisitor()->id, 'customer_id' => $customerId ? $customerId : new Zend_Db_Expr('NULL'));
     $votes = $this->_getParam('vote');
     $isMulti = Axis::single('poll/question')->find($questionId)->current()->isMultiQuestion();
     $modelAnswer = Axis::single('poll/answer');
     if (!empty($votes)) {
         foreach ($votes as $voteId) {
             //  checking answer depend.. question
             if ($modelAnswer->getAttitude($questionId, $voteId)) {
                 $data['answer_id'] = $voteId;
                 $modelPollVote->insert($data);
             }
             if (!$isMulti) {
                 break;
             }
         }
     }
     if ($this->_request->isXmlHttpRequest()) {
         return $this->_ajaxSaveResponse($questionId);
     }
     $this->_redirect('/poll/index/index/questionId/' . $questionId);
 }
예제 #29
0
 /**
  *
  * @param Axis_Date $date
  * @return Axis_Catalog_Model_Product_Category_Select
  */
 public function addDateAvailableFilter(Axis_Date $date = null)
 {
     if (null === $date) {
         $date = Axis_Date::now();
     }
     return $this->addProductTable()->where('cp.date_available IS NULL OR cp.date_available <= ?', $date->toPhpString('Y-m-d'));
 }
예제 #30
0
 /**
  * Add comment to order(not change order status)
  * Fluent interface
  * @param $comment string
  * @param $notify bool
  * @param $statusId int
  * @return this
  */
 public function addComment($comment, $notify = false, $statusId = null)
 {
     if (null === $statusId) {
         $statusId = $this->order_status_id;
     }
     if ($notify) {
         $notify = $this->_notify($comment);
     }
     Axis::single('sales/order_status_history')->insert(array('order_id' => $this->id, 'order_status_id' => $statusId, 'created_on' => Axis_Date::now()->toSQLString(), 'notified' => (int) $notify, 'comments' => $comment));
     return $this;
 }