2013-10-20 59 views
0

將Magento從1.7升級到1.8(帶有一些第三個擴展程序)後,我無法再保存產品。每當我保存的產品,我得到這個錯誤:這個Magento查詢有什麼問題?

SQL錯誤:SQLSTATE [21S01]:插入值列表不匹配列列表:1136列數並不在行1

匹配值計數通過調試技術,我能找到的錯誤查詢:

SQL查詢:

INSERT INTO `catalogrule_product_price` 
SELECT NULL AS `rule_product_price_id`, 
`dates`.`rule_date`, 
`t`.`customer_group_id`, 
`t`.`product_id`, 
MIN(rule_price) AS `rule_price`, 
1 AS `website_id`, 
`t`.`latest_start_date`, 
`t`.`earliest_end_date` 
FROM 
(SELECT `cppt`.`customer_group_id`, 
`cppt`.`product_id`, 
CASE WHEN IFNULL((@group_id), 'N/A') != cppt.grouped_id THEN @price := CASE `cppt`.`action_operator` WHEN 'to_percent' THEN cppt.price * cppt.action_amount/100 WHEN 'by_percent' THEN cppt.price * (1 - cppt.action_amount/100) WHEN 'to_fixed' THEN IF((cppt.action_amount < cppt.price), cppt.action_amount, cppt.price) WHEN 'by_fixed' THEN IF((0 > cppt.price - cppt.action_amount), 0, cppt.price - cppt.action_amount) END WHEN IFNULL((@group_id), 'N/A') = cppt.grouped_id AND IFNULL((@action_stop), 0) = 0 THEN @price := CASE `cppt`.`action_operator` WHEN 'to_percent' THEN @price * cppt.action_amount/100 WHEN 'by_percent' THEN @price * (1 - cppt.action_amount/100) WHEN 'to_fixed' THEN IF((cppt.action_amount < @price), cppt.action_amount, @price) WHEN 'by_fixed' THEN IF((0 > @price - cppt.action_amount), 0, @price - cppt.action_amount) END ELSE @price := @price END AS `rule_price`, `cppt`.`from_date` AS `latest_start_date`, `cppt`.`to_date` AS `earliest_end_date`, CASE WHEN IFNULL((@group_id), 'N/A') != cppt.grouped_id THEN @action_stop := cppt.action_stop WHEN IFNULL((@group_id), 'N/A') = cppt.grouped_id THEN @action_stop := IFNULL((@action_stop), 0) + cppt.action_stop END, @group_id := cppt.grouped_id, 
`cppt`.`from_time`, 
`cppt`.`to_time` 
FROM 
`catalogrule_product_price_tmp` AS `cppt` 
ORDER BY `cppt`.`grouped_id` ASC, 
`cppt`.`sort_order` ASC, 
`cppt`.`rule_product_id` ASC) AS `t` INNER JOIN (SELECT DATE_ADD(FROM_UNIXTIME(1382202000), INTERVAL -1 DAY) AS rule_date UNION SELECT FROM_UNIXTIME(1382202000) AS rule_date UNION SELECT DATE_ADD(FROM_UNIXTIME(1382202000), INTERVAL 1 DAY) AS rule_date) AS `dates` ON 1=1 WHERE (UNIX_TIMESTAMP(dates.rule_date) >= from_time) AND (IF((to_time = 0), 1, UNIX_TIMESTAMP(dates.rule_date) <= to_time)) 
GROUP BY `customer_group_id`, `product_id`, `dates`.`rule_date`; 

你能指出我爲什麼這個查詢具有錯誤?謝謝!

UPDATE:原因是TBT獎勵模塊在catalogrule_product_price表中添加了名爲「rules_hash」的列。

+0

怎麼沒喲你解決它? –

回答

0

您是否確定了哪個擴展名正在生成該查詢?看起來插入語句沒有考慮catalogrule_product_price表中的任何新字段。您可以通過限制INSERT到特定的列修復:

