function uc_ups_node_load in Ubercart 8.4
Same name and namespace in other branches
- 7.3 shipping/uc_ups/uc_ups.module \uc_ups_node_load()
Implements hook_node_load().
File
- shipping/
uc_ups/ uc_ups.module, line 173 - UPS shipping quote module.
Code
function uc_ups_node_load($nodes) {
$nids = [];
foreach ($nodes as $node) {
if (uc_product_is_product($node)) {
$nids[] = $node
->id();
}
}
if (empty($nids)) {
return;
}
$vids = [];
$connection = \Drupal::database();
$ups_config = \Drupal::config('uc_ups.settings');
$shipping_type = $ups_config
->get('uc_store_shipping_type');
$shipping_types = $connection
->query("SELECT id, shipping_type FROM {uc_quote_shipping_types} WHERE id_type = :type AND id IN (:ids[])", [
':type' => 'product',
':ids[]' => $nids,
])
->fetchAllKeyed();
foreach ($nids as $nid) {
if (isset($shipping_types[$nid])) {
$nodes[$nid]->shipping_type = $shipping_types[$nid];
}
else {
$nodes[$nid]->shipping_type = $shipping_type;
}
if ($nodes[$nid]->shipping_type == 'small_package') {
$vids[$nid] = $nodes[$nid]
->getRevisionId();
}
}
if ($vids) {
$result = $connection
->query("SELECT * FROM {uc_ups_products} WHERE vid IN (:vids[])", [
':vids[]' => $vids,
], [
'fetch' => PDO::FETCH_ASSOC,
]);
foreach ($result as $ups) {
$nodes[$ups['nid']]->ups = $ups;
}
}
}