Hello Community,
Situation:
We sell two types of products: 'by item' and 'by metre'.
The 'by item' setup is straight forward, but I can't figure out how to do the 'by metre' setup.
Challenge 'by Metre':
1) Should have 3 prices: quarter, half and full.
2) Should substract from the base stock: quarter -1, half -2, full - 4 (I multiplied the base stock by 4, as it comes from a single roll).
3) Should show up in the cart / checkout as either 'quarter' or by metre.
I tried options, but they all have there own stock, rather then subtracting from the base stock.
Suggestions for a 'free' solution highly appriciated.
Situation:
We sell two types of products: 'by item' and 'by metre'.
The 'by item' setup is straight forward, but I can't figure out how to do the 'by metre' setup.
Challenge 'by Metre':
1) Should have 3 prices: quarter, half and full.
2) Should substract from the base stock: quarter -1, half -2, full - 4 (I multiplied the base stock by 4, as it comes from a single roll).
3) Should show up in the cart / checkout as either 'quarter' or by metre.
I tried options, but they all have there own stock, rather then subtracting from the base stock.
Suggestions for a 'free' solution highly appriciated.
Last edited by Thor_SilverSpool on Tue Sep 08, 2020 2:56 pm, edited 1 time in total.
how exactly have you tried ?Thor_SilverSpool wrote: ↑Mon Sep 07, 2020 3:22 pmI tried options, but they all have there own stock, rather then subtracting from the base stock.
Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature
First, I tried the vanilla setup, but the main stock is always reduced by the order amount - not good.
Also the alternative stock for the other options is not reduced either in vanilla setup.
So, I was looking at /catalog/controller/checkout/confirm.php - if I can substiture the product['subtract'] by the option['quantity]' - as this would always remove the 'correct' amount without the need to fiddle around much and would keep the main functions intact.
And this is, where I'm stuck.
I have the value itself, no bother.
from confirm.php - row 376
Code: Select all
$data['products'][] = array(
'cart_id' => $product['cart_id'],
'product_id' => $product['product_id'],
'name' => $product['name'] . ":" . $quant, // check that is is there
'model' => $product['model'],
'option' => $option_data,
'recurring' => $recurring,
'quantity' => $product['quantity'],
'subtract' => $product['subtract'] * $quant, //expect to myltiply the stock to be reduced accordingly.
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']),
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
So, I put 1 item into the cart, do the checkout and $quant == 2, but the total stock is only reduced by 1; I would expect the stock to be reduced by 2 here.
So, where do I miss something? maybe I need to amend something else as well?
You need to re-pull the cart quantity as described in your catalog/controller/checkout/cart.php file or your system/library/cart/cart.php file.
This example shows += in the loop and inside the if statement of the foreach statement. Simply manipulate it the way you want from there.
Code: Select all
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
catalog/controller/checkout/cart.phpstraightlight wrote: ↑Tue Sep 08, 2020 2:34 amYou need to re-pull the cart quantity as described in your catalog/controller/checkout/cart.php file or your system/library/cart/cart.php file.
This example shows += in the loop and inside the if statement of the foreach statement. Simply manipulate it the way you want from there.
Code: Select all
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$quant = 1;
foreach ($product_2['option'] as $option) {
if (isset($option['quantity'])) {
$quant = $option['quantity'];
} else {
$quant = 0;
}
}
$product_total += ($product_2['quantity'] * $quant);
}
}
Code: Select all
public function countProducts() {
$product_total = 0;
$products = $this->getProducts();
foreach ($products as $product) {
$quant = 1;
foreach ($product['option'] as $option) {
if (isset($option['quantity'])) {
$quant = $option['quantity'];
} else {
$quant = 0;
}
}
$product_total += ($product['quantity'] * $quant);
}
return $product_total;
}
stock is only reduced when adding order history both for the product and options if subtract stock has been set for them.
that is done in catalog/model/checkout/order.php.
Not grasping what you are doing in the cart.
that is done in catalog/model/checkout/order.php.
Not grasping what you are doing in the cart.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Who is online
Users browsing this forum: OSWorX and 476 guests