CartProduct.php 738 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace Entity;
  3. class CartProduct extends ModelBase
  4. {
  5. protected function install()
  6. {
  7. $dbPrefix = $this->getDbPrefix();
  8. $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}cart_product` (
  9. `cart_id` INTEGER(11) UNSIGNED NOT NULL,
  10. `product_id` INTEGER(11) UNSIGNED NULL,
  11. `quantity` INTEGER(10) UNSIGNED NOT NULL,
  12. FOREIGN KEY (`cart_id`) REFERENCES `{$dbPrefix}cart`(id),
  13. FOREIGN KEY (`product_id`) REFERENCES `{$dbPrefix}product`(id),
  14. UNIQUE(`cart_id`, `product_id`)
  15. )");
  16. if ($result === false)
  17. throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
  18. return true;
  19. }
  20. }