今日試用了rule based related product , 在一堆product 加上一個attribute " related product code"
再在rule base product 裏面"product to display" 設定上該attribute
但在frontend 一直call不到product...
磨了良久, 最後發覺condition 設定條件時不能選"is" , 要選"contains" ....
估計是有space / trim 空白的問題.......
這不科學啊!
Programming language e.g. PHP, JAVASCRIPT, coding, web developing hints and skills applying on mobile device e.g. iphone
2013/07/30
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
URL KEY 的TABLE獨立抽出存在
catalog_product_entity_url_key (不可DEL)
之後RUN REINDEX 會把這些RECORD 轉存到
enterprise_catalog_product_
換言之, 若果SKU 不存在於catalog_product_entity_
但問題是經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>
2012/08/21
PHP parse_url 不用再自己拆解URL了
曾經用過EXPLODE 和PREG_MATCH慢慢拆開URL...但原來有快方法parse_url
$url = "http://www.electrictoolbox.com/php-extract-domain-from-full-url/";
$parts = parse_url($url);
輸出:
Array
(
[scheme] => http
[host] => www.electrictoolbox.com
[path] => /php-extract-domain-from-full-url/
)
================================================================
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
$url = "http://www.electrictoolbox.com/php-extract-domain-from-full-url/";
$parts = parse_url($url);
輸出:
Array
(
[scheme] => http
[host] => www.electrictoolbox.com
[path] => /php-extract-domain-from-full-url/
)
================================================================
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
2012/08/10
改變地址次序等格式 Customer Address Format
因香港地區問題, 客人需要印出的PDF SLIP 中的姓名欄位根據特定格式展現:
E.G. prefix LAST NAME , firstname
即是本來內置看成Mr Chris Wong 的, 要改成 Mr WONG , Chris
其實要分成兩部份去做
(1) 修改Address template
原來magento 已在backend提供了template 的XML
System->Configuration->Customer->Customers->Customer Configuration->Address Templates
改改排序就可以了
{{depend prefix}}{{var prefix}} {{/depend}}{{var lastname}} {{depend middlename}}{{var middlename}}{{/depend}}, {{var firstname}}
這樣姓氏和名字的次序便倒轉了, 還可在中間加上逗號
(2)override observer "customer_address_format" 把姓氏轉為大寫
簡單先講做法:
在config.xml
<adminhtml>
<events>
<customer_address_format>
<observers>
<cleargo_custom>
<class>Cleargo_Custom_Model_Countryformat</class>
<method>countryFormat</method>
</cleargo_custom>
</observers>
</customer_address_format>
</events>
</adminhtml>
Cleargo/Custom/Model/Countryformat.php
class Cleargo_Custom_Model_Countryformat {
public function countryFormat($observer) {
$event = $observer->getEvent();
$address = $event->getAddress();
$type = $event->getType();
//if($address->getData('country_id') == 'FR'){
$lastname = strtoupper($address->getData('lastname'));
$address->setData('lastname', $lastname);
//}
}
}
順便講講發現既過程
事源我要在PDF 裏更改格式, 於是在order/pdf/shipment.php 發現
$shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
再追尋format這function 是源自Mage_Customer_Model_Address_Abstract
在入面可發現在render address前, dispatch了一個event
Mage::dispatchEvent('customer_address_format', array('type' => $formatType, 'address' => $this));
於是根據magento的dispatchEvent 機制, 我們可輕鬆override observer 以改變程式run到呢行時既data
E.G. prefix LAST NAME , firstname
即是本來內置看成Mr Chris Wong 的, 要改成 Mr WONG , Chris
其實要分成兩部份去做
(1) 修改Address template
原來magento 已在backend提供了template 的XML
System->Configuration->Customer->Customers->Customer Configuration->Address Templates
改改排序就可以了
{{depend prefix}}{{var prefix}} {{/depend}}{{var lastname}} {{depend middlename}}{{var middlename}}{{/depend}}, {{var firstname}}
這樣姓氏和名字的次序便倒轉了, 還可在中間加上逗號
(2)override observer "customer_address_format" 把姓氏轉為大寫
簡單先講做法:
在config.xml
<adminhtml>
<events>
<customer_address_format>
<observers>
<cleargo_custom>
<class>Cleargo_Custom_Model_Countryformat</class>
<method>countryFormat</method>
</cleargo_custom>
</observers>
</customer_address_format>
</events>
</adminhtml>
Cleargo/Custom/Model/Countryformat.php
class Cleargo_Custom_Model_Countryformat {
public function countryFormat($observer) {
$event = $observer->getEvent();
$address = $event->getAddress();
$type = $event->getType();
//if($address->getData('country_id') == 'FR'){
$lastname = strtoupper($address->getData('lastname'));
$address->setData('lastname', $lastname);
//}
}
}
順便講講發現既過程
事源我要在PDF 裏更改格式, 於是在order/pdf/shipment.php 發現
$shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
再追尋format這function 是源自Mage_Customer_Model_Address_Abstract
在入面可發現在render address前, dispatch了一個event
Mage::dispatchEvent('customer_address_format', array('type' => $formatType, 'address' => $this));
於是根據magento的dispatchEvent 機制, 我們可輕鬆override observer 以改變程式run到呢行時既data
訂閱:
文章 (Atom)