| 1 |
<?php namespace TierPricingTable\Forms; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainer; |
| 4 |
|
| 5 |
class MinimumOrderQuantityForm { |
| 6 |
|
| 7 |
public static function render( |
| 8 |
$role = null, |
| 9 |
$loop = null, |
| 10 |
$minimumOrderQuantity = null |
| 11 |
) { |
| 12 |
ServiceContainer::getInstance()->getFileManager()->includeTemplate( 'admin/components/minimum-order-quantity-form.php', |
| 13 |
array( |
| 14 |
'role' => $role, |
| 15 |
'loop' => $loop, |
| 16 |
'minimum_order_quantity' => $minimumOrderQuantity, |
| 17 |
) ); |
| 18 |
} |
| 19 |
|
| 20 |
public static function getDataFromRequest( $role = null, $loop = null, $request = null ) { |
| 21 |
|
| 22 |
$data = array(); |
| 23 |
|
| 24 |
$fields = array( |
| 25 |
'minimum_order_quantity' => function ( $quantity ) { |
| 26 |
return ! is_null( $quantity ) && '' !== $quantity ? max( 1, intval( $quantity ) ) : null; |
| 27 |
}, |
| 28 |
); |
| 29 |
|
| 30 |
foreach ( $fields as $fieldKey => $sanitizeFunction ) { |
| 31 |
$data[ $fieldKey ] = call_user_func( $sanitizeFunction, |
| 32 |
Form::getFieldValue( $fieldKey, $role, $loop, null, $request ) ); |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
return $data; |
| 37 |
} |
| 38 |
} |
| 39 |
|