【问题标题】:How to get the grouped product price with a quantity of 1 shild product in magento如何在magento中获得数量为1 shild产品的分组产品价格
【发布时间】:2015-10-31 21:53:51
【问题描述】:

我有一个由 2 个 shild 产品(1 个真实产品 + 1 个代表维修成本的“虚拟”产品)制成的 groupe 产品。

因此,客户有两种可能性:

  • 他可以购买真品自行解决问题 或
  • 他可以购买捆绑包,他会购买维修套件并自动购买真正的产品,我的工厂会为他解决问题

例如,产品成本 30 欧元,维修套件成本 20 欧元。

在前端,它将被设置: “起价:20 欧元”

但是,我认为客户不能仅用一种产品购买此捆绑包。因此价格为 50 欧元,我希望在前端将价格设置为 50 欧元。

我尝试在我的主题上修改位于以下位置的文件: .../目录/块/产品/视图/price.phtml

我想插入以下变量 $simulationPrice :

<span class="price" id="product-minimal-price-<?php echo $_id ?> <?php echo $this->getIdSuffix() ?>"> <?php "there I would like the price 50€" echo $simulationPrice ?>
</span>

为此,我想执行以下操作:

<?php $_associatedProducts = $this->getAssociatedProducts(); ?> <?php foreach ($_associatedProducts as $childProduct) { ?> <?php $simulationPrice += $childProduct->getPrice() ?> <?php } ?>

我该怎么做?我希望价格 = 1 个实物产品 * 1 个数量 + 1 个虚拟产品 * 1 个数量。

如果您有其他方法,很高兴阅读您的建议。 我准确地说我已经修改了捆绑包,客户无法修改设置为 1 个单位(1 个真实产品 + 1 个虚拟产品)的数量,但是他可以修改篮子中的数量...

如果您有关于此代码不起作用的解决方案,那将是一种乐趣。

感谢您的帮助。

【问题讨论】:

标签: php magento


【解决方案1】:

我得到了这个代码的解决方案:

$simulationPrice=0;  
$associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); 
foreach ($associatedProducts as $childProduct) {  
    $quantityBackGround=$childProduct->getQty();
    $simulationPrice +=  $childProduct->getPrice() * $childProduct->getQty(); 
} 

事实上,最大的问题是我的代码超出了以下条件:

<?php if (!$_product->isGrouped()): ?>

我没有看到“!”在这种情况下......因此它永远无法工作......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    相关资源
    最近更新 更多