Ejemplo n.º 1
0
 /**
  * Execute multiqueries
  *
  * @param string $sql
  * @return Axis_Install_Model_Installer provides fluent interface
  * @throws Exception
  */
 public function run($sql)
 {
     $tries = 0;
     $stmts = $this->_splitMultiQuery($sql);
     foreach ($stmts as $stmt) {
         do {
             $retry = false;
             try {
                 // skip commented queries
                 if (0 === strpos($stmt, '--') || 0 === strpos($stmt, '/*')) {
                     continue;
                 }
                 Axis::db()->getConnection()->exec($stmt);
             } catch (Exception $e) {
                 if ($e->getMessage() == 'SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query' && $tries < 10) {
                     $retry = true;
                     $tries++;
                 } else {
                     //                        Axis::message()->addError($e->getTraceAsString());
                     Axis::message()->addError($e->getMessage());
                     throw $e;
                 }
             }
         } while ($retry);
     }
     return $this;
 }
Ejemplo n.º 2
0
 public function removeAction()
 {
     $id = $this->_getParam('id');
     Axis::model('cms/category')->delete(Axis::db()->quoteInto('id IN(?)', $id));
     Axis::message()->addSuccess(Axis::translate('cms')->__('Category was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
Ejemplo n.º 3
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));
     }
 }
Ejemplo n.º 4
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     $db = Axis::db();
     $this->setAttrib('id', 'form-customer');
     $this->addElement('select', 'site_id', array('label' => 'Site'));
     $this->getElement('site_id')->setMultiOptions(Axis::model('core/option_site')->toArray());
     $this->addElement('text', 'email', array('required' => true, 'label' => 'Email'));
     $this->addElement('password', 'password', array('label' => 'Password'));
     $this->addElement('text', 'firstname', array('required' => true, 'label' => 'Firstname', 'class' => 'input-text required'));
     $this->addElement('text', 'lastname', array('required' => true, 'label' => 'Lastname', 'class' => 'input-text required'));
     $this->addElement('checkbox', 'is_active', array('label' => 'Active'));
     $this->addDisplayGroup(array('site_id', 'email', 'password', 'firstname', 'lastname', 'is_active'), 'login', array('legend' => 'General information'));
     $rows = Axis::single('account/customer_field')->getFields();
     $groupsFields = array();
     foreach ($rows as $row) {
         $field = 'field_' . $row['id'];
         $this->addElement($row['field_type'], $field, array('required' => (bool) $row['required'], 'label' => $row['field_label']));
         if ($row['required']) {
             $this->getElement($field)->addValidator('NotEmpty');
         }
         if (!empty($row['validator'])) {
             $this->getElement($field)->addValidator($row['validator']);
             if ($row['validator'] == 'Date') {
                 $this->getElement($field)->setAttrib('class', 'date-picker');
             }
         }
         if (isset($row['customer_valueset_id'])) {
             $values = Axis::single('account/Customer_ValueSet_Value')->getCustomValues($row['customer_valueset_id'], Axis_Locale::getLanguageId());
             $this->getElement($field)->setMultiOptions($values);
         }
         $groupsFields[$row['customer_field_group_id']][$row['id']] = $field;
     }
     /* add field groups */
     if (count($groupsFields)) {
         $groups = Axis::single('account/customer_fieldGroup')->getCustomGroups(array_keys($groupsFields), Axis_Locale::getLanguageId());
         foreach ($groups as $row) {
             $this->addDisplayGroup(array_values($groupsFields[$row['id']]), 'group_' . $row['id'], array('legend' => $row['group_label']));
             $this->getDisplayGroup('group_' . $row['id'])->setDisableTranslator(true);
         }
     }
 }
