function uc_usps_node_load in Ubercart 8.4
Same name and namespace in other branches
- 7.3 shipping/uc_usps/uc_usps.module \uc_usps_node_load()
Implements hook_node_load().
File
- shipping/
uc_usps/ uc_usps.module, line 86 - United States Postal Service (USPS) shipping quote module.
Code
function uc_usps_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();
$usps_config = \Drupal::config('uc_usps.settings');
$shipping_type = $usps_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_usps_products} WHERE vid IN (:vids[])", [
':vids[]' => $vids,
], [
'fetch' => PDO::FETCH_ASSOC,
]);
foreach ($result as $usps) {
$nodes[$usps['nid']]->usps = $usps;
}
}
}