0

私のショップはすべての商品を で販売しています$ 25。次に、顧客のチェックアウト時に製品の合計数量に基づいて割引を行いたいと考えています。

顧客が合計数量が 50 を超えて購入した場合、各製品の価格は各製品の から$25まで$22に上書きされます。

以下のようなもの:

if (total_quantity > 80) {
   price for each product is $19
}

elseif (total_quantity > 50) {
  price for each product is $22
}
else {
  normal price
}

$this->cart->countProducts()現在、顧客のチェックアウト時に使用して合計数量を検出できますが、価格を上書きする方法がわかりません(これはファイル controller\checkout\confirm.php に関連していると確信しています)。

誰かがこれについて私を案内してくれることを願っています。

アップデート :

これで、合計数量に基づいてすべての製品の価格をフィルタリングできます。

if ($this->cart->countProducts() > 3) {
    $product_price = '24.00';
}
elseif ($this->cart->countProducts() > 2) {
    $product_price = '23.00';
}
else {
    $product_price = $product['price'];
}

$this->data['products'][] = array(
    'product_id' => $product['product_id'],
    'name'       => $product['name'],
    'model'      => $product['model'],
    'option'     => $option_data,
    'quantity'   => $product['quantity'],
    'subtract'   => $product['subtract'],
    'price'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax'))),
    'total'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
    'href'       => $this->url->link('product/product', 'product_id=' . $product['product_id'])
); 

しかし、小計と合計をどこでオーバーライドするかわかりません。

p/s: すべての製品価格は $25 に固定されています

OC バージョン: 最新バージョン

4

2 に答える 2

0

ここで私の解決策:

カタログ/コントローラー/チェックアウト

以下のコードを前に追加$this->data['products'][] = array( (361 行目)

if ($this->cart->countProducts() > 80) {
    $product_price = '24.00';
}
elseif ($this->cart->countProducts() > 50) {
    $product_price = '23.00';
}
else {
    $product_price = $product['price'];
}

$this->data['products'][] = array(... に置き換えます

$this->data['products'][] = array(
    'product_id' => $product['product_id'],
    'name'       => $product['name'],
    'model'      => $product['model'],
    'option'     => $option_data,
    'quantity'   => $product['quantity'],
    'subtract'   => $product['subtract'],
    'price'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax'))),
    'total'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
    'href'       => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);

システム/ライブラリ

if (!$this->data) {以下のコードを(22 行目)の後に追加します。

//Count how many product in cart
$total_quantity = $this->session->data['cart'];
$total_product_in_cart = 0;
foreach ($total_quantity as $t_q) {
    $total_product_in_cart += $t_q;
}
$total_product_in_cart;

これ$price = $product_query->row['price'];(173行目)を次のように置き換えます

if ($quantity > 80) {
    $price = '24.00';
}
elseif ($quantity > 50) {
    $price = '23.00';
}
else {
    $price = $product_query->row['price'];
}
于 2013-05-04T03:17:53.247 に答える
0

これは、直接的な具体的な回答ではなく、用途と方法を見つけるための回答です。

オブジェクトが利用できるメソッド/変数の方法がわからない場合は、次のような方法でそれらを出力してみてください。

<?php
echo "<pre>";
print_r(get_class_methods($objectName));
print_r(get_object_vars($objectName));
echo "</pre>";
?>

利用可能なメソッドのリストが表示されます。setPrice() などと呼ばれるメソッドがあるかもしれませんが、少なくとも利用可能ないくつかのオプションについてより多くの洞察を得ることができますか?

于 2013-05-03T13:52:46.947 に答える