Post by comprido » Sat Jan 12, 2019 3:11 pm

Hi there,
I'm stuck working on my mod https://www.opencart.com/index.php?rout ... n_id=33289

I would like to avoid customers to continue adding products once there are two different manufacturer_ids from products on the cart module.

So adding the 'manufacturer_id' => $product['manufacturer_id'], line to the $this->data['products'][] = array( ...

Anyone to give a hand on the piece of code to improve this or with a better idea?:

/* Manufacturer Mod */
if(count($product['manufacturer_id'] > 2) && $this->request->get['route'] != 'checkout/cart') {
$this->redirect($this->url->link('checkout/cart'));
}
/* Manufacturer Mod */

Thanks

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by OSWorX » Sun Jan 13, 2019 12:44 am

Really not sure what you want.
Does the mod not working?
Or do you want more functionalities?
Have seen that yo are offering 2 different versions, 1 with manufacturer id and 1 without.

And what for shall the code above?

If you count on the manufacturer id, what is the benefit?
Manufacture id is an integer value, so this is basically useless:

Code: Select all

count( $product['manufacturer_id'] > 2 ) 
Why counting here?

I am really confused ..
Or you have not posted the whole code ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Sun Jan 13, 2019 12:55 am

Not quite useful to publish products by different manufacturers on your store if customers would not be able to add more than 1 manufacturer per checkout process … Besides, the financial providers do not restrict purchases by manufacturers in anyhow.

However, in your catalog/controller/checkout/checkout.php file, try the following:

Find:

Code: Select all

// Validate minimum quantity requirments.			
		$products = $this->cart->getProducts();
add below:

Code: Select all

$this->load->model('catalog/product');
		
		$manufacturers_info = array();
Then, find:

Code: Select all

if ($product['minimum'] > $product_total) {
				$this->redirect($this->url->link('checkout/cart'));
			}
add below:

Code: Select all

$store_product = $this->model_catalog_product->getProduct($product['product_id']);			
			
			if (!empty($store_product['manufacturer'])) {
				$manufacturers_info[html_entity_decode($store_product['manufacturer'], ENT_QUOTES, 'UTF-8')] = true;
			}
Then, find:

Code: Select all

$this->language->load('checkout/checkout');
add above:

Code: Select all

if (sizeof($manufacturers_info) > 2) {
			$this->redirect($this->url->link('checkout/cart'));
		}
This should resolved the issue.

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 comprido » Sun Jan 13, 2019 3:10 am

OSWorX wrote:
Sun Jan 13, 2019 12:44 am
Really not sure what you want.
Does the mod not working?
Or do you want more functionalities?
Have seen that yo are offering 2 different versions, 1 with manufacturer id and 1 without.

And what for shall the code above?

If you count on the manufacturer id, what is the benefit?
Manufacture id is an integer value, so this is basically useless:

Code: Select all

count( $product['manufacturer_id'] > 2 ) 
Why counting here?

I am really confused ..
Or you have not posted the whole code ..
That's what I though yesterday so far.
I have providers in different locations, I work with dropshipping.
For most of my products the client wants screen printing as and added value.
If I work screen printing services as an option, I need to add heaps of values to each products. Since I started the shop, I though add those services as another product/s that they can add later on, once they select products they are interested in.
That's the reason to have 2 versions of the mod: the version "except manufacturer_id = 0" allows to declare that manufacturer_id as the screen printing services and be compatible with the rest of manufacturer_ids.

At this moment, the warning is just showing on the cart/checkout. It is a bit annoying keep adding different products and realize that is not possible purchase from different manufacturer_ids at that stage and it is something I wanted to implement. So as soon as the customer add to the cart a second manufacturer_id != 0, the cart module redirect him to the checkout page saying "Warning: Due to warehouse locations we cannot supply orders from different manufacturers. Please make a different order for each manufacturer and use the cross X to leave products from only one manufacturer."

You can see the mod "working" at www.tee-shirt.com.au, thanks for your time.

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by OSWorX » Sun Jan 13, 2019 3:26 am

I understood what you want to to.
And checked the code of the version 3 module.

But, why 2 different modules when you can have 1 which does both?
And why

Code: Select all

count( .. )
You do not want to count, you want to check only if the manufacturer id = 2 or any other id.

And - what i would do, is some backend.
Where you could define granular - if the customer wants that - which manufactuer belongs to which shop.
But if this is only based on:

"you are another manufacturer than the bfore, okay go to the other shop"

the simple check for different IDs would fit.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by comprido » Sun Jan 13, 2019 3:28 am

straightlight wrote:
Sun Jan 13, 2019 12:55 am
Not quite useful to publish products by different manufacturers on your store if customers would not be able to add more than 1 manufacturer per checkout process … Besides, the financial providers do not restrict purchases by manufacturers in anyhow.

However, in your catalog/controller/checkout/checkout.php file, try the following (...)
This should resolved the issue.
I'm afraid I didn't give enough info before.
The mod actually block the checkout:

Code: Select all

if ($product_2['manufacturer_id'] != $product['manufacturer_id']) {						
				if (($product_2['manufacturer_id'] != 0) && ($product['manufacturer_id'] != 0))  {
				$this->redirect($this->url->link('checkout/cart'));
					 } elseif (isset($product['manufacturer_id']) || isset($product_2['manufacturer_id'])) {
					 } 
				}		
What I need is, if a customer add a product from a second manufacturer diferent from zero, redirect him to the checkout where he will see the alert or even not add the second manufacturer_id product/s and show the warning in the same product page.
So one manufacturer_id + manufacturer_id=0 is compatible.
Any other manufacturer_ids combined are no compatible and must show the alert and avoid the cart increasing.
Thanks

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Sun Jan 13, 2019 3:39 am

OSWorX wrote:
Sun Jan 13, 2019 3:26 am
I understood what you want to to.
And checked the code of the version 3 module.

But, why 2 different modules when you can have 1 which does both?
And why

Code: Select all

count( .. )
You do not want to count, you want to check only if the manufacturer id = 2 or any other id.

And - what i would do, is some backend.
Where you could define granular - if the customer wants that - which manufactuer belongs to which shop.
But if this is only based on:

"you are another manufacturer than the bfore, okay go to the other shop"

the simple check for different IDs would fit.
The reason to have all in the same shop is SEO porpouses....
After years working with different shops, I realize that Google appreciate the most products I have in one shop, and if I classified as they are, the most visits and customers I get, I mean, mentioning "By colour"-"By Gender"-"By Fabric"... (not as filters).

I've been working with 3 different shops for years: bahiafightwear.com, serigrafiacamiseta.com, camiseta-amarilla.com... and once I merge all the shops the sales increase a lot.

By the way, if I got 1,000 visits in one shop and 40 in the other, in this way I can always "at least display" another products to potential clients, like the martial arts ones, that as less interest in average...

So far, the best seller product I have are the yellow fluro t-shirts. Is not a common product and give a range of models and designs or just longsleeve/short sleeve availability FROM DIFFERENT PROVIDERS on the spot, have increased my number of customers.

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Sun Jan 13, 2019 3:51 am

OSWorX wrote:
Sun Jan 13, 2019 3:26 am
You do not want to count, you want to check only if the manufacturer id = 2 or any other id.
Sorry, that's it, partially. I want to check if customer is adding more than one manufacturer_id product/s and manufacturer_id != 0.
And stop him from adding product/s that later will have to remove from the cart.

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Sun Jan 13, 2019 4:01 am

By the way, this function is the same as Aliexpress have, for example. But you can finalize the cart with different manufacturers/shipping methods at the same time and it really increases the sales.
I don't want to enable multiple manufacturer orders, as per logistic when I'm out of my desk I just resend the order to my provider/s and/or courier/s to process the order.
Unless I make something complicated in the backend like organize a multi-order by manufacturer also, is not reasonable just for logistics.
But the mod so far is useful, that's why I'm looking that improvement.
Thanks guys

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Sun Jan 13, 2019 4:06 am

comprido wrote:
Sun Jan 13, 2019 4:01 am
Unless I make something complicated in the backend like organize a multi-order by manufacturer also, is not reasonable just for logistics.
This takes me to another idea that is IF CART HAS MORE THAN 1 MANUFACTURER THEN CREATE SEPARATE ORDERS FOR EACH MANUFACTURER, but I don't know how complex could be to develop... will see. Anyway due to the sector I work with, the screen printing is an added value and with that way of offer the screen printing as a different product I still find the handicap of associate the service to a specific product.

I mean: customer buy 10 items manufacturer_id= 1, 10 items manufacturer_id= 2, 10 screen printings (manufacturer_id=0) but I do I know wich tshirts do I have to print?
...

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Sun Jan 13, 2019 4:32 am

Something like...?

/* Manufacturer Mod */
$manufacturers = array_unique($product['manufacturer_id']);
if(($product['manufacturer_id'] != 0 && $manufacturers > 2) && $this->request->get['route'] != 'checkout/cart') {
$this->redirect($this->url->link('checkout/cart'));
}

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by kestas » Sun Jan 13, 2019 5:55 am

Really I do not understand what do you want, but first your code is wrong..

/* Manufacturer Mod */

Code: Select all

if(count($product['manufacturer_id'] > 2) && $this->request->get['route'] != 'checkout/cart') { 
$this->redirect($this->url->link('checkout/cart'));	
} 
/* Manufacturer Mod */

should be:
/* Manufacturer Mod */

Code: Select all

if((count($product['manufacturer_id']) >  2)  &&  $this->request->get['route'] != 'checkout/cart') { 
$this->redirect($this->url->link('checkout/cart'));	
} 
/* Manufacturer Mod */

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by comprido » Mon Jan 14, 2019 7:10 am

kestas wrote:
Sun Jan 13, 2019 5:55 am
Really I do not understand what do you want, but first your code is wrong..
Thanks, that's why I'm trying to get help.
I want the cart module to redirect the customer when is trying to add a second manufacturer_id product different from manufacturer_id = "0", so the manufacturer_id zero is compatible with the rest but any other combination is not possible (they can just buy from 1 manufacturer each time, or combine with the manufacturer_id = 0 products).

I got this still giving an error:

Code: Select all

/* Manufacturer Mod */
		$manufacturers = array_unique($product['manufacturer_id']);
		$containsDifferentManufacturers = false;
		$currentManufacturer = -1;
		for($i=0; $i < count($manufacturers); $i++){
			if ($manufacturers[$i] != 0 && $manufacturers[$i] != $currentManufacturer){
				if ($currentManufacturer != -1){
					$containsDifferentManufacturers = true;
				}
				$currentManufacturer = $manufacturers[$i];
			}
		}
		if($containsDifferentManufacturers && $this->request->get['route'] != 'checkout/cart') { 		
			$this->redirect($this->url->link('checkout/cart'));	
		} 
		/* Manufacturer Mod */
We have to do a count or array_unique_count I guess as far as a the customer can add something like this before getting an error:
Product id 1 manufacturer_id 12
Product id 3 manufacturer_id 12
Product id 22 manufacturer_id 12
Product id 5 manufacturer_id 0
Product id 9 manufacturer_id 3 >>> redirect to checkout / disallow add products from different manufacturer
Product id 7 manufacturer_id 12 >> no problem, manufacturer_id 12 match so can add it.
Product id 43 manufacturer_id 7 >>> redirect to checkout / disallow add products from different manufacturer

I guess you understand from that.
Cheers

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by straightlight » Mon Jan 14, 2019 10:14 am

The post: viewtopic.php?f=112&t=209375&p=744207#p744124 covers the part from checkout/checkout event when more than 2 manufacturers fails, all fails despite if originating from Opencart or from an API.

However, if you are looking to restrict manufacturers from the cart when adding products, using an array_unique in this case would be useless. As you mentioned on one of your previous post above, adding the suggested code from my previous post restricts the checkout access when adding more than 2 manufacturers which means the code is working from checkout/checkout as intended.

From checkout/cart route, you'd simply need to integrate as the following in your catalog/controller/checkout/cart.php file:

Find:

Code: Select all

if (!$json) {
				$this->cart->add($this->request->post['product_id'], $quantity, $option, $profile_id);
add above:

Code: Select all

$cart = $this->cart->getProducts();

$manufacturers_info = array();

foreach ($cart as $cart_product) {
    if (!empty($cart_product['product_id'])) {
        $store_product = $this->model_catalog_product->getProduct($cart_product['product_id']);

        if ($store_product['manufacturer']) {
            $manufacturers_info[html_entity_decode($store_product['manufacturer'], ENT_QUOTES, 'UTF-8')] = true;
        }
    }
}

if (sizeof($manufacturers_info) > 2) {
    $json['error']['manufacturer'] = $this->language->get('error_manufacturer_exceeded');
}
Then, in your catalog/language/<your_language>/checkout/cart.php file,

add at the bottom:

Code: Select all

$_['error_manufacturer_exceeded'] = 'You cannot add more than 2 manufacturers in the cart. Please try again with different manufacturers!';
Then, in your catalog/view/javascript/common.js file, in the AddToCart function,

find:

Code: Select all

if (json['success']) {
add above:

Code: Select all

if (json['error']['manufacturer']) {
    $('#notification').html('<div class="error" style="display: none;">' + json['error']['manufacturer'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				
				$('.error').fadeIn('slow');
}
This should provide what you need.

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 comprido » Wed Jan 16, 2019 5:05 pm

straightlight wrote:
Mon Jan 14, 2019 10:14 am
This should provide what you need.
First of all, thanks for your support/help- I understand the code, but it doesn't make the function and the cart module disappear when I click to view the items that contains.

Is that the easiest way to check and redirect (not necessary the warning, but redirect once the 2nd manufacturer is added)?
I want the customers at the checkout point to decide wich manufacturer_id products remove from their cart.

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Wed Jan 16, 2019 5:59 pm

Using the same code I used before I got the function, in module/cart, after foreach ($this->cart->getProducts() as $product) {

Code: Select all

			/* Manufacturer Mod */
			$product_total = 0;
			foreach ($this->cart->getProducts() as $product_2) {
			$product_total = 0;
	
			if ($product_2['manufacturer_id'] != $product['manufacturer_id'] && $this->request->get['route'] != 'checkout/cart') {						
				if (($product_2['manufacturer_id'] != 0) && ($product['manufacturer_id'] != 0))  {
				$this->redirect($this->url->link('checkout/cart'));
					 } elseif (isset($product['manufacturer_id']) || isset($product_2['manufacturer_id'])) {		 } 
				}	
			}
			/* Manufacturer Mod */
I'm happy with that, thank you guys, all of you.

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by comprido » Wed Jan 16, 2019 6:12 pm

You may take a look at https://www.tee-shirt.com.au if you want.
Cheers mates

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by straightlight » Wed Jan 16, 2019 6:44 pm

Is that the easiest way to check and redirect (not necessary the warning, but redirect once the 2nd manufacturer is added)?
It is rather the most convenient way to do it. Customers may want to be informed whenever this restriction implies versus redirection without considering the Event Management during the process.

However, it is great to see that you found what you were looking for.

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 comprido » Thu Jan 17, 2019 4:38 am

straightlight wrote:
Wed Jan 16, 2019 6:44 pm
Customers may want to be informed whenever this restriction implies versus redirection without considering the Event Management during the process.
How can I run my code exactly after the product/s is/are added?
Or print the alert since then on $(document).ready(function() ?

// $this->redirect($this->url->link('checkout/cart'));
$this->data['error_warning'] = sprintf($this->language->get('error_manufacturer'));

I mean, use cart.php with my code and product.tpl to print the warning if possible.

Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido


User avatar
New member

Posts

Joined
Mon Sep 10, 2012 11:46 pm

Post by straightlight » Thu Jan 17, 2019 6:52 am

My code above already shows how to show an event to the customers when adding a product to the cart exceeding 2 manufacturers originating from all products.

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
Who is online

Users browsing this forum: No registered users and 14 guests