【问题标题】:How to set discount price for all products globally in opencart如何在opencart中为全球所有产品设置折扣价
【发布时间】:2014-01-08 10:26:05
【问题描述】:

我需要店内所有产品的折扣价为 -5%。它必须显示在产品详细信息页面和产品列表页面中,例如个人折扣价(删除线)。我想将折扣应用于全球商店中的所有产品。正如我所尝试的,我们可以选择在添加产品时在选项选项卡中设置折扣价格,但为每个产品添加折扣似乎是一个漫长的过程。所以我想在全球范围内应用它。任何帮助或想法将不胜感激。

我检查了一些扩展程序,但都在结帐页面中显示了全球折扣。我想根据商品价格在商品详情页展示。

【问题讨论】:

  • 您可以在 opencart 之外创建一个 php 页面,将所有产品的折扣更改为数据库...这只是一个初步想法。
  • 您没有正确检查扩展。我已经完成了一个完全符合您要求的扩展程序...在 OpenCart 扩展程序商店搜索 Mass discount 或我的昵称...

标签: php mysql e-commerce opencart


【解决方案1】:

打开catalog/model/catalog/product.php

找到第 40 行附近结束的代码行

=> $query->row['special'],

改成

=> $query->row['price'] * 0.95,

然后保存。请注意,如果您对产品有任何折扣,则不会出现额外 5% 的折扣价。如果你也想这样,请将特殊行改为 end

($query->row['discount'] ? $query->row['discount'] : $query->row['price']) * 0.95,

【讨论】:

    【解决方案2】:

    在产品控制器中

    $this->load->model('catalog/product');
    $products = $this->model_catalog_product->getProducts();
    foreach ($products as $product) {
    $this->model_catalog_product->setdiscount($product['product_id'],$product['price']);
    }
    

    在模型中

    public function getProducts()
    {
    $query = $this->db->query("SELECT product_id, price FROM oc_product");
    return $query->rows; 
    }
        public function setdiscount($id,$price)
    {
    
        $price=($price*95)/100;
        $query = $this->db->query("INSERT INTO oc_product_discount (product_id,customer_group_id,quantity,priority,price,date_start,date_end) VALUES ('".$id."','1','1','1','".$price."','xxx','yyy')");
    }
    

    xxx 和 yyy 由您选择。并根据您的要求更改 customer_group_id、数量、优先级。

    我已经为您提供了流程,您可以随心所欲地进行更改。

    【讨论】:

      【解决方案3】:

      我有 18,000 种产品,需要为特定客户群提供折扣。我不想玩 php!

      我是在mysql中做的,在opencart数据库上操作。 0product_discount 是你需要操作的表。在您针对 product_id 为特定客户组创建折扣条目之前,它将为空。

      # open your opencart database in mysql
      # first create a file listing the product_id's you want the discount applied to: you can restrict the 'select' as desired. 
      # This selects all products. Or you can edit the file
      
      select product_id into outfile '/home/junkfile' from 0product;
      # outside mysql in a console run the following as a script file (this is for linux console should work in windows(???) idk
      # read each product_id line from the file and creates an insert line with the proper data
      
      while read line; do
      
      echo "TRUNCATE TABLE 0product_discount;" >> testxx.sql
      echo "" >> testxx.sql
      
      # third item "3" is the customer_group_id
      # quantity 1, priority 1 and price $1.0000
      #OR you can use a percent discount
      # dates are zeros for unlimited time frame
      
      echo "INSERT INTO 0product_discount ( product_discount_id, product_id, customer_group_id, quantity, priority, price, date_start, date_end) VALUES ( '"${id}"','"${id}"', '3', '1', '1', '1.0000', '0000-00-00',  '0000-00-00');" >> testxx.sql
      
      done < /home/junkfile
      
      #This creates a form of mysqldump text file
      
      ## now use mysql -u [user] -p < testxx.sql to load the 0product_discount table
      ### note that the 'truncate line, clears out your failures ready for your next try!!
      

      不确定折扣价是否会显示在产品页面上,但确实会显示在结帐时。只需将客户添加到适当的组中即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-24
        • 1970-01-01
        • 2020-01-15
        • 2015-08-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多