简体   繁体   English

shopp插件添加具有自定义价格的现有购物车项目

[英]shopp plugin add existing cart item with custom price

I have normal product with price 29$, what I want is by charging extra 10$ on this and give another item (same product) , means buy one in 29$ and buy two in 39$. 我有一个标价为29 $的普通产品,我想要的是在此产品上额外收取10 $的价格,再给另一个商品(相同产品),意味着以29 $购买一个,以39 $购买两个。

For this I have using this code to add product to cart 为此,我使用此代码将产品添加到购物车

<?php
if($_POST['duplica_las_flores'] != '' && isset($_POST['duplica_las_flores']))
{

    $customProdcutId = $_POST['productID'];
    if(is_numeric($customProdcutId))
    {
        global $Shopp; //load up our $Shopp variable

        $Product = new Product(absint($customProdcutId)); //We have to create a Product object to use in our add to cart function.
        if(!empty($Product->id)){
            $pricing = 10.00;
            $result = $Shopp->Order->Cart->add(1, $Product, $pricing, false, array(), array()); //This is where "the magic happens"
        }
}
?>

In this if checkbox is checked in single product page then this will add another product with my custom price (10$) but this is adding new product with same price (29$). 在此情况下,如果在单个产品页面中选中了复选框,则将添加具有我的自定义价格(10 $)的另一个产品,但这将添加具有相同价格(29 $)的新产品。

How can I change price here for second product or is there any other way to do this ? 如何在这里更改第二个产品的价格,或者还有其他方法可以这样做?

Thanks 谢谢

Easier than modifying the cart code, would to be to use the built in Add-ons system, and create an add on for adding an additional item. 比修改购物车代码更容易,它是使用内置的附加组件系统,并创建一个用于添加其他物品的附加组件。

Pros: Save yourself some time messing around in the plugin code 优点:节省一些时间在插件代码中弄乱

Cons: No inventory updating if you're dealing with a physical product 缺点:如果要处理实物产品,则不会更新库存

I couldn't find the documentation for it, but 'Add-ons' are mentioned here: https://shopplugin.net/docs/the-catalog/product-settings/ 我找不到它的文档,但此处提到了“附加组件”: https : //shopplugin.net/docs/the-catalog/product-settings/

如果您没有太多不同的产品采用这种定价方式,则可以查看折扣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM