Skip to content

Commit

Permalink
0.1.2: #17
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Oct 22, 2019
1 parent 1135820 commit 6ed3c3a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
23 changes: 23 additions & 0 deletions Plugin/Backend/Block/Widget/Grid/Massaction/Extended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace PPCs\Core\Plugin\Backend\Block\Widget\Grid\Massaction;
use Magento\Backend\Block\Widget\Grid\Massaction\Extended as Sb;
// 2019-10-22
final class Extended {
/**
* 2019-10-22
* "Make the «Cost» and «Price» columns of the the Iksanika's Stock Inventory Manager's grid editable":
* https://github.com/p-pcs/core/issues/17
* @see \Iksanika\Stockmanage\Block\Adminhtml\Product\Grid::_prepareMassaction()
* @see \Magento\Backend\Block\Widget\Grid\Massaction\Extended::addItem()
* @param Sb $sb
* @param string $id
* @param array(string => mixed) $a
* @return array(string, array(string => mixed))
*/
function beforeAddItem(Sb $sb, $id, array $a) {
if ('save' === $id && df_contains(dfa($a, 'url'), 'stockmanage/product/massUpdateProducts')) {
$a['fields'] = array_merge($a['fields'], ['cost', 'price']);
}
return [$id, $a];
}
}
12 changes: 11 additions & 1 deletion Plugin/Iksanika/Stockmanage/Block/Adminhtml/Product/Grid.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PPCs\Core\Plugin\Iksanika\Stockmanage\Block\Adminhtml\Product;
use Iksanika\Stockmanage\Block\Adminhtml\Product\Grid as Sb;
use Iksanika\Stockmanage\Block\Widget\Grid\Column\Renderer\Number;
use Magento\Framework\Event\Observer as Ob;
// 2019-10-22
final class Grid {
Expand All @@ -22,7 +23,16 @@ final class Grid {
function aroundAddColumn(Sb $sb, \Closure $f, $id, $data) {
if (!in_array($id, ['visibility', 'websites'])) {
if ('price' === $id) {
$f('cost', [
/**
* 2019-10-22
* "Make the «Cost» and «Price» columns
* of the the Iksanika's Stock Inventory Manager's grid editable":
* https://github.com/p-pcs/core/issues/17
*/
/** @var array(string => string) $pd */
$pd = ['class' => 'input-text admin__control-text', 'renderer' => Number::class];
$data = $pd + $data;
$f('cost', $pd + [
'column_css_class' => 'col-price'
,'currency_code' => df_currency_base_c(df_request('store', 0))
,'header' => 'Cost'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace PPCs\Core\Plugin\Iksanika\Stockmanage\Controller\Adminhtml\Product;
use Magento\Catalog\Model\Product as P;
// 2019-10-22
final class MassUpdateProducts {
/**
* 2019-10-22
* "Make the «Cost» and «Price» columns of the the Iksanika's Stock Inventory Manager's grid editable":
* https://github.com/p-pcs/core/issues/17
* @see \Iksanika\Stockmanage\Controller\Adminhtml\Product\MassUpdateProducts::execute()
*/
function beforeExecute() {
$cost = df_float(df_request('cost')); /** @var float[] $cost */
$price = df_float(df_request('price')); /** @var float[] $price */
$storeId = (int)df_request('store'); /** @var int $storeId */
foreach (df_int(df_request('product', [])) as $i => $id) { /** @var int $i */ /** @var int $id */
$p = df_product_r()->getById($id, true, $storeId); /** @var P $p */
$p->addData(['cost' => $cost[$i], 'price' => $price[$i]])->save();
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "p-pcs/core"
,"version": "0.1.1"
,"version": "0.1.2"
,"description": "A custom module for performance-pcs.com (Magento 2)"
,"type": "magento2-module"
,"homepage": "https://github.com/p-pcs/core"
Expand Down
22 changes: 21 additions & 1 deletion etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,31 @@ https://github.com/p-pcs/core/issues/12
2) "Remove the «Visibility» column from the Iksanika's Stock Inventory Manager's grid":
https://github.com/p-pcs/core/issues/13
3) "Remove the «Type» column from the Iksanika's Stock Inventory Manager's grid":
https://github.com/p-pcs/core/issues/14 -->
https://github.com/p-pcs/core/issues/14
4) "Make the «Cost» and «Price» columns of the the Iksanika's Stock Inventory Manager's grid editable":
https://github.com/p-pcs/core/issues/17 -->
<type name='Iksanika\Stockmanage\Block\Adminhtml\Product\Grid'>
<plugin
name='PPCs\Core\Plugin\Iksanika\Stockmanage\Block\Adminhtml\Product\Grid'
type='PPCs\Core\Plugin\Iksanika\Stockmanage\Block\Adminhtml\Product\Grid'
/>
</type>
<!-- 2019-10-22
"Make the «Cost» and «Price» columns of the the Iksanika's Stock Inventory Manager's grid editable":
https://github.com/p-pcs/core/issues/17 -->
<type name='Iksanika\Stockmanage\Controller\Adminhtml\Product\MassUpdateProducts'>
<plugin
name='PPCs\Core\Plugin\Iksanika\Stockmanage\Controller\Adminhtml\Product\MassUpdateProducts'
type='PPCs\Core\Plugin\Iksanika\Stockmanage\Controller\Adminhtml\Product\MassUpdateProducts'
/>
</type>
<!-- 2019-10-22
"Make the «Cost» and «Price» columns of the the Iksanika's Stock Inventory Manager's grid editable":
https://github.com/p-pcs/core/issues/17 -->
<type name='Magento\Backend\Block\Widget\Grid\Massaction\Extended'>
<plugin
name='PPCs\Core\Plugin\Backend\Block\Widget\Grid\Massaction\Extended'
type='PPCs\Core\Plugin\Backend\Block\Widget\Grid\Massaction\Extended'
/>
</type>
</config>

0 comments on commit 6ed3c3a

Please sign in to comment.