2013/07/22

Magento ce 1.8, ee 1.13 no seo product url after magmi import

新版不再用CORE_URL_WRITE

URL KEY 的TABLE獨立抽出存在

catalog_product_entity_url_key (不可DEL)


之後RUN REINDEX 會把這些RECORD 轉存到
enterprise_catalog_product_
rewrite,

換言之, 若果SKU 不存在於catalog_product_entity_url_key  , 即使REINDEX 完佢亦都不會存於enterprise_catalog_product_rewrite
但問題是經MAGMI IMPORT的產品, 並沒有儲URL KEY到catalog_product_entity_
url_key ...
所以就寫了一段SCRIPT, 把逐個SKU 的URL-KEY INSERT到  catalog_product_entity_
url_key  , 當然是會加上CHECKING, 當不存在此URL-KEY才INSERT


 <code>
<?php
include_once('app/Mage.php');
Mage::app();
echo 'go';
$dbHandle          = Mage::getSingleton('core/resource')->getConnection('core_write');
$productCounter    = 0;
$nameFixCounter    = 0;
$vUrlKeyFixCounter = 0;
$urlPathCounter    = 0;
$urlKeyCounter     = 0;
$productCollection = $dbHandle->query("SELECT entity_id, sku FROM catalog_product_entity where sku not like '%EP' and sku not in (SELECT value FROM catalog_product_entity_url_key ) order by entity_id desc");

$limit =1000000;
$i = 0;
print'<pre>';
while($i<=$limit && $product = $productCollection->fetch()) {
   
    //if (preg_match("/EP/i",$product['sku'])) continue;
   
  $dataString       = null;

  $key_exist   = $dbHandle->query("SELECT value FROM catalog_product_entity_url_key WHERE  entity_id = '".$product['entity_id']."'")->fetch();
 
  if (!empty($key_exist)){
    print_r( $key_exist);
  } else {
 
    //echo 'no - '.$product['sku'];
    //echo '<br/>';
    //INSERT INTO `catalog_product_entity_url_key` (`value_id`, `entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (132441, 4, 97, 0, 1506165, '9789620433139');
    try
    {
        echo 'insert - '. $product['entity_id'];
        $dbHandle->query("INSERT INTO `catalog_product_entity_url_key` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (4, 97, 0, ".$product['entity_id'].", '".$product['sku']."')")
        ->fetch();
       
    }
    catch(Exception $e)
    {
        //echo '<p style="color:red;">'.$e -> getMessage().'</p>';
    }
   
  }
 
 
  $i++;
  }
</code>

沒有留言:

發佈留言