Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: Define max quantity products for customer  (Read 8425 times)

Offline Claudio Garcia

  • Newbie
  • *
  • Posts: 35
  • Karma: +7/-0
    • View Profile
Define max quantity products for customer
« on: October 21, 2019, 06:58:53 AM »
Hello Everybody

What i need is to block customer who orders more than 3 quantity for every product, not per order, Per customer and per all orders.
I was thinking to block customer to make one order. But its better customer makes orders who they want but restrict only 3 products quantity per each product per all orders. I know is not logical rule but its a requeriment.

I checked exists orders in Cart Controller Hook: storefront/controller/pages/checkout/cart.php:260 line
« Last Edit: October 30, 2019, 09:47:08 PM by Claudio Garcia »

Offline Claudio Garcia

  • Newbie
  • *
  • Posts: 35
  • Karma: +7/-0
    • View Profile
Re: Define max quantity products for customer - please help me
« Reply #1 on: October 22, 2019, 04:53:36 AM »
Hi Basara

Please help with this. A case is the following:

Order1 has 3 towells, 2 Shampoo
Order2 has 2 pamper
order3 has 1 haircom

If customer is doing a new order, i need Abantecart valide Customer not buy towells, Allow only 1 Shampoo, Only 1 pamper and 2 haircom, becuase it has a max of 3 products per all orders.

I did a view in the database who list:

Customer_id, product_id, and max_quantity.
2              pamper               2
2                towel                3
2                haircom           1

How can query this in cart.php?
What is the variable who has the customer_id
it i know who is customer_id maybe i can go a head in my proyect.

Thank you a lot for your help.



Offline Claudio Garcia

  • Newbie
  • *
  • Posts: 35
  • Karma: +7/-0
    • View Profile
Re: Define max quantity products for customer - please help me
« Reply #2 on: October 30, 2019, 09:46:22 PM »
Hello everybody

I investigated how to do the quantity restriction and got it by this way:

I create a view in mysql workbech:
Code: [Select]
CREATE
    ALGORITHM = UNDEFINED
    DEFINER = `root`@`localhost`
    SQL SECURITY DEFINER
VIEW `bitnami_abantecart`.`products_customer` AS
    SELECT
        `ac_op`.`product_id` AS `product_id`,
        `ac_op`.`name` AS `product_name`,
        SUM(`ac_op`.`quantity`) AS `quantity_hist`,
        `ac_c`.`customer_id` AS `customer_id`
    FROM
        ((`bitnami_abantecart`.`ac_order_products` `ac_op`
        JOIN `bitnami_abantecart`.`ac_orders` `ac_o` ON (`ac_op`.`order_id` = `ac_o`.`order_id`))
        JOIN `bitnami_abantecart`.`ac_customers` `ac_c` ON (`ac_c`.`customer_id` = `ac_o`.`customer_id`))
    WHERE
        `ac_o`.`order_status_id` = 5
    GROUP BY `ac_op`.`product_id`, `ac_c`.`customer_id`, `ac_c`.`customer_id`

This view show product_id, product_name, customer_id and sum(quantity) group by product and customer, so i can ask for orders made in history by customer with status "5-Complete".

And modify this
Code: [Select]
htdocs\core\lib\cart.php from line 166
Code: [Select]
$product_result = $this->buildProductDetails($product_id, $quantity, $options);
            if (count($product_result)) {
                $product_data[$key] = $product_result;
                $product_data[$key]['key'] = $key;

// Query for max product per customer --- CG
$prod_query_customer = $this->db->query("SELECT * FROM products_customer WHERE customer_id =
'".(int)$this->customer->getId()."' and product_id = '".(int)$product_result['product_id']."' ");
$quantity_hist = $prod_query_customer->row['quantity_hist'];
$quantity_ask = $quantity_hist +  $product_result['quantity'];

if ( $quantity_hist >= $product_result['maximum']) {
$this->cust_data['error'] = "Ya compró " .$quantity_hist. " de " .$product_result['maximum']. " unidades permitidas de: " .$prod_query_customer->row['product_name']. ". El producto se ha retirado de su carro de compras. Por favor compre otros productos disponibles.";
$this->update($key, 0 );
}
elseif ($quantity_hist > 0 and ($quantity_ask > $product_result['maximum'])) {
$new_quantity = $product_result['maximum'] - $quantity_hist;
$this->cust_data['error'] = "Ya compró " .$quantity_hist. " de " .$product_result['maximum']. " unidades permitidas de: " .$prod_query_customer->row['product_name']. ". La cantidad solicitada se ha ajustado a " .$new_quantity. ". Por favor revise su pedido.";
$this->update($key, $new_quantity);
}

//else {

                //apply min and max for quantity once we have product details.
                // if ($quantity < $product_result['minimum']) {
                //    $this->language->load('checkout/cart', 'silent');
                //    $this->cust_data['error'] = $this->language->get('error_quantity_minimum');
                //    $this->update($key, $product_result['minimum']);
                //}
                //if ($product_result['maximum'] > 0) {
                //    $this->language->load('checkout/cart', 'silent');
                //    if ($quantity > $product_result['maximum']) {
                //        $this->cust_data['error'] = $this->language->get('error_quantity_maximum');
                //        $this->update($key, $product_result['maximum']);
                //    }
             //   }
            } else {
                $this->remove($key);
            }
        }

I had to comment the quantity validation made by order (Abantecart default) to apply my own validation per customer.



« Last Edit: November 24, 2019, 12:41:04 PM by Claudio Garcia »

Offline deepvyas

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
  • Advanced Customization & Integration Services
    • View Profile
Re: Define max quantity products for customer
« Reply #3 on: October 31, 2019, 05:06:31 AM »
Hi ,
I am available for help you
Please let me know, If still searching for solution

Regards
Deep
Professional Developer

 

Powered by SMFPacks Social Login Mod