Post by Thor_SilverSpool » Mon Sep 07, 2020 3:22 pm

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.
Last edited by Thor_SilverSpool on Tue Sep 08, 2020 2:56 pm, edited 1 time in total.


Posts

Joined
Wed Aug 19, 2020 5:34 pm

Post by khnaz35 » Mon Sep 07, 2020 3:27 pm

Thor_SilverSpool wrote:
Mon Sep 07, 2020 3:22 pm
I tried options, but they all have there own stock, rather then subtracting from the base stock.
how exactly have you tried ?

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by Thor_SilverSpool » Mon Sep 07, 2020 5:05 pm

khnaz35 wrote:
Mon Sep 07, 2020 3:27 pm
how exactly have you tried ?
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.


Posts

Joined
Wed Aug 19, 2020 5:34 pm

Post by Thor_SilverSpool » Tue Sep 08, 2020 2:05 am

chongshengdz wrote:
Tue Sep 08, 2020 1:23 am
try to use "option" and "option value"
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'])
				);
The value ($quant) is clearly shown as the one given in the option.
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?


Posts

Joined
Wed Aug 19, 2020 5:34 pm

Post by straightlight » Tue Sep 08, 2020 2:34 am

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.

Code: Select all

$product_total = 0;

				foreach ($products as $product_2) {
					if ($product_2['product_id'] == $product['product_id']) {
						$product_total += $product_2['quantity'];
					}
				}
This example shows += in the loop and inside the if statement of the foreach statement. Simply manipulate it the way you want from there.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Thor_SilverSpool » Tue Sep 08, 2020 3:36 am

straightlight wrote:
Tue Sep 08, 2020 2:34 am
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.
catalog/controller/checkout/cart.php

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);
					}
				}
system/library/cart/cart.php

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;
	}
No luck - the quantity of the stock of the product is still only reduced by 1 (instead of the expected 2)


Posts

Joined
Wed Aug 19, 2020 5:34 pm

Post by letxobnav » Tue Sep 08, 2020 7:58 am

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.

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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Thor_SilverSpool » Tue Sep 08, 2020 2:55 pm

letxobnav wrote:
Tue Sep 08, 2020 7:58 am
that is done in catalog/model/checkout/order.php.
Cheers - two steps further - now all the little things to be done.


Posts

Joined
Wed Aug 19, 2020 5:34 pm
Who is online

Users browsing this forum: OSWorX and 476 guests