function uc_cart_links_uc_add_to_cart in Ubercart 8.4
Same name and namespace in other branches
- 7.3 uc_cart_links/uc_cart_links.module \uc_cart_links_uc_add_to_cart()
Implements hook_uc_add_to_cart().
File
- uc_cart_links/
uc_cart_links.module, line 29 - Allows store owners to create links to add products to carts and send customers on to checkout.
Code
function uc_cart_links_uc_add_to_cart($nid, $qty, $data) {
if (\Drupal::currentUser()
->hasPermission('administer cart links') && \Drupal::config('uc_cart_links.settings')
->get('add_show')) {
$cart_link = 'p' . $nid . '_q' . $qty;
if (!empty($data['attributes'])) {
foreach ($data['attributes'] as $attribute => $option) {
if (is_array($option)) {
// Checkbox options are stored in an array.
foreach ($option as $oid => $ovalue) {
if ($ovalue != 0) {
$cart_link .= '_a' . $attribute . 'o' . $oid;
}
}
}
else {
// Textfield, Select, or Radio options.
$cart_link .= '_a' . $attribute . 'o' . $option;
}
}
}
\Drupal::messenger()
->addMessage(t('Cart Link product action: @cart_link', [
'@cart_link' => $cart_link,
]));
}
}