Add Product to Cart that doesn't Exist?

Hey guys, how can I add a product to the cart that doesn’t exist in the product inventory. I am getting product data from a broker platform, adding my percentage margin to the price and displaying it on the website search results. However if I want it so that someone can add the product to the cart, how can this be done? I searched fn.cart.php for the add to cart function and it expects a product_id throughout the function. However the products don’t exist in the cart.

Intercept your feed and look up the products by their product code. If it doesn't exist, build the proper structure and create it.

Hi There,





To add a product if there is no inventory then follow these steps:



[color=“#008000”]####################[/color]

[color=“#008000”]Go to Admin panel->Settings->General.[/color]

[color=“#008000”]Under The Catalog Heading, there will be option “Allow negative amount in inventory”. Check the box next to it and save the data.[/color]

[color=“#008000”]This will allow the customer to add any product to cart whose inventory is Zero.[/color]

[color=“#008000”]####################[/color]



Hope this helps.

Correct me if I'm wrong…but that response is completely irrelevent? Amount of stock is irrelevent if the product_id does not exist in the database.

Yea I might not have phrased it properly in the first sentence but the rest explains what I'm trying to do. I would like to bypass stucturing the database to contain the product, because I do not want to create new products in the store, I want to leave those alone. I just want to be able to add products to the cart that do not exist in my store. There must be a way to add stuff to the cookie or something.

I tried doing a test by adding something like this to the beginning of fn_add_product_to_cart function in /core/fn.cart.php , it didn't work.



$cart['products']['777777777777']['amount'] = 1;
$cart['products']['777777777777']['product_options'] = array();
$cart['products']['777777777777']['price'] = 777;
$cart['products']['777777777777']['stored_price'] = "N";
$cart['products']['777777777777']['extra']['product_options'] = array();
$cart['products']['777777777777']['extra']['unlimited_download'] = "N";
$cart['products']['777777777777']['extra']['return_period'] = 1;
$cart['products']['777777777777']['stored_discount'] = "N";
$cart['products']['777777777777']['company_id'] = 0;
$cart['products']['777777777777']['return_period'] = 1;
$cart['products']['777777777777']['amount_total'] = 1;
$cart['products']['777777777777']['options_type'] = "P";
$cart['products']['777777777777']['exceptions_type'] = "F";
$cart['products']['777777777777']['modifiers_price'] = 0;
$cart['products']['777777777777']['is_edp'] = "N";
$cart['products']['777777777777']['edp_shipping'] = "N";
$cart['products']['777777777777']['base_price'] = 777;
$cart['products']['777777777777']['display_price'] = 777;

Still unclear why you would want to do what you are doing, but…

You might create a new product with a product_code of 'on-the-fly' or something. Make it 'hidden' so it doesn't show.



Then when you add one of these non-existent products to the cart, have a hook that will go in and change the product_code, product (name), price, etc. to your liking.

I am working on that code that would add it on the fly as a hidden product, that should be a working method for sure. The reason why I am doing this is because our search engine within the site is connecting to a broker platform feed. Imagine like an ebay. We don't want the products added in with our normal inventory and mixed up with the rest. If someone searches for a product on our search, and the broker platform has it, they can make the purchase and we can make the deal like the middleman.