簡體   English   中英

Drupal 7-Ubercart-視圖字段中的屬性

[英]Drupal 7 - Ubercart - Attributes in Views Fields

我的產品具有“顏色”和“強度”的屬性。 我正在嘗試將那些屬性下列出的那些選項作為視圖的字段,以便可以將它們用作過濾器。 因此,例如按顏色和強度排序。

我在Google上四處查看,只能找到Drupal 6的模塊。有人知道7的任何內容嗎?

就像上一篇文章中所說的,我有2個屬性“顏色”和“強度”,我需要對其進行匹配以進行精確的產品匹配,但是ubercart沒有任何屬性,因此我將它們寫到URL的get語句中,作為變量1和2 ,例如,同時選擇了兩個屬性的網址如下所示:

www.website.com/node/68?1=96&2=7

有時會設置一個變量,而不會設置其他變量,因此我還必須使用%通配符來彌補這一點。 這是該部分的代碼

//  Since PHP's serialize function sometimes serializes in the incorrect order,
//  here we manually build the comparison key
//  Additionally append the image links urls with provided strength/color data

if( isset( $_REQUEST['1'] ) ) {
    $_1 = $_REQUEST['1'];
    if( $_1 !== '%' ) $url[] = "1=$_1";
} else $_1 = '%';

if( isset( $_REQUEST['2'] ) ) {
    $_2 = $_REQUEST['2'];
    if( $_2 !== '%' ) $url[] = "2=$_2";
} else $_2 = '%';

$combination = "a:2:{i:1;s:";
$combination .= $_1 == '%' ? '%:"%";' : strlen($_1) . ':"' . $_1 . '";';
$combination .= "i:2;s:";
$combination .= $_2 == '%' ? '%:"%";' : strlen($_2) . ':"' . $_2 . '";';
$combination .= '}';

// if some products don't have a second attribute at all
$combination2 = "a:1:{i:1;s:";
$combination2 .= $_1 == '%' ? '%:"%"' : strlen($_1) . ':"' . $_1 . '";';
$combination2 .= ';}';

在此之下,我必須進行一些額外的查詢,例如是否設置了分類法,並檢查是否設置了一些動態屬性,這就是為什么WHERE存儲在變量中的原因。 坦率地說,他們只會使任何人感到困惑,所以我將其排除在外。 但是為您着想,下一部分您只需要查詢它。

$where = "WHERE (pa.combination LIKE :pattern1 OR pa.combination LIKE :pattern2) AND s.stock IS NOT NULL";
$comparison = array( ':pattern1' => $combination,
                     ':pattern2' => $combination2 );

$filtered = db_query(
    "
        SELECT pa.nid, pa.model, pa.combination, n.title, p.sell_price, f.uri
        FROM {uc_product_adjustments} pa
        LEFT JOIN {node} n ON pa.nid = n.nid
        LEFT JOIN {uc_products} p ON pa.nid = p.nid
        LEFT JOIN {field_data_uc_product_image} i ON i.entity_type = 'node' AND i.entity_id = n.nid
        LEFT JOIN {file_managed} f ON f.fid = i.uc_product_image_fid
        LEFT JOIN {uc_product_stock} s ON pa.model = s.sku AND s.stock <> '0'
        $where
    ",
    $comparison
);

最后遍歷結果並將它們存儲在普通數組中

foreach( $filtered as $i => $record ) {
    if( is_int( array_search( $record->nid, $nids ) ) ) continue;
    else {
        $nids[] = $record->nid;
        $result[] = $record;
    }
}

此代碼檢查與當前庫存中的任何屬性值匹配的任何產品

您可以看一下以下沙箱項目: UC視圖屬性工作UC屬性視圖

我正在尋找類似的功能,因為似乎無法將UC屬性添加到視圖中。 我無法測試自己,因為我本周末有一個項目的截止日期,但很高興收到您的反饋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM