1

viewtopic.php?t=7080 よりも高度なものを探しています

在庫がなく、特定のカテゴリにある製品を非表示にする (または無効にする) 必要があります。

この問題が発生したのは、「クリアランス」というカテゴリがあり、売り切れ後に在庫がなくなるため、クリアランスアイテムを自動的に無効にしたいためです. 同時に、他のすべてのカテゴリの製品が在庫切れになった後も引き続き表示されるようにしたいと考えています。

助けてください。マイク

4

1 に答える 1

1

これは、注文モデルの確認メソッド内で行います。これは、販売が確認されると、製品の数量が更新される場所です。

開ける:

catalog/model/checkout/order.php

confirm() メソッド内には、次のような行があります。

foreach ($order_product_query->rows as $order_product) {

特定の製品の既存の数量を返し、販売された数量を差し引いて、新しい数量が 0 であるかどうかを確認する新しいメソッドを作成できます。さらに、その製品が特定のカテゴリに関連付けられているかどうかを確認します。

その場合、商品をまったく表示したくない場合は商品ステータスを無効に設定し、売り切れであることを表示したい場合は、stock_status を Out of Stock に設定します。

// check quantity and categories
private function checkQuantity ($product_id) {
    $return = array();

    // first check if product is attached to your specified category and add boolean to array
    $categories = $this->db->query ("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
    if (in_array($your_clearance_category_id, $categories->rows)):
        $return['check'] = true;
    else:
        $return['check'] = false;
    endif;

    // get your pre-sale quantity and add to array
    $quantity = $this->db->query ("SELECT quantity FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
    $return['quantity'] = $quantity->row['quantity'];

    return $return;
}

foreach ($order_product_query->rows as $order_product) {次に、構造を開いた直後にこれを追加します。

$checks = $this->checkQuantity($order_product['product_id']);
if ($checks['check']):
    if (((int)$check['quantity'] - (int)$order_product['quantity']) <= 0):
        $this->db->query ("UPDATE " . DB_PREFIX . "product SET status = '0' WHERE product_id = '" . (int)$order_product['product_id'] . "'");
    endif;
endif;

テストはしていませんが、いくつかの微調整の有無にかかわらず動作するはずです。

于 2013-08-14T12:03:06.893 に答える