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
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 )
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.
However, in your catalog/controller/checkout/checkout.php file, try the following:
Find:
Code: Select all
// Validate minimum quantity requirments.
$products = $this->cart->getProducts();
Code: Select all
$this->load->model('catalog/product');
$manufacturers_info = array();
Code: Select all
if ($product['minimum'] > $product_total) {
$this->redirect($this->url->link('checkout/cart'));
}
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;
}
Code: Select all
$this->language->load('checkout/checkout');
Code: Select all
if (sizeof($manufacturers_info) > 2) {
$this->redirect($this->url->link('checkout/cart'));
}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
That's what I though yesterday so far.OSWorX wrote: ↑Sun Jan 13, 2019 12:44 amReally 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:Why counting here?Code: Select all
count( $product['manufacturer_id'] > 2 )
I am really confused ..
Or you have not posted the whole code ..
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
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( .. )
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.
I'm afraid I didn't give enough info before.straightlight wrote: ↑Sun Jan 13, 2019 12:55 amNot 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.
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'])) {
}
}
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
The reason to have all in the same shop is SEO porpouses....OSWorX wrote: ↑Sun Jan 13, 2019 3:26 amI 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 whyYou do not want to count, you want to check only if the manufacturer id = 2 or any other id.Code: Select all
count( .. )
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.
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
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
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
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
/* 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
/* Manufacturer Mod */
Code: Select all
if(count($product['manufacturer_id'] > 2) && $this->request->get['route'] != 'checkout/cart') {
$this->redirect($this->url->link('checkout/cart'));
}
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'));
}
Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
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 */
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
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);
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');
}
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!';
find:
Code: Select all
if (json['success']) {
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');
}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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
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 */
Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido
Cheers mates
Pedro Martin - websitesbuilder.com.au
Checkout my free extensions: https://www.opencart.com/index.php?rout ... r=comprido
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.Is that the easiest way to check and redirect (not necessary the warning, but redirect once the 2nd manufacturer is added)?
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
How can I run my code exactly after the product/s is/are added?straightlight wrote: ↑Wed Jan 16, 2019 6:44 pmCustomers may want to be informed whenever this restriction implies versus redirection without considering the Event Management during the process.
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
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 57 guests