Hello,
I added the follwing lines inside the function "viewsForm" inside the file "web/modules/contrib/commerce/modules/cart/src/Plugin/views/field/EditQuantity.php"viewsForm" of the module "Commerce Cart".
This allows me to maximize the number of items relative to the stock in the quantity fields of the form on the shopping cart page.
....
$moduleHandler = \Drupal::service('module_handler');
$stock = 0;
if ($moduleHandler->moduleExists('commerce_stock')){
$stockServiceManager = \Drupal::service('commerce_stock.service_manager');
$purchasedEntity = $order_item->getPurchasedEntity();
$stock = $stockServiceManager->getStockLevel($purchasedEntity);
}
$stock = ($stock != 0) ? $stock : 9999;
.....
'#max' => $stock,
.....
It works pretty well, but is there a way to create a small module that will add this functionality without having to patch the contrib module?
or maybe it can be used for "commerce_stock" expect something better ...
Comments
Comment #2
steveoriolComment #3
steveoriolComment #4
steveoriolComment #5
fool2 commentedThis should be done as a form_alter from commerce_stock, not directly in commerce cart.
Comment #6
fool2 commentedWe need to test this patch. There is also an opportunity to remove the form altogether here, if it is an item that only has one in stock.
Comment #7
fool2 commentedFixed formatting and a mistake
Comment #8
fool2 commentedI'm a mess
Comment #9
luksakI needed the default values to be adjusted directly. The attached patch does that. This functionality could be provided as a configurable option.
Comment #10
luksakThis needs a re-roll at least.
Comment #11
joey91133 commentedre-roll at least