diff --git a/uc_cart/uc_cart.module b/uc_cart/uc_cart.module
index 9e32faa..d87edbb 100644
--- a/uc_cart/uc_cart.module
+++ b/uc_cart/uc_cart.module
@@ -1147,30 +1147,33 @@ function uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE
}
}
- $item = db_query("SELECT * FROM {uc_cart_products} WHERE cart_id = :cart_id AND nid = :nid AND data = :data", array(':cart_id' => $cid, ':nid' => $node->nid, ':data' => serialize($data)))->fetchObject();
-
+ $efq = new EntityFieldQuery();
+ $ids = $efq->entityCondition('entity_type', 'uc_cart_item')
+ ->propertyCondition('cart_id', $cid)
+ ->propertyCondition('nid', $node->nid)
+ ->propertyCondition('data', serialize($data))
+ ->execute();
+
// If the item isn't in the cart yet, add it.
- if (is_null($item) || $item === FALSE) {
- db_insert('uc_cart_products')
- ->fields(array(
- 'cart_id' => $cid,
- 'nid' => $node->nid,
- 'qty' => $qty,
- 'changed' => REQUEST_TIME,
- 'data' => serialize($data),
- ))
- ->execute();
+ if (empty($ids['uc_cart_item'])) {
+ $item_entity = entity_create('uc_cart_item',array('cart_id' => $cid, 'nid' => $node->nid, 'qty' => $qty, 'changed' => REQUEST_TIME, 'data' => $data));
+ entity_save('uc_cart_item', $item_entity);
if ($msg) {
drupal_set_message(t('@product-title added to your shopping cart.', array('@product-title' => $node->title, '!url' => url('cart'))));
}
}
else {
+ //TODO: should be a better way
+ $entities = array_keys($ids['uc_cart_item']);
+ $item_entity = entity_load_single('uc_cart_item', $entities[0]);
// Update the item instead.
if ($msg) {
drupal_set_message(t('Your item(s) have been updated.'));
}
- $qty += $item->qty;
- module_invoke($data['module'], 'uc_update_cart_item', $node->nid, $data, min($qty, 999999), $cid);
+ $item_entity->qty += $qty;
+ //TODO: I don't know if this hook should be called or not anymore
+ //module_invoke($data['module'], 'uc_update_cart_item', $node->nid, $data, min($qty, 999999), $cid);
+ entity_save('uc_cart_item', $item_entity);
}
// If specified, rebuild the cached cart items array.