public function Products::submitForm in Ubercart 8.4
Form submission handler.
Parameters
\Drupal\uc_order\OrderInterface $order: The order that is being viewed.
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides EditableOrderPanePluginInterface::submitForm
File
- uc_order/
src/ Plugin/ Ubercart/ OrderPane/ Products.php, line 176
Class
- Products
- Manage the products an order contains.
Namespace
Drupal\uc_order\Plugin\Ubercart\OrderPaneCode
public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state) {
// @todo Decouple stock related code into uc_stock
if (\Drupal::moduleHandler()
->moduleExists('uc_stock')) {
$qtys = [];
foreach ($order->products as $product) {
$qtys[$product
->id()] = intval($product->qty->value);
}
}
if (is_array($form_state
->getValue('products'))) {
foreach ($form_state
->getValue('products') as $product) {
if (isset($order->products[$product['order_product_id']])) {
foreach ([
'qty',
'title',
'model',
'cost',
'price',
] as $field) {
if (!empty($product[$field])) {
$order->products[$product['order_product_id']]->{$field}->value = $product[$field];
}
}
// Weight is stored as an array, so we should handle it another way.
if (!empty($product['weight']) && !empty($product['weight_units'])) {
$weight = [
'value' => $product['weight'],
'units' => $product['weight_units'],
];
$order->products[$product['order_product_id']]->weight
->setValue($weight);
}
if (\Drupal::moduleHandler()
->moduleExists('uc_stock')) {
$temp = $product['qty'];
$order->products[$product['order_product_id']]->qty->value = $product['qty'] - $qtys[$product['order_product_id']];
uc_stock_adjust_product_stock($order->products[$product['order_product_id']], 0, $order);
$order->products[$product['order_product_id']]->qty->value = $temp;
}
}
}
}
}