CartItemStorage.php in Ubercart 8.4
File
uc_cart/src/CartItemStorage.php
View source
<?php
namespace Drupal\uc_cart;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
class CartItemStorage extends SqlContentEntityStorage {
public function save(EntityInterface $entity) {
if ($entity->qty->value < 1) {
if (isset($entity->cart_item_id->value)) {
parent::delete([
$entity->cart_item_id->value => $entity,
]);
}
}
else {
$entity
->setChangedTime(REQUEST_TIME);
parent::save($entity);
}
}
public function getSchema() {
$schema = parent::getSchema();
$schema['uc_cart_products']['fields']['cart_id']['not null'] = TRUE;
$schema['uc_cart_products']['indexes'] += [
'cart_id' => [
'cart_id',
],
];
$schema['uc_cart_products']['foreign keys'] += [
'node' => [
'table' => 'node',
'columns' => [
'nid' => 'nid',
],
],
];
return $schema;
}
}