/** * * @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); }
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(); }
/** * 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; }
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)); }
/** * * @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); }
/** * 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; }
/** * * @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(); }
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(); }
/** * 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; }
/** * @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); }
/** * * @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; }
public function changeAction() { $this->setTitle(Axis::translate('account')->__('Change Info')); $form = Axis::single('account/Form_ChangeInfo'); if ($this->_request->isPost()) { $data = $this->_request->getPost(); if ($data['change_password_toggle'] == 0) { $form->getElement('password_current')->clearValidators(); // removeValidator('NotEmpty'); $form->getElement('password')->clearValidators(); //removeValidator('NotEmpty'); $form->getElement('password_confirm')->clearValidators(); //removeValidator('NotEmpty'); } if ($form->isValid($data)) { $model = Axis::single('account/customer'); $row = $model->find(Axis::getCustomerId())->current(); if (empty($data['password'])) { unset($data['password']); } else { $data['password'] = md5($data['password']); } $row->setFromArray($data); $row->modified_at = Axis_Date::now()->toSQLString(); $row->save(); $row->setDetails($data); Axis::message()->addSuccess(Axis::translate('Axis_Core')->__('Data was saved successfully')); } } else { $data = array(); $customer = Axis::getCustomer(); $extraInfo = $customer->findDependentRowset('Axis_Account_Model_Customer_Detail'); $data = $customer->toArray(); foreach ($extraInfo as $row) { $value = empty($row->data) ? $row->customer_valueset_value_id : $row->data; $isMulti = isset($data['field_' . $row->customer_field_id]); if ($isMulti && is_array($data['field_' . $row->customer_field_id])) { $data['field_' . $row->customer_field_id][] = $value; } elseif ($isMulti) { $data['field_' . $row->customer_field_id] = array($data['field_' . $row->customer_field_id], $value); } else { $data['field_' . $row->customer_field_id] = $value; } } } $form->populate($data); $this->view->form = $form; $this->render(); }
protected function _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; }
/** * * @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); }
/** * * @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); }
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(); }
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(); }
/** * 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; }
/** * * @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')); }
/** * 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(); }
/** * * @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(); }
protected function _getStartDate($type, $period = 0, $time = null) { if (null === $time) { $time = Axis_Date::now(); } $time->setMinute(0)->setSecond(0)->setMilliSecond(0); $period = $period > 0 ? $period : 0; switch (strtolower($type)) { case 'hour': $time->subHour($period); break; case 'week': $time->subDay(date('w') + $period * 7)->setHour(0); break; case 'month': $time->subMonth($period)->setDay(1)->setHour(0); break; case 'year': $time->subYear($period)->setMonth(1)->setDay(1)->setHour(0); break; case 'day': default: $time->subDay($period)->setHour(0); } return $time; }
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; }
/** * 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; }
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(); }
/** * Create order, and clears shopping cart after that * * @return Axis_Sales_Model_Order_Row * @throws Axis_Exception */ public function createFromCheckout() { /** * @var Axis_Checkout_Model_Checkout $checkout */ $checkout = Axis::single('checkout/checkout'); if (!$checkout->getCart()->validateContent()) { throw new Axis_Exception(); } $orderRow = $this->createRow(); $storage = $checkout->getStorage(); if ($customer = Axis::getCustomer()) { $orderRow->customer_id = $customer->id; $orderRow->customer_email = $customer->email; } else { $orderRow->customer_email = $checkout->getBilling()->email; } $orderRow->site_id = Axis::getSiteId(); $orderRow->payment_method = $checkout->payment()->getTitle(); $orderRow->payment_method_code = $checkout->payment()->getCode(); $orderRow->shipping_method = $checkout->shipping()->getTitle(); $orderRow->shipping_method_code = $checkout->shipping()->getCode(); $orderRow->date_purchased_on = Axis_Date::now()->toSQLString(); $orderRow->currency = Axis::single('locale/currency')->getCode(); $orderRow->currency_rate = Axis::single('locale/currency')->getData($orderRow->currency, 'rate'); $orderRow->order_total = $checkout->getTotal()->getTotal(); $orderRow->txn_id = 0; //@todo $orderRow->order_status_id = 0; $orderRow->ip_address = $_SERVER['REMOTE_ADDR']; $orderRow->customer_comment = $storage->customer_comment; $orderRow->locale = Axis_Locale::getLocale()->toString(); /* build delivery & billing arrays */ $addressFormatId = Axis::config('core/store/addressFormat'); $delivery = $checkout->getDelivery()->toArray(); $delivery['country'] = isset($delivery['country']['name']) ? $delivery['country']['name'] : ''; if (isset($delivery['zone']['name'])) { $delivery['state'] = $delivery['zone']['name']; } $delivery['address_format_id'] = $addressFormatId; $billing = $checkout->getBilling()->toArray(); $billing['country'] = isset($billing['country']['name']) ? $billing['country']['name'] : ''; if (isset($billing['zone']['name'])) { $billing['state'] = $billing['zone']['name']; } $billing['address_format_id'] = $addressFormatId; unset($billing['id'], $delivery['id']); foreach ($delivery as $key => $value) { $delivery['delivery_' . $key] = $value; } foreach ($billing as $key => $value) { $billing['billing_' . $key] = $value; } $orderRow->setFromArray($delivery); $orderRow->setFromArray($billing); /* Save order (auto generate number ) */ $orderRow->save(); /* Add products to order and change quantity */ $modelOrderProduct = Axis::single('sales/order_product'); foreach ($checkout->getCart()->getProducts() as $product) { $modelOrderProduct->add($product, $orderRow->id); } /* Add total info */ $total = $checkout->getTotal(); $orderTotal = Axis::single('sales/order_total'); foreach ($total->getCollects() as $collect) { $orderTotal->insert(array('order_id' => $orderRow->id, 'code' => $collect['code'], 'title' => $collect['title'], 'value' => $collect['total'])); } // update product stock $orderRow->setStatus('pending'); return $orderRow; }
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); }
/** * 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; }
/** * * @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; }
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']++; }