Discount check in the openCart basket



  • I have a product with options. I use it as a form of order. For example, I'm ordering parameters: A - 333 B - 222 C - 111 Pressure to add to the basket, and the basket displays my order with these parameters. Then I make another order, just like that, and it goes into the basket, and the basket only increases its collo, so the parameters are identical. If I make another order with parameters: A - 444 B. ♪ ♪ C. ♪ ♪ The merchandise is added to the basket, but it's already in the new table. I can't figure out how to test the option.

    The thing is, I've got a discount on ordering two grand. - 6 per cent, 3 - 8 per cent, 4 - 10 per cent, etc. But it's necessary that the discount be extended only to an order with certain parameters, i.e., in the above example, I have three goods in my basket (2 items with identical parameters and 1 with other parameters), which means that the discount is calculated as three goods, and it must be two goods, and the 3rd must be considered full, because it's colummetically one.

    I don't understand how to do this, but I assumed there was a way to make a test of the identity of the parameters, if the goods with the same parameters were less than the 2nd,ffix the discount. ♪ ♪

    I've been told that I need to "help the discount, in addition to the number of items to take into account the other option"... But I'd have a little more information, so it's still hard to deal with these tasks on my own.

    In system\library\cart.php There's a request in the 180 row.

    $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id .    "'AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");
    

    a sub-item

    if ($product_discount_query->num_rows) {
      $price = $product_discount_query->row['price'];
    }
    

    I think if it's a sql request, it's a discount.

    So, with a clue, I thought that we could add a sql request to an O.R., and I finally did this:

    $product_discount_query = $this->db->query("SELECT price FROM "
    . DB_PREFIX . "product_discount LEFT JOIN " 
    . DB_PREFIX . "product_option_value pov LEFT JOIN "
    . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id)   WHERE product_id = '" . (int)$product_id . "'
     AND pov.product_option_value_id = '" . (int)$option_value . "'
     AND pov.product_option_id = '" . (int)$product_option_id . "'
     AND quantity <= '" . (int)$discount_quantity . "'
     AND ((date_start = '0000-00-00' OR date_start < NOW())
     AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC,  priority ASC, price ASC LIMIT 1");
    

    ...but I get a mistake:

    Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE product_id = '2419' and pov.product_option_value_id = '27' and p' at line 1 Error No: 1064

    Can you tell me, please, how is it right to write a request?



  • My job wasn't a SQL request, I had to replace this piece of code.

    // Product Discounts
    $discount_quantity = 0;
    

    foreach ($this->session->data['cart'] as $key_2 => $quantity_2) {
    $product_2 = explode(':', $key_2);
    if ($product_2[0] == $product_id) {
    $discount_quantity += $quantity_2;
    }
    }

    $discount_quantity = $quantity;




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2