- Status changed to Needs review
18 days ago 5:17pm 1 December 2024
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 ...
Needs work
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.