@@ -528,7 +528,7 @@ public function saveSubItems( Product $product, $subItems )
528
528
$ subitem ->sale_price = $ item [ 'sale_price ' ];
529
529
$ subitem ->quantity = $ item [ 'quantity ' ];
530
530
$ subitem ->total_price = $ item [ 'total_price ' ] ?? (float ) $ item [ 'sale_price ' ] * (float ) $ item [ 'quantity ' ];
531
- $ subitem ->author = Auth:: id () ;
531
+ $ subitem ->author = $ product -> author ;
532
532
$ subitem ->save ();
533
533
} else {
534
534
$ subitem = ProductSubItem::find ( $ item [ 'id ' ] );
@@ -544,7 +544,7 @@ public function saveSubItems( Product $product, $subItems )
544
544
$ subitem ->sale_price = $ item [ 'sale_price ' ];
545
545
$ subitem ->quantity = $ item [ 'quantity ' ];
546
546
$ subitem ->total_price = $ item [ 'total_price ' ] ?? (float ) $ item [ 'sale_price ' ] * (float ) $ item [ 'quantity ' ];
547
- $ subitem ->author = Auth:: id () ;
547
+ $ subitem ->author = $ product -> author ;
548
548
$ subitem ->save ();
549
549
}
550
550
@@ -1178,6 +1178,7 @@ public function stockAdjustment( $action, $data ): ProductHistory|EloquentCollec
1178
1178
* @param float $quantity
1179
1179
* @param string $sku
1180
1180
* @param string $unit_identifier
1181
+ * @param int $author
1181
1182
*/
1182
1183
$ product = isset ( $ product_id ) ? Product::find ( $ product_id ) : Product::usingSKU ( $ sku )->first ();
1183
1184
@@ -1225,7 +1226,8 @@ public function stockAdjustment( $action, $data ): ProductHistory|EloquentCollec
1225
1226
orderProductQuantity: $ quantity ,
1226
1227
product: $ product ,
1227
1228
orderProduct: isset ( $ orderProduct ) ? $ orderProduct : null ,
1228
- parentUnit: $ unit
1229
+ parentUnit: $ unit ,
1230
+ author: $ author ?? 0 ,
1229
1231
);
1230
1232
} else {
1231
1233
return $ this ->handleStockAdjustmentRegularProducts (
@@ -1236,7 +1238,8 @@ public function stockAdjustment( $action, $data ): ProductHistory|EloquentCollec
1236
1238
total_price: $ total_price ,
1237
1239
unit_price: $ unit_price ,
1238
1240
orderProduct: isset ( $ orderProduct ) ? $ orderProduct : null ,
1239
- procurementProduct: isset ( $ procurementProduct ) ? $ procurementProduct : null
1241
+ procurementProduct: isset ( $ procurementProduct ) ? $ procurementProduct : null ,
1242
+ author: $ author ?? 0 ,
1240
1243
);
1241
1244
}
1242
1245
}
@@ -1256,6 +1259,7 @@ private function handleStockAdjustmentsForGroupedProducts(
1256
1259
$ orderProductQuantity ,
1257
1260
Product $ product ,
1258
1261
Unit $ parentUnit ,
1262
+ int $ author = 0 ,
1259
1263
?OrderProduct $ orderProduct = null ): EloquentCollection
1260
1264
{
1261
1265
$ product ->load ( 'sub_items ' );
@@ -1264,7 +1268,7 @@ private function handleStockAdjustmentsForGroupedProducts(
1264
1268
throw new Exception ( __ ( 'Adjusting grouped product inventory must result of a create, update, delete sale operation. ' ) );
1265
1269
}
1266
1270
1267
- $ products = $ product ->sub_items ->map ( function ( ProductSubItem $ subItem ) use ( $ action , $ orderProductQuantity , $ parentUnit , $ orderProduct ) {
1271
+ $ products = $ product ->sub_items ->map ( function ( ProductSubItem $ subItem ) use ( $ author , $ action , $ orderProductQuantity , $ parentUnit , $ orderProduct ) {
1268
1272
$ finalQuantity = $ this ->computeSubItemQuantity (
1269
1273
subItemQuantity: $ subItem ->quantity ,
1270
1274
parentUnit: $ parentUnit ,
@@ -1314,6 +1318,7 @@ private function handleStockAdjustmentsForGroupedProducts(
1314
1318
return $ this ->recordStockHistory (
1315
1319
product_id: $ subItem ->product_id ,
1316
1320
action: $ action ,
1321
+ author: $ author ,
1317
1322
unit_id: $ subItem ->unit_id ,
1318
1323
unit_price: $ subItem ->sale_price ,
1319
1324
quantity: $ finalQuantity ,
@@ -1332,6 +1337,7 @@ private function handleStockAdjustmentsForGroupedProducts(
1332
1337
$ this ->recordStockHistory (
1333
1338
product_id: $ product ->id ,
1334
1339
action: $ action ,
1340
+ author: $ author ,
1335
1341
unit_id: $ orderProduct ->unit_id ,
1336
1342
unit_price: $ orderProduct ->unit_price ,
1337
1343
quantity: $ orderProductQuantity ,
@@ -1382,7 +1388,7 @@ private function preventNegativity( $oldQuantity, $quantity )
1382
1388
* @param ProcurementProduct $procurementProduct
1383
1389
* @return ProductHistory
1384
1390
*/
1385
- private function handleStockAdjustmentRegularProducts ( $ action , $ quantity , $ product_id , $ unit_id , $ orderProduct = null , $ unit_price = 0 , $ total_price = 0 , $ procurementProduct = null )
1391
+ private function handleStockAdjustmentRegularProducts ( $ action , $ quantity , $ product_id , $ unit_id , $ author = 0 , $ orderProduct = null , $ unit_price = 0 , $ total_price = 0 , $ procurementProduct = null )
1386
1392
{
1387
1393
/**
1388
1394
* we would like to verify if
@@ -1433,6 +1439,7 @@ private function handleStockAdjustmentRegularProducts( $action, $quantity, $prod
1433
1439
1434
1440
return $ this ->recordStockHistory (
1435
1441
product_id: $ product_id ,
1442
+ author: $ author ,
1436
1443
action: $ action ,
1437
1444
unit_id: $ unit_id ,
1438
1445
unit_price: $ unit_price ,
@@ -1478,6 +1485,7 @@ private function handleStockAdjustmentRegularProducts( $action, $quantity, $prod
1478
1485
return $ this ->recordStockHistory (
1479
1486
product_id: $ product_id ,
1480
1487
action: $ action ,
1488
+ author: $ author ,
1481
1489
unit_id: $ unit_id ,
1482
1490
unit_price: $ unit_price ,
1483
1491
quantity: $ adjustQuantity ,
@@ -1518,6 +1526,7 @@ public function recordStockHistory(
1518
1526
$ unit_price ,
1519
1527
$ quantity ,
1520
1528
$ total_price ,
1529
+ $ author = 0 ,
1521
1530
$ order_id = null ,
1522
1531
$ order_product_id = null ,
1523
1532
$ procurement_product_id = null ,
@@ -1539,7 +1548,7 @@ public function recordStockHistory(
1539
1548
$ history ->before_quantity = $ old_quantity ; // if the stock management is 0, it shouldn't change
1540
1549
$ history ->quantity = abs ( $ quantity );
1541
1550
$ history ->after_quantity = $ new_quantity ; // if the stock management is 0, it shouldn't change
1542
- $ history ->author = Auth::id ();
1551
+ $ history ->author = $ author ?: Auth::id ();
1543
1552
$ history ->save ();
1544
1553
1545
1554
event ( new ProductAfterStockAdjustmentEvent ( $ history ) );
@@ -1839,7 +1848,7 @@ public function createProductVariation( Product $parent, $fields )
1839
1848
$ this ->__fillProductFields ( $ product , compact ( 'field ' , 'value ' , 'mode ' , 'fields ' ) );
1840
1849
}
1841
1850
1842
- $ product ->author = Auth:: id () ;
1851
+ $ product ->author = $ parent -> author ;
1843
1852
$ product ->parent_id = $ parent ->id ;
1844
1853
$ product ->type = $ parent ->type ;
1845
1854
$ product ->category_id = $ parent ->category_id ;
@@ -1848,11 +1857,6 @@ public function createProductVariation( Product $parent, $fields )
1848
1857
1849
1858
event ( new ProductAfterCreatedEvent ( $ product ) );
1850
1859
1851
- /**
1852
- * compute product tax
1853
- */
1854
- // $this->taxService->computeTax( $product, $fields[ 'tax_group_id' ] ?? null );
1855
-
1856
1860
return [
1857
1861
'status ' => 'success ' ,
1858
1862
'message ' => __ ( 'The product variation has been successfully created. ' ),
@@ -1884,7 +1888,7 @@ public function updateProductVariation( $parent, $id, $fields )
1884
1888
$ this ->__fillProductFields ( $ product , compact ( 'field ' , 'value ' , 'mode ' , 'fields ' ) );
1885
1889
}
1886
1890
1887
- $ product ->author = Auth:: id () ;
1891
+ $ product ->author = $ parent -> author ;
1888
1892
$ product ->parent_id = $ parent ->id ;
1889
1893
$ product ->type = $ parent ->type ;
1890
1894
$ product ->product_type = 'variation ' ;
0 commit comments