Jump to content

[SOLVED] Allow admin to create orders including products not available for sale


cercamon

Recommended Posts

Hi, we are using prestashop 1.5 on our store, and want to set up an override to be able to generate orders from the backoffice which might include products that are not available for sale.

I've been reading and looking at code for several days, but still I'm unable to find out how to override this behaviour.

Any ideas?

Much appreciated :)

Edited by cercamon (see edit history)
Link to comment
Share on other sites

cercamon,

No need to override anything. This is standard available:

 

Create/Edit your product you don't want to show to customers.

Set its visibility to Nowhere

post-455771-0-35968800-1415167779_thumb.png

 

Check your shop, see that it isn't in the categories you added to the product

Make an order, (obviously without that product, as they cannot choose it)

Go to back office, Orders. Choose edit order

Go to the current products list that are in the order.

Press Add new product. You get a field where you can type a name of a product.

Type (part of) the name of the hidden product and add the add button.

post-455771-0-78273200-1415167775_thumb.png

 

 

Voilá,  the hidden product is added to the order :-)

 

Hope this helps,

pascal.

Link to comment
Share on other sites

Hi PascalVP, thanks for your reply.

 

In our case, we have products that must appear to customers, but due to contractual limitations they cannot be added to online carts.

We need the ability to generate orders from B.O. including such products.

 

Your workaround actually would do the trick, but we have one more thing to consider.

Since we use the advance stock functionality, we need to track down inventories for every product and therefore need the functionality to generate orders including all the products that appear on front-end, whether available-for-sale or not.

 

That's why I was thinking to override this behaviour.

 

Any hints on it?

Many thanks!

Link to comment
Share on other sites

... therefore need the functionality to generate orders including all the products that appear on front-end, whether available-for-sale or not.

 

I'm not sure I understand the exact problem you have that isn't solved yet by doing the above trick. Products in front end can be ordered by the customer using the shop front. Products that shouldn't be allowed in front shop can be added in back office by the employee. What exactly can't you do yet? The stock is normally managed when adding/subtracting products to/from the order...

 

Please elaborate a little.

Thanks,

pascal

Link to comment
Share on other sites

Hi, I'll try to elaborate a bit more the reasoning.

 

We have retail online and physical shops. All products for sale are stocked in our own warehouse, and we use the advanced stock management feature to control inventories levels.

 

In the online shop catalog, there are certain physical products that due to contractual reasons cannot be sold through online cart. They must be sold either by phone or face-to-face. Those products have been assigned to be "not-available-for-order" in the product detail form. That is, they have a value of '0' in ps_product -> available_for_order field. For the sake of simplicity, let's refer those products as 'offline products'.

 

All products in online catalog show delivery estimation according to their stock levels.

That's why the solution previously proposed wouldn't work. Since we would need to alter the inventory by syncing stock levels for the 'offline product' shown in front end and the 'mirror product' just available from backoffice. Having duplicated products is a potential source of problems to have a clear stock management control.

 

 

Now, the store employees must be able to generate orders from backoffice in which are included either usual online products and 'offline products', not matter what. The idea is that the back office order form should allow adding to cart such 'offline products'.

 

That's why I want to override the limitation that prevents to adding 'offline products' to cart from back office when ps_product -> available_for_order field equals zero.

 

Hope it helps. If something needs further clarification, just let me know.

 

Thanks!

Link to comment
Share on other sites

So, do I understand correctly, the customer has to have the possibility to SEE the product, (but is not allowed to order) on line?

 

Then, to save you from any programming, (with all version update management problems that comes with it) you could just make two the same products, one that you can only show and not sell online (avaialble_for_sale=0) and a same one (maybe with same name, with some small extension OFL (off line sale) or so that has the visibility =nowhere. As the customer needs to call anyway, you can then check the stock of the product by checking the product with visibility =nowhere, which can be sold (by employee intervention) and thus has its stock managed as usual. If stock is zero, you can tell the customer at that moment.

 

If you really need up to the minute stock info updates visible online for the not-for-sale product, you could make some trigger, that updates a stock field according to stock of the visible=nowhere product.

 

Pascal

  • Like 1
Link to comment
Share on other sites

OK, Make an override for/edit file classes/Cart.php

 

and override/modify function:

 

public function getProducts($refresh = false, $id_product = false, $id_country = null)

 

change needed: (Add red code)

 

 

...
// Build SELECT
$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`,
p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
' . (isset(Context::getContext()->employee)? ' 1 as available_for_order' :' product_shop.`available_for_order`') . ', product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`, 
stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
product_shop.`wholesale_price`, product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference, IFNULL(sp.`reduction_type`, 0) AS reduction_type');
 
// Build FROM
$sql->from('cart_product', 'cp');
...
 
 
And override/modify function:
public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, Shop $shop = null, $auto_add_cart_rule = true)
 
 

change needed: (Add red code)

 
...
/* If we have a product combination, the minimal quantity is set with the one of this combination */
if (!empty($id_product_attribute))
  $minimal_quantity = (int)Attribute::getAttributeMinimalQty($id_product_attribute);
else
  $minimal_quantity = (int)$product->minimal_quantity;
 
if (!Validate::isLoadedObject($product))
  die(Tools::displayError());
 
if (isset(self::$_nbProducts[$this->id]))
  unset(self::$_nbProducts[$this->id]);
 
if (isset(self::$_totalWeight[$this->id]))
  unset(self::$_totalWeight[$this->id]);
 
if ((int)$quantity <= 0)
  return $this->deleteProduct($id_product, $id_product_attribute, (int)$id_customization);
elseif ((empty(Context::getContext()->employee) && !$product->available_for_order) || Configuration::get('PS_CATALOG_MODE'))
  return false;
else
{
  /* Check if the product is already in the cart */
 ...
 
 
 
 
What is does: It checks if we are in back office (An employee is defined if so) and if we are, we either ignore the value of available_for_order (in updateQty), or we change it to 1 (= available for ordering) when getting the product out of the database.
 
 
This means, ALL products that are active can now be ordered in back office, if there is stock enough, including the ones that aren't available in front office.
 
Images:
post-455771-0-95968900-1415683465_thumb.png
Product Test2, only viewable in front office (Available for order = NO, visible = everywhere)
 
post-455771-0-96393000-1415683475_thumb.png
Product Test2 Added in Back office, Order , edit order. Click Add new Product button and type name, add quantity and press Add button
 
post-455771-0-89440700-1415683470_thumb.png
When printing Invoice, new product Test2 is added to the order.
 
 
Hope this helps,
pascal.
 
  • Like 1
Link to comment
Share on other sites

  • 3 years later...

On latest prestashop 1.6.1.20 I got error and can't add product in admin panel.

PHP Warning:  Cannot modify header information - headers already sent by (output started at C:\wamp64\www\test\controllers\admin\AdminCartsController.php:481) in C:\wamp64\www\test\classes\controller\AdminController.php on line 1829

Stack trace:
1. {main}() C:\wamp64\www\test\admin886qq1yby\index.php:0
2. Dispatcher->dispatch() C:\wamp64\www\test\admin886qq1yby\index.php:58
3. AdminCartsController->run() C:\wamp64\www\test\classes\Dispatcher.php:367
4. AdminCartsController->initHeader() C:\wamp64\www\test\classes\controller\Controller.php:185
5. header() C:\wamp64\www\test\classes\controller\AdminController.php:1829

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...