質問

価格に応じて、いくつかの製品を異なる方法で表示する必要があります。私は単にの価値を単に確認できることを望んでいました $price 関連するテーマファイル内から変数がありますが $price 通貨フォーマットされた文字列が含まれています。また、OpenCartはさまざまな通貨形式をサポートしているため、価格文字列を数値に戻す簡単で堅牢な方法はありません。

私は製品コントローラーのクラスを見ました、 ControllerProductProduct. 。私が知る限り、OpenCartはビューに数値の価格値を公開しません。コントローラーのクラスを変更できますが、更新を複雑にするからではありません。

私は何かを見落としましたか? OpenCartテーマ内から価格で数値比較を実行する簡単な方法はありませんか?

役に立ちましたか?

解決 2

残念ながら、答えはノーです。OpenCartは、数値値をテーマに公開しません。コアファイルを変更する必要があります。ブラッド 方法を説明します.

他のヒント

Product.phpでv1.4.9.4を見る(ControllerProductProduct)あなたが話している$価格のフォーマット値を設定する次のコードを見ることができます。

if ($discount) {
    $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
    $price = $this->currency->format($this->tax->calculate($result['price'],$result['tax_class_id'], $this->config->get('config_tax')));

これを次のように変更してみませんか...

if ($discount) {
    $price_num = $this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax'));
    $price = $this->currency->format($price_num);
} else {
    $price_num = $this->tax->calculate($result['price'],$result['tax_class_id'], $this->config->get('config_tax'));
    $price = $this->currency->format($price_num);

そして、これから数行下にあると、次のものを追加することで、この$ rice_num値をテンプレートに渡すことができます。

$this->data['products'][] = array(
    'product_id'    => $result['product_id'],
    ...
    'price'         => $price,
    'price_num'     => $price_num,
    ...

必要なことをする必要があります

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top