Add all files
0 parents
Showing
13 changed files
with
249 additions
and
0 deletions
.gitignore
0 → 100644
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Copyright © Magento, Inc. All rights reserved. | ||
| 4 | * See COPYING.txt for license details. | ||
| 5 | */ | ||
| 6 | |||
| 7 | // @codingStandardsIgnoreFile | ||
| 8 | |||
| 9 | namespace FGCT\OverrideCreateInvoice\Block\Adminhtml\Items\Renderer; | ||
| 10 | |||
| 11 | use Magento\Sales\Model\Order\CreditMemo\Item as CreditMemoItem; | ||
| 12 | use Magento\Sales\Model\Order\Invoice\Item as InvoiceItem; | ||
| 13 | use Magento\Sales\Model\Order\Item as OrderItem; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Order item render block | ||
| 17 | * | ||
| 18 | * @api | ||
| 19 | * @since 100.0.2 | ||
| 20 | */ | ||
| 21 | class DefaultRenderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer { | ||
| 22 | public function __construct( | ||
| 23 | \Magento\Backend\Block\Template\Context $context, | ||
| 24 | \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, | ||
| 25 | \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration, | ||
| 26 | \Magento\Framework\Registry $registry, | ||
| 27 | array $data = [] | ||
| 28 | ) { | ||
| 29 | $this->_coreRegistry = $registry; | ||
| 30 | parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data); | ||
| 31 | } | ||
| 32 | |||
| 33 | public function getErrorOutStock($productId) { | ||
| 34 | $productsId = explode(',',$this->getRequest()->getParam('productsId')); | ||
| 35 | if(in_array($productId, $productsId)) { | ||
| 36 | $html = '<div id="messages"><div class="messages"><div class="message message-error error"><div data-ui-id="messages-message-error">This product is out of stock</div></div></div></div>'; | ||
| 37 | return $html; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace FGCT\OverrideCreateInvoice\Helper; | ||
| 4 | |||
| 5 | class Data extends \Magento\Framework\App\Helper\AbstractHelper { | ||
| 6 | protected $_filesystem; | ||
| 7 | protected $_directory_list; | ||
| 8 | protected $_resource; | ||
| 9 | protected $_scopeConfig; | ||
| 10 | public function __construct( | ||
| 11 | \Magento\Framework\App\Helper\Context $context, | ||
| 12 | \Magento\Framework\Filesystem $filesystem, | ||
| 13 | \Magento\Framework\App\ResourceConnection $resource, | ||
| 14 | \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
| 15 | \Magento\Framework\App\Filesystem\DirectoryList $directory_list | ||
| 16 | ) { | ||
| 17 | parent::__construct($context); | ||
| 18 | $this->_filesystem = $filesystem; | ||
| 19 | $this->_directory_list = $directory_list; | ||
| 20 | $this->_resource = $resource; | ||
| 21 | $this->_scopeConfig = $scopeConfig; | ||
| 22 | } | ||
| 23 | } |
| 1 | <?php | ||
| 2 | namespace FGCT\OverrideCreateInvoice\Observer; | ||
| 3 | use Magento\Framework\Event\ObserverInterface; | ||
| 4 | |||
| 5 | class OrderInvoiceSaveAfter implements ObserverInterface { | ||
| 6 | public $_coreRegistry; | ||
| 7 | protected $_helper; | ||
| 8 | public function __construct( | ||
| 9 | \Magento\Framework\Registry $coreRegistry | ||
| 10 | ) { | ||
| 11 | $this->_coreRegistry = $coreRegistry; | ||
| 12 | } | ||
| 13 | public function execute(\Magento\Framework\Event\Observer $observer) { | ||
| 14 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
| 15 | $productsId = $this->_coreRegistry->registry('fgct_overridecreateinvoice_products_out_stock') ?: []; | ||
| 16 | if(count($productsId)) { | ||
| 17 | $msg = "Some of the products are out of stock"; | ||
| 18 | //throw new \Exception($msg); | ||
| 19 | exit('OrderInvoiceSaveAfter'); | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } |
| 1 | <?php | ||
| 2 | namespace FGCT\OverrideCreateInvoice\Observer; | ||
| 3 | |||
| 4 | use Magento\Framework\Event\Observer; | ||
| 5 | use Magento\Framework\Event\ObserverInterface; | ||
| 6 | |||
| 7 | use Magento\Framework\Controller\ResultFactory; | ||
| 8 | |||
| 9 | class OrderInvoiceSaveBefore implements ObserverInterface { | ||
| 10 | public $_coreRegistry; | ||
| 11 | protected $_helper; | ||
| 12 | public function __construct( | ||
| 13 | \Magento\Framework\Registry $coreRegistry, | ||
| 14 | \Magento\Framework\App\RequestInterface $request, | ||
| 15 | \Magento\Framework\App\ResponseFactory $responseFactory, | ||
| 16 | \Magento\Framework\Message\ManagerInterface $messageManager, | ||
| 17 | \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository, | ||
| 18 | \Magento\Framework\UrlInterface $url | ||
| 19 | ) { | ||
| 20 | $this->_coreRegistry = $coreRegistry; | ||
| 21 | $this->_request = $request; | ||
| 22 | $this->responseFactory = $responseFactory; | ||
| 23 | $this->url = $url; | ||
| 24 | $this->_messageManager = $messageManager; | ||
| 25 | $this->_stockItemRepository = $stockItemRepository; | ||
| 26 | } | ||
| 27 | public function execute(\Magento\Framework\Event\Observer $observer) { | ||
| 28 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
| 29 | $orderId = $this->_request->getParam('order_id'); | ||
| 30 | $invoice = $observer->getEvent()->getInvoice(); | ||
| 31 | $order = $invoice->getOrder(); | ||
| 32 | $productManager = $objectManager->create('Magento\Catalog\Model\Product'); | ||
| 33 | $productsOutStock = $productsNotEnoughQty = []; | ||
| 34 | foreach ($invoice->getAllItems() as $item) { | ||
| 35 | $name = $item->getName(); | ||
| 36 | $type = $item->getSku(); | ||
| 37 | $productId = $item->getProductId(); | ||
| 38 | $qty = $item->getQty(); | ||
| 39 | $product = $productManager->load($productId); | ||
| 40 | |||
| 41 | $_productStock = $this->_stockItemRepository->get($productId); | ||
| 42 | // $_productStock->getQty(); | ||
| 43 | if(!$_productStock->getIsInStock()) { | ||
| 44 | $productsOutStock[$productId] = $name; | ||
| 45 | } | ||
| 46 | if($qty > $_productStock->getQty()) { | ||
| 47 | $productsNotEnoughQty[$productId] = $_productStock->getQty(); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | if(count($productsOutStock)) { | ||
| 51 | $productsId = array_keys($productsOutStock); | ||
| 52 | $this->_coreRegistry->register('fgct_overridecreateinvoice_products_out_stock', $productsId, true); | ||
| 53 | $this->_messageManager->addError(__('Some of the products are out of stock')); | ||
| 54 | |||
| 55 | $redirectionUrl = $this->url->getUrl('sales/order_invoice/new/*/product/*/', ['order_id' => $orderId, 'productsId' => implode(',', $productsId)]); | ||
| 56 | $this->responseFactory->create()->setRedirect($redirectionUrl)->sendResponse(); | ||
| 57 | return $this; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } |
| 1 | <?xml version="1.0"?> | ||
| 2 | <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> | ||
| 3 | <event name="sales_order_invoice_save_before"> | ||
| 4 | <observer name="fgc_sales_order_invoice_save_before" instance="FGCT\OverrideCreateInvoice\Observer\OrderInvoiceSaveBefore" /> | ||
| 5 | </event> | ||
| 6 | <event name="sales_order_invoice_save_after"> | ||
| 7 | <observer name="fgc_sales_order_invoice_save_after" instance="FGCT\OverrideCreateInvoice\Observer\OrderInvoiceSaveAfter" /> | ||
| 8 | </event> | ||
| 9 | </config> |
| 1 | <?xml version="1.0"?> | ||
| 2 | <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
| 3 | <preference for="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" type="FGCT\OverrideCreateInvoice\Block\Adminhtml\Items\Renderer\DefaultRenderer" /> | ||
| 4 | </config> |
| 1 | <?xml version="1.0"?> | ||
| 2 | <!-- | ||
| 3 | /** | ||
| 4 | * Copyright © Magento, Inc. All rights reserved. | ||
| 5 | * See COPYING.txt for license details. | ||
| 6 | */ | ||
| 7 | --> | ||
| 8 | <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
| 9 | <update handle="sales_invoice_item_price"/> | ||
| 10 | <body> | ||
| 11 | <!-- <referenceBlock name="order_items.default" remove="true"/> --> | ||
| 12 | <!-- <referenceContainer name="content"> | ||
| 13 | <block class="FGCT\OverrideCreateInvoice\Block\Adminhtml\Items\Renderer\FgcDefaultRenderer" name="order_items.default" template="FGCT_OverrideCreateInvoice::order/invoice/create/items/renderer/default.phtml"/> | ||
| 14 | </referenceContainer> --> | ||
| 15 | <referenceBlock name="order_items.default"> | ||
| 16 | <action method="setTemplate"> | ||
| 17 | <argument name="template" translate="true" xsi:type="string">FGCT_OverrideCreateInvoice::order/invoice/create/items/renderer/default.phtml</argument> | ||
| 18 | </action> | ||
| 19 | </referenceBlock> | ||
| 20 | </body> | ||
| 21 | </page> |
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Copyright © Magento, Inc. All rights reserved. | ||
| 4 | * See COPYING.txt for license details. | ||
| 5 | */ | ||
| 6 | |||
| 7 | // @codingStandardsIgnoreFile | ||
| 8 | |||
| 9 | ?> | ||
| 10 | <?php /** @var $block \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer */ ?> | ||
| 11 | <?php $_item = $block->getItem() ?> | ||
| 12 | <?php $block->setPriceDataObject($_item)?> | ||
| 13 | <td class="col-product"><?= $block->getColumnHtml($_item, 'name') ?> | ||
| 14 | <?= $block->getErrorOutStock($_item->getProductId()) ?> | ||
| 15 | </td> | ||
| 16 | <td class="col-price"> | ||
| 17 | <?= $block->getColumnHtml($_item, 'price') ?> | ||
| 18 | </td> | ||
| 19 | <td class="col-qty"><?= $block->getColumnHtml($_item, 'qty') ?></td> | ||
| 20 | <td class="col-qty-invoice"> | ||
| 21 | <?php if ($block->canEditQty()) : ?> | ||
| 22 | <input type="text" class="input-text admin__control-text qty-input" | ||
| 23 | name="invoice[items][<?= /* @escapeNotVerified */ $_item->getOrderItemId() ?>]" | ||
| 24 | value="<?= /* @escapeNotVerified */ $_item->getQty()*1 ?>"/> | ||
| 25 | <?php else : ?> | ||
| 26 | <?= /* @escapeNotVerified */ $_item->getQty()*1 ?> | ||
| 27 | <?php endif; ?> | ||
| 28 | </td> | ||
| 29 | <td class="col-subtotal"> | ||
| 30 | <?= $block->getColumnHtml($_item, 'subtotal') ?> | ||
| 31 | </td> | ||
| 32 | <td class="col-tax"><?= /* @escapeNotVerified */ $block->displayPriceAttribute('tax_amount') ?></td> | ||
| 33 | <td class="col-discount"><?= /* @escapeNotVerified */ $block->displayPriceAttribute('discount_amount') ?></td> | ||
| 34 | <td class="col-total last"> | ||
| 35 | <?= $block->getColumnHtml($_item, 'total') ?> | ||
| 36 | </td> |
readme.md
0 → 100644
| 1 | # GET EXTENSION | ||
| 2 | |||
| 3 | Use modman [Linux](https://github.com/colinmollenhour/modman) | [Windows](https://github.com/khoazero123/modman-php) : | ||
| 4 | |||
| 5 | cd magento_root/ | ||
| 6 | modman clone http://fgit.fgct.net/vankhoa/M2OverrideCreateInvoice.git | ||
| 7 | modman deploy M2OverrideCreateInvoice | ||
| 8 | |||
| 9 | Use git: | ||
| 10 | |||
| 11 | git clone http://fgit.fgct.net/vankhoa/M2OverrideCreateInvoice.git | ||
| 12 | cp M2OverrideCreateInvoice/* magento_root/ | ||
| 13 | |||
| 14 | |||
| 15 | # INSTALLATION | ||
| 16 | |||
| 17 | bin/magento setup:upgrade | ||
| 18 | bin/magento setup:di:compile | ||
| 19 | bin/magento cache:clean && bin/magento cache:flush | ||
| 20 | bin/magento setup:static-content:deploy |
-
Please register or sign in to post a comment