php定制做官网多少钱_php – 在prestashop中定制价格计算

您必须在prestashop中创建Product类的覆盖.为此,请在覆盖/类中创建一个名为Product.php的新文件,并将此代码放在其中:

class Product extends ProductCore

{

// Here we will put every method or property override

}

在这个类中,您将复制/粘贴静态方法priceCalculation(在我的原始Product.php文件的第2567行).完成后,只需在方法的最后添加这些行,就在self :: $_price [$cache_id] = $price之前; :

if ($id_product == 44 && Context::getContext()->customer->isLogged()) {

$customer = Context::getContext()->customer;

$nbTimesBoughtThisProduct = (int) Db::getInstance()->getValue('

SELECT COUNT(*)

FROM `' . _DB_PREFIX_ . 'product` p

JOIN `' . _DB_PREFIX_ . 'order_detail` od

ON p.`id_product` = od.`product_id`

JOIN `' . _DB_PREFIX_ . 'orders` o

ON od.`id_order` = o.`id_order`

WHERE o.`id_customer` = ' . $customer->id . '

AND p.`id_product` = ' . $id_product . '

');

$price += $nbTimesBoughtThisProduct * 10;

}

我没有时间测试这些,但我认为这是做你想要做的方式.

priceCalculation是每次Prestashop需要产品价格的方法.通过将此代码放在此方法的最后,我们修改返回的价格.

代码首先检查客户是否被记录(如果没有,我们不能从他那里获得订单).如果是这样,查询会检索客户过去购买此产品的次数.该数字乘以十,并将该值添加到价格.

编辑:如果,如Cyril Tourist所说,你还要计算当前的购物车,得到这个新的代码(仍然没有测试,但应该工作):

if ($id_product == 44 && Context::getContext()->customer->isLogged()) {

$customer = Context::getContext()->customer;

$nbTimesBoughtThisProduct = (int) Db::getInstance()->getValue('

SELECT COUNT(*)

FROM `' . _DB_PREFIX_ . 'product` p

JOIN `' . _DB_PREFIX_ . 'order_detail` od

ON p.`id_product` = od.`product_id`

JOIN `' . _DB_PREFIX_ . 'orders` o

ON od.`id_order` = o.`id_order`

WHERE o.`id_customer` = ' . $customer->id . '

AND p.`id_product` = ' . $id_product . '

');

$productsInCart = Context::getContext()->cart->getProducts();

foreach ($productsInCart as $productInCart) {

if ($productInCart['id_product'] == 44) {

$nbTimesBoughtThisProduct++;

}

}

$price += $nbTimesBoughtThisProduct * 10;

}

此外,我建议您将“44”产品ID存储在常量,配置变量或任何东西中,但不保留在代码中.我只是为了这个例子.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值