문제

Magento-Backend에서 자신의 제품 속성 "높이"를 만들었습니다. 입력 유형은 "텍스트"(비슷한 유형의 "float"가 없었기 때문에)입니다. 이 속성을 필터로 사용하려면 작은 확장자를 썼습니다. 이 확장에서는

로 제품을 필터링합니다.
$this->_productCollection->addAttributeToFilter('height', array('lteq' => $height) );
.

제품 높이가 69cm (69.00)이고 필터는 "<= 80cm"(LTEQ 80.00)입니다. 필터가 잘 작동합니다. 그러나 필터가 "<= 100cm"(LTEQ 100.00) 인 경우에는 작동하지 않습니다. 이것은 Magento가 Height-Attribute를 VARCHAR로 생성하므로 AddAttributetofilter 함수는 String-Compare를 비교합니다. 문자열 비교 "69"는 "6"이 "1"보다 큰 경우 "100"입니다.

은 addattributetofilter를 문자열 대신 값을 숫자로 비교 해야하는

(속성을 삭제하고 확장자를 통해 "float"유형이있는 새로운 방법을 만드는 것이 가장 좋습니다. 그러나 가게는 거의 완성되고 이미 제품이 포함되어있어 "큰"변화를 피하고 싶습니다. 이 상태에서.)

도움이 되었습니까?

해결책

TextPart와 Prateek의 코멘트

PHP

가 아닌 mysql 비교가 될 것입니다.

필드 유형을 변경하지 않고 해결책으로 인도했습니다. _getProductCollection 에서 MAGE_CATALOG_BLOCK_PRODUCT_LIST 에 대한 코드를 다음과 같이 변경했습니다. :

...
if(isset($_GET['height']) && ''!=trim($_GET['height'])){

    // this line adds the attribute "height" to the query (without this line we couln't use the field in our own constraint) 
    $this->_productCollection->addAttributeToFilter('height', array('gteq' => 0) );     

    // we are in search (in search there is an additional height-table with the name at_height_default)
    if(false!==strpos($this->_productCollection->getSelect(), 'at_height_default')){
        $this->_productCollection->getSelect()->where(new Zend_Db_Expr(
            "CAST(IF(at_height.value_id > 0, at_height.value, at_height_default.value) AS DECIMAL(9,2)) <= ".(float) $height
        )); 
    }
    // we are in normal list-view (here the height-table has the name at_height)
    else{
        $this->_productCollection->getSelect()->where(new Zend_Db_Expr(
            "CAST(at_height.value AS DECIMAL(9,2)) <= ".(float) $height
        ));
    }
}
...
.

물론 코어에서 코드를 변경하지 않았습니다.내 확장명의 함수를 덮어 씁니다.Typecast 때문에 값은 문자열 대신 숫자로 비교됩니다. 가장 깨끗한 해결책이 아니라 순간에 저를 위해 알 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top