My requirement is here:-
I have a Game booking requirement in Magento 2, just like online movie booking(e.g- booking movie from Bookmyshow, Paytm etc). there is fix number of tickets in each slot per day.user can buy the ticket for the same day or for the future.
To achieve the same I've created a configurable product and assign associated products as slots.
for same venue and slot, ticket can be book from paytm as well as bookmyshow and many more...and ticket price may vary depending on the platform(bookmyshow,paytm etc).
so to synchronize the inventory I've chosen the configurable product concept and will assign the same associated product to each configurable product.
You can visit here for more clarification:-
My problem is that I've to manage the inventory date and slot wise.suppose for a date "dd-mm-yy" and slot 10AM-11AM(it may be same or future date,slots) someone has book 2 tickets out of 50 so now 48 tickets are left for same date and slot.
I've 3 option to achieve the same:-
1-Plugin.
2-Event.
3-Overriding.
But according to the Magento 2, a plugin is the best way to customize the things and I'm using as below:-
di.xml:-
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\CatalogInventory\Model\StockStateProvider">
<plugin name="Wakar_Wakar_Plugin_StockStateProvider" sortOrder="1" type="Wakar\Stockcheck\Plugin\StockStateProvider"/>
</type>
</config>
MethodName:-
public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQty, $origQty = 0)
Before Plugin:-
<?php
namespace Wakar\Stockcheck\Plugin;
class StockStateProvider
{
public function beforeCheckQuoteItemQty(){
echo "hey " ; exit;
}
}
It's working fine.
But my question is that how can I use the parameter in the method beforeCheckQuoteItemQty() so that I can get the data of the original method **CheckQuoteItemQty() ??
I've also R&D for the plugin concept but still not clear on what basis/reference they are passing the parameters in the plugin methods? what're the criteria?how can we know that for beforeCheckQuoteItemQty() what parameter I need to take to hold the data here?
e.g-
I've gone through Webkul Plugin tutorial:-
https://webkul.com/blog/magento2-use-plugins/
And for the "beforeAddProduct()",they are using just like :-
public function beforeAddProduct(\Magento\Checkout\Model\Cart $subject,$productInfo,$requestInfo = null) {
$requestInfo['qty'] = 10; // increasing quantity to 10
return array($productInfo, $requestInfo);
}
On what basis they are passing parameters "(\Magento\Checkout\Model\Cart $subject,$productInfo,$requestInfo = null)" how can we know what parameter we need to pass, what is the logic behind it??
After getting the data beforeCheckQuoteItemQty(), I can check the previous orders based on date and time slots and can control the quantity.
You can also suggest any alternate best solution for the same scenerio,waiting for your update.
Please help me to clear the plugin concept!!!
=================Modification==========================
How can I use before plugin for the class "Magento\CatalogInventory\Model\StockStateProvider.php" having the method "public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQty, $origQty = 0)" ??
Thanks!!!