INSERT INTO `catalogrule_product_price` 
VALUES (rule_product_price_id, rule_date, customer_group_id, product_id, rule_price, website_id, latest_start_date, earliest_end_date) 
SELECT NULL AS `rule_product_price_id`, 
`dates`.`rule_date`, 
`t`.`customer_group_id`, 
`t`.`product_id`, 
MIN(rule_price) AS `rule_price`, 
1 AS `website_id`, 
`t`.`latest_start_date`, 
`t`.`earliest_end_date` 
FROM 
(SELECT `cppt`.`customer_group_id`, 
`cppt`.`product_id`, 
CASE WHEN IFNULL((@group_id), 'N/A') != cppt.grouped_id THEN @price := CASE `cppt`.`action_operator` WHEN 'to_percent' THEN cppt.price * cppt.action_amount/100 WHEN 'by_percent' THEN cppt.price * (1 - cppt.action_amount/100) WHEN 'to_fixed' THEN IF((cppt.action_amount < cppt.price), cppt.action_amount, cppt.price) WHEN 'by_fixed' THEN IF((0 > cppt.price - cppt.action_amount), 0, cppt.price - cppt.action_amount) END WHEN IFNULL((@group_id), 'N/A') = cppt.grouped_id AND IFNULL((@action_stop), 0) = 0 THEN @price := CASE `cppt`.`action_operator` WHEN 'to_percent' THEN @price * cppt.action_amount/100 WHEN 'by_percent' THEN @price * (1 - cppt.action_amount/100) WHEN 'to_fixed' THEN IF((cppt.action_amount < @price), cppt.action_amount, @price) WHEN 'by_fixed' THEN IF((0 > @price - cppt.action_amount), 0, @price - cppt.action_amount) END ELSE @price := @price END AS `rule_price`, `cppt`.`from_date` AS `latest_start_date`, `cppt`.`to_date` AS `earliest_end_date`, CASE WHEN IFNULL((@group_id), 'N/A') != cppt.grouped_id THEN @action_stop := cppt.action_stop WHEN IFNULL((@group_id), 'N/A') = cppt.grouped_id THEN @action_stop := IFNULL((@action_stop), 0) + cppt.action_stop END, @group_id := cppt.grouped_id, 
`cppt`.`from_time`, 
`cppt`.`to_time` 
FROM 
`catalogrule_product_price_tmp` AS `cppt` 
ORDER BY `cppt`.`grouped_id` ASC, 
`cppt`.`sort_order` ASC, 
`cppt`.`rule_product_id` ASC) AS `t` INNER JOIN (SELECT DATE_ADD(FROM_UNIXTIME(1382202000), INTERVAL -1 DAY) AS rule_date UNION SELECT FROM_UNIXTIME(1382202000) AS rule_date UNION SELECT DATE_ADD(FROM_UNIXTIME(1382202000), INTERVAL 1 DAY) AS rule_date) AS `dates` ON 1=1 WHERE (UNIX_TIMESTAMP(dates.rule_date) >= from_time) AND (IF((to_time = 0), 1, UNIX_TIMESTAMP(dates.rule_date) <= to_time)) 
GROUP BY `customer_group_id`, `product_id`, `dates`.`rule_date`; 
1

已經剛剛升級到1.9.2.2一個朋友的網站,並運行到這個問題,我把下面的補丁,而不是文件中,

[magento/app/code/core/Mage /目錄規則/型號/動作/索引/ Refresh.php]

我不能說什麼流量效應可能會有,未來的更新必須小心不要錯過此功能如果這個文件被覆蓋當然,但要開始添加行:

'rules_hash'   => new Zend_Db_Expr('NULL'), 

使select語句如下所示:

$select = $this->_connection->select() 
     ->from($indexSelect, array()) 
     ->joinInner(
      array(
       'dates' => $this->_connection->select()->union(
        array(
         new Zend_Db_Expr(
          'SELECT ' . $this->_connection->getDateAddSql(
           $this->_connection->fromUnixtime($time), 
           -1, 
           Varien_Db_Adapter_Interface::INTERVAL_DAY 
          ) . ' AS rule_date' 
         ), 
         new Zend_Db_Expr('SELECT ' . $this->_connection->fromUnixtime($time) . ' AS rule_date'), 
         new Zend_Db_Expr(
          'SELECT ' . $this->_connection->getDateAddSql(
           $this->_connection->fromUnixtime($time), 
           1, 
           Varien_Db_Adapter_Interface::INTERVAL_DAY 
          ) . ' AS rule_date' 
         ), 
        ) 
       ) 
      ), 
      '1=1', 
      array() 
     ) 
     ->columns(
      array(
       'rule_product_price_id' => new Zend_Db_Expr('NULL'), 
       'rule_date'    => 'dates.rule_date', 
       'customer_group_id'  => 'customer_group_id', 
       'product_id'   => 'product_id', 
       'rule_price'   => 'MIN(rule_price)', 
       'website_id'   => new Zend_Db_Expr($website->getId()), 
       'latest_start_date'  => 'latest_start_date', 
       'earliest_end_date'  => 'earliest_end_date', 
       /** 
       Added because rules_hash was created by some module and not handled properly, 
       see http://stackoverflow.com/questions/19480415/whats-wrong-with-this-magento-query 
       */ 
       'rules_hash'   => new Zend_Db_Expr('NULL'), 
      ) 
     ) 
     ->where(new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " >= from_time")) 
     ->where(
      $this->_connection->getCheckSql(
       new Zend_Db_Expr('to_time = 0'), 
       new Zend_Db_Expr(1), 
       new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " <= to_time") 
      ) 
     ) 
     ->group(array('customer_group_id', 'product_id', 'dates.rule_date')); 

    return $select; 
1

關注@Dale Holborow也替換下面的代碼在應用程序\代碼\社區\ TBT \獎勵\型號\觀察員\目錄\產品\平板\更新\ Product.php

if ($product) { 
     $target_product_id = $product->getEntityId(); 
     if (! $target_product_id) 
      $target_product_id = null; 

    //if no product id 
    //available, reset our assumption because this must be some other 
    //unrecognized request. 
    } 

更換

if ($product) { 
     if ($product instanceof Mage_Catalog_Model_Product) { 
      $target_product_id = $product->getEntityId(); 
     } elseif(is_numeric($product)) { 
      $target_product_id = $product; 
     } 

     if (! $target_product_id) 
      $target_product_id = null; 
    }