Ejemplo n.º 5
0
 protected function _isEmailValid($email, $siteId, $customerId = null)
 {
     $where = Axis::db()->quoteInto('site_id = ?', $siteId);
     if (null !== $customerId) {
         $where .= Axis::db()->quoteInto(' AND id <> ?', $customerId);
     }
     $validator = new Axis_Validate_Exists(Axis::single('account/customer'), 'email', $where);
     if (!$validator->isValid($email)) {
         foreach ($validator->getMessages() as $message) {
             Axis::message()->addError($message);
         }
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     Axis::model('cms/page')->delete(Axis::db()->quoteInto('id IN (?)', $data));
     Axis::message()->addSuccess(Axis::translate('cms')->__('Page was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
Ejemplo n.º 7
0
 public function addProductAction()
 {
     $params = Zend_Json::decode($this->_getParam('data'));
     $data = array();
     foreach ($params as $param) {
         $productId = $param['id'];
         $product = Axis::single('catalog/product')->find($productId)->current();
         if (!$product instanceof Axis_Catalog_Model_Product_Row) {
             Axis::message()->addError(Axis::translate('catalog')->__('Product not found'));
             return $this->_helper->json->sendFailure();
         }
         $quantity = $param['quantity'];
         $variationId = $param['variationId'];
         $orderId = $param['orderId'];
         if (!$product->getStockRow()->canAddToCart($quantity, $variationId)) {
             return $this->_helper->json->sendFailure();
         }
         $stock = Axis::single('catalog/product_stock')->find($productId)->current();
         $modifierAttributes = Axis::single('catalog/product_attribute')->getAttributesByModifiers($product->id, $param['modifiers']);
         $variationAttributes = array_fill_keys(Axis::single('catalog/product_attribute')->select('id')->where('modifier <> 1')->where('product_id = ?', $product->id)->where('variation_id = ?', $variationId)->fetchCol(), null);
         $attributes = $modifierAttributes + $variationAttributes;
         $attributesOptions = array();
         if (!empty($attributes)) {
             $attributesOptions = Axis::single('catalog/product_attribute')->select('id')->join('catalog_product_option_text', 'cpa.option_id = cpot.option_id AND ' . Axis::db()->quoteInto('cpot.language_id = ?', Axis_Locale::getLanguageId()), array('product_option' => 'cpot.name'))->join('catalog_product_option_value_text', 'cpa.option_value_id = cpovt.option_value_id AND ' . Axis::db()->quoteInto('cpovt.language_id = ?', Axis_Locale::getLanguageId()), array('product_option_value' => 'cpovt.name'))->where('id IN(?)', array_keys($attributes))->fetchAll();
         }
         $finalPrice = $product->getPrice(array_keys($attributes));
         $finalWeight = $product->getWeight(array_keys($attributes));
         $countryId = $param['countryId'];
         $zoneId = empty($param['zoneId']) ? 0 : $param['zoneId'];
         $geozoneIds = Axis::single('location/geozone')->getIds($countryId, $zoneId);
         $customerGroupId = $param['customerGroupId'];
         $productTax = Axis::single('tax/rate')->calculateByPrice($finalPrice, $product->tax_class_id, $geozoneIds, $customerGroupId);
         $descriptionRow = $product->getDescription();
         $taxRate = 0;
         if ($finalPrice > 0) {
             $taxRate = $productTax * 100 / $finalPrice;
         }
         $data[] = array('attributes' => $attributesOptions, 'backorder' => $stock->backorder, 'final_price' => $finalPrice, 'final_weight' => $finalWeight, 'order_id' => $orderId, 'product_id' => $product->id, 'name' => $descriptionRow['name'], 'price' => $product->price, 'quantity' => $quantity, 'sku' => $product->sku, 'tax_rate' => $taxRate, 'variation_id' => $variationId);
     }
     return $this->_helper->json->setData($data)->sendSuccess();
 }
Ejemplo n.º 8
0
 /**
  * Run modules installation
  *
  * @return Axis_Install_Model_Wizard Provides fluent interface
  */
 public function run()
 {
     @set_time_limit(300);
     $modelModule = Axis::single('core/module');
     if (!count(Axis::db()->fetchAll("SHOW TABLES LIKE '%core_module'"))) {
         $modelModule->getByCode('Axis_Core')->install();
         $this->_installStore();
         $modelModule->getByCode('Axis_Locale')->install();
         $this->_installLocale();
     }
     foreach ($this->_session->modules as $code) {
         if (!strstr($code, '_')) {
             continue;
         }
         $this->log("Module {$code}:");
         $moduleRow = $modelModule->getByCode($code);
         if ($moduleRow->isInstalled()) {
             $this->log("\tSkipped (already installed)");
             continue;
         }
         $this->log("\tBegin");
         $moduleRow->install();
         $this->log("\tEnd");
     }
     $this->_addUser();
     return $this;
 }
Ejemplo n.º 9
0
 /**
  *
  * @param type $data
  */
 public function setDetails($data)
 {
     $modelDetail = Axis::model('account/customer_detail');
     $modelDetail->delete(Axis::db()->quoteInto('customer_id = ?', $this->id));
     $fields = Axis::single('account/customer_field')->select()->fetchAssoc();
     $multiFields = Axis_Account_Model_Customer_Field::$fieldMulti;
     foreach ($data as $id => $value) {
         if (0 !== strpos($id, 'field_') || empty($value)) {
             continue;
         }
         list(, $id) = explode('_', $id);
         $_row = array('customer_id' => $this->id, 'customer_field_id' => $id);
         $isMultiField = in_array($fields[$id]['field_type'], $multiFields);
         if ($isMultiField && is_string($value) && strpos($value, ',')) {
             $value = explode(',', $value);
         }
         if ($isMultiField && is_array($value)) {
             foreach ($value as $_value) {
                 $row = $modelDetail->createRow($_row);
                 $row->customer_valueset_value_id = $_value;
                 $row->save();
             }
         } elseif ($isMultiField) {
             $row = $modelDetail->createRow($_row);
             $row->customer_valueset_value_id = $value;
             $row->save();
         } else {
             $row = $modelDetail->createRow($_row);
             $row->data = $value;
             $row->save();
         }
     }
 }
Ejemplo n.º 10
0
 public function deleteByIds($ids)
 {
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $success = (bool) $this->delete(Axis::db()->quoteInto('id IN(?)', $ids));
     if (!$success) {
         return false;
     }
     Axis::message()->addSuccess(Axis::translate('catalog')->__('Manufacturer was deleted successfully'));
     Axis::single('catalog/hurl')->delete(Axis::db()->quoteInto("key_type = 'm' AND key_id IN (?)", $ids));
     return $success;
 }
Ejemplo n.º 11
0
 /**
  *  Main init
  */
 public function init()
 {
     parent::init();
     $this->db = Axis::db();
     $this->layout = Axis_Layout::getMvcInstance();
 }
Ejemplo n.º 12
0
 public function dropAction()
 {
     Axis::single('core/cache')->clean();
     /**
      * @var Axis_Install_Model_Installer
      */
     $installer = Axis::single('install/installer');
     $installer->run("\n            SET SQL_MODE='';\n            SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n            SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n        ");
     $tables = Axis::db()->fetchAll('show tables');
     foreach ($tables as $table) {
         $tableName = current($table);
         $installer->run("DROP TABLE `{$tableName}`;");
     }
     Axis::single('install/installer')->run("\n            SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'');\n            SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS,0);\n        ");
     unlink(AXIS_ROOT . '/app/etc/config.php');
     if (!headers_sent()) {
         $host = $_SERVER['HTTP_HOST'];
         $uri = rtrim(dirname(str_replace('/install', '', $_SERVER['PHP_SELF'])), '/\\');
         header("Location: http://{$host}{$uri}/");
     }
     exit;
 }
Ejemplo n.º 13
0
 private function addOrder($entry)
 {
     $_SESSION['processed_count']++;
     if (!isset($_SESSION['customer_relations_array'][$entry['order']['customers_id']])) {
         $_SESSION['message_stack']['skipped (customer not found)'][] = $entry['order']['customers_name'] . ' ' . $entry['order']['customers_email_address'];
         return;
     }
     /**
      * array(
      *  [0] => array(
      *    [lang_id] => array(values)
      *  ),
      *  [1] => ...
      * )
      */
     foreach ($entry['statuses'] as $id => $status) {
         if (!isset($status[$this->_primary_language]) || $status[$this->_primary_language] == '') {
             $current_status = current($status);
             $_SESSION['message_stack']['skipped (status code is undefined)'][] = 'CreLoaded status id: ' . $id;
             continue;
         }
         if (!isset($_SESSION['status_relations_array'][$id])) {
             $duplicate = Axis::db()->fetchOne("SELECT os.id\n                    FROM " . parent::$_db_prefix . parent::ORDER_STATUS . " AS os\n                    WHERE name = ?", $status[$this->_primary_language]);
             if (!$duplicate) {
                 //insert new status
                 $status_id = Axis::single('sales/order_status')->insert(array('name' => $status[$this->_primary_language], 'system' => false));
                 foreach (array_keys($this->_language) as $axis_language) {
                     Axis::single('sales/order_status_text')->insert(array('status_id' => $status_id, 'language_id' => $axis_language, 'status_name' => $status[$this->_language[$axis_language]]));
                 }
             } else {
                 //use existing status
                 $status_id = $duplicate;
                 $_SESSION['message_stack']['skipped statuses (duplicate entry)'][] = $status[$this->_primary_language];
             }
             $_SESSION['status_relations_array'][$id] = $status_id;
         }
     }
     $total = 0;
     $tax = new Zend_Db_Expr('NULL');
     //get order total
     foreach ($entry['total'] as $key => $line) {
         if ($line['title'] == 'Total:') {
             $total = $line['value'];
         }
         if ($line['title'] == 'Tax:') {
             $tax = $line['value'];
         }
     }
     $order = array('customer_id' => $_SESSION['customer_relations_array'][$entry['order']['customers_id']], 'customer_email' => $entry['order']['customers_email_address'], 'delivery_firstname' => $entry['order']['delivery_name'], 'delivery_lastname' => $entry['order']['delivery_name'], 'delivery_phone' => '', 'delivery_fax' => '', 'delivery_company' => $entry['order']['delivery_company'], 'delivery_street_address' => $entry['order']['delivery_street_address'], 'delivery_suburb' => $entry['order']['delivery_suburb'], 'delivery_city' => $entry['order']['delivery_city'], 'delivery_postcode' => $entry['order']['delivery_postcode'], 'delivery_state' => $entry['order']['delivery_state'], 'delivery_country' => $entry['order']['delivery_country'], 'delivery_address_format_id' => $entry['order']['delivery_address_format_id'], 'billing_firstname' => $entry['order']['billing_name'], 'billing_lastname' => $entry['order']['billing_name'], 'billing_phone' => '', 'billing_fax' => '', 'billing_company' => $entry['order']['billing_company'], 'billing_street_address' => $entry['order']['billing_street_address'], 'billing_suburb' => $entry['order']['billing_suburb'], 'billing_city' => $entry['order']['billing_city'], 'billing_postcode' => $entry['order']['billing_postcode'], 'billing_state' => $entry['order']['billing_state'], 'billing_country' => $entry['order']['billing_country'], 'billing_address_format_id' => $entry['order']['billing_address_format_id'], 'payment_method' => $entry['order']['payment_method'], 'payment_method_code' => $this->_prepareString($entry['order']['payment_method'], '', true) . '_Standard', 'shipping_method' => 'Free Shipping', 'shipping_method_code' => 'Free_Standard', 'coupon_code' => new Zend_Db_Expr('NULL'), 'date_modified_on' => new Zend_Db_Expr('NULL'), 'date_purchased_on' => $entry['order']['date_purchased'], 'date_finished_on' => new Zend_Db_Expr('NULL'), 'order_status_id' => $_SESSION['status_relations_array'][$entry['order']['orders_status']], 'currency' => $entry['order']['currency'], 'currency_rate' => $entry['order']['currency_value'], 'order_total' => $total, 'txn_id' => 0, 'ip_address' => $entry['order']['ipaddy'], 'site_id' => $this->_site);
     $order_id = Axis::single('sales/order')->insert($order);
     foreach ($entry['total'] as $line) {
         if ($line['title'] == 'Total:') {
             continue;
         }
         $title = substr($line['title'], 0, -1);
         $code = preg_replace('/\\s+/', '_', trim($title));
         $order_total = array('order_id' => $order_id, 'code' => $code, 'title' => $title, 'value' => $line['value']);
         Axis::single('sales/order_total')->insert($order_total);
     }
     foreach ($entry['status_history'] as $date => $status) {
         $history_data = array('order_id' => $order_id, 'order_status_id' => $_SESSION['status_relations_array'][$status['orders_status_id']], 'created_on' => $date, 'notified' => $status['customer_notified'], 'comments' => $status['comments']);
         Axis::single('sales/order_status_history')->insert($history_data);
     }
     foreach ($entry['products'] as $product) {
         //import product if not imported yet
         if (!isset($_SESSION['product_relations_array'][$product['product']['products_id']])) {
             $entry = $this->getProduct($product['product']['products_id']);
             $this->addProduct($entry);
         }
         $product_id = $_SESSION['product_relations_array'][$product['product']['products_id']];
         //get product sku
         $sku = Axis::single('catalog/product')->getSkuById($product_id);
         //inserting product
         $product_data = array('order_id' => $order_id, 'product_id' => $product_id, 'variation_id' => new Zend_Db_Expr('NULL'), 'sku' => $sku, 'name' => $product['product']['products_name'], 'price' => $product['product']['products_price'], 'final_price' => $product['product']['final_price'], 'tax' => $product['product']['products_tax'], 'quantity' => $product['product']['products_quantity'], 'backorder' => 0);
         $order_product_id = Axis::single('sales/order_product')->insert($product_data);
         if (!count($product['attributes'])) {
             continue;
         }
         //inserting attributes
         foreach ($product['attributes'] as $attribute) {
             $attribute_data = array('order_product_id' => $order_product_id, 'product_option' => $attribute['products_options'], 'product_option_value' => $attribute['products_options_values']);
             Axis::db()->insert(parent::$_db_prefix . parent::ORDER_PRODUCT_ATTRIBUTE, $attribute_data);
         }
     }
     $_SESSION['imported_count']++;
 }
Ejemplo n.º 14
0
 /**
  * Add filter to get products that is not linked to any category
  *
  * @return Axis_Catalog_Model_Product_Select
  */
 public function addFilterByUncategorized()
 {
     $mProductToCategory = Axis::single('catalog/product_category');
     $rootProducts = Axis::db()->quoteInto('cp.id = ANY (?)', $mProductToCategory->select('cpc.product_id')->join('catalog_category', 'cc.id = cpc.category_id')->where('cc.lvl = 0'));
     $notChildProducts = Axis::db()->quoteInto('cp.id <> ALL (?)', $mProductToCategory->select('cpc.product_id')->join('catalog_category', 'cc.id = cpc.category_id')->where('cc.lvl <> 0'));
     $this->where('cp.id <> ALL (?)', $mProductToCategory->select('cpc.product_id'))->orWhere($rootProducts . ' AND ' . $notChildProducts);
     return $this;
 }
Ejemplo n.º 15
0
 protected function _initDbAdapter()
 {
     $this->bootstrap('Config');
     $config = $this->getResource('Config');
     $db = Zend_Db::factory('Pdo_Mysql', array('host' => $config->db->host, 'username' => $config->db->username, 'password' => $config->db->password, 'dbname' => $config->db->dbname, 'charset' => 'UTF8'));
     //Set default adapter for childrens Zend_Db_Table_Abstract
     Zend_Db_Table_Abstract::setDefaultAdapter($db);
     //Axis_Config::setDefaultDbAdapter($db);
     Zend_Registry::set('db', $db);
     return Axis::db();
 }
Ejemplo n.º 16
0
 public function removeLogEventOnCatalogProductRemoveSuccess($data)
 {
     Axis::model('log/event')->delete(array(Axis::db()->quoteInto('event_name = ? ', 'catalog_product_view'), Axis::db()->quoteInto('object_id IN (?)', $data['product_ids'])));
 }
Ejemplo n.º 17
0
 public function batchSaveAction()
 {
     $dataset = Zend_Json::decode($this->_getParam('data'));
     $model = Axis::single('core/template_box');
     $modelAssign = Axis::model('core/template_box_page');
     foreach ($dataset as $data) {
         if (!isset($data['id'])) {
             $data['config'] = '{}';
         }
         $row = $model->getRow($data);
         $row->save();
         $assigns = array_filter(explode(',', $data['page_ids']));
         $_where = array(Axis::db()->quoteInto('box_id = ?', $row->id));
         if (count($assigns)) {
             $_where[] = Axis::db()->quoteInto('page_id NOT IN (?)', $assigns);
         }
         $modelAssign->delete($_where);
         foreach ($assigns as $pageId) {
             $_row = $modelAssign->find($row->id, $pageId)->current();
             if (!$_row) {
                 $_row = $modelAssign->createRow(array('box_id' => $row->id, 'page_id' => $pageId, 'box_show' => 1));
             }
             $_row->save();
         }
     }
     Axis::message()->addSuccess(Axis::translate('core')->__('Box was saved successfully'));
     return $this->_helper->json->sendSuccess();
 }