From 7e75df97aa1e38c124ef8dbeee014583431fce71 Mon Sep 17 00:00:00 2001 From: Kavinda Harshana Date: Mon, 21 Oct 2024 09:04:52 +0530 Subject: [PATCH] convert products as dataobjects --- src/Cart/ShoppingCart.php | 3 ++- src/Model/Product/OrderItem.php | 3 ++- src/Model/Variation/AttributeType.php | 2 +- src/Model/Variation/Variation.php | 2 +- src/Page/Product.php | 2 +- src/Page/ProductCategory.php | 3 ++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Cart/ShoppingCart.php b/src/Cart/ShoppingCart.php index 6f8b932d8..830d40872 100644 --- a/src/Cart/ShoppingCart.php +++ b/src/Cart/ShoppingCart.php @@ -16,6 +16,7 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Omnipay\Model\Payment; +use SilverStripe\ORM\DataObject; use SilverStripe\Security\Member; use SilverStripe\Security\Security; @@ -495,7 +496,7 @@ public function get(Buyable $buyable, $customFilter = []) */ public function getCorrectBuyable(Buyable $buyable) { - if ($buyable instanceof Product + if ($buyable instanceof DataObject && $buyable->hasExtension(ProductVariationsExtension::class) && $buyable->Variations()->count() > 0 ) { diff --git a/src/Model/Product/OrderItem.php b/src/Model/Product/OrderItem.php index 2f6cb49ac..e2a24b0bf 100644 --- a/src/Model/Product/OrderItem.php +++ b/src/Model/Product/OrderItem.php @@ -3,6 +3,7 @@ namespace SilverShop\Model\Product; use SilverShop\Page\Product; +use SilverStripe\ORM\DataObject; use SilverStripe\Versioned\Versioned; /** @@ -19,7 +20,7 @@ class OrderItem extends \SilverShop\Model\OrderItem ]; private static $has_one = [ - 'Product' => Product::class, + 'Product' => DataObject::class, ]; private static $table_name = 'SilverShop_Product_OrderItem'; diff --git a/src/Model/Variation/AttributeType.php b/src/Model/Variation/AttributeType.php index 1c86fd476..35e193e84 100644 --- a/src/Model/Variation/AttributeType.php +++ b/src/Model/Variation/AttributeType.php @@ -37,7 +37,7 @@ class AttributeType extends DataObject ]; private static $belongs_many_many = [ - 'Product' => Product::class, + 'Product' => DataObject::class, ]; private static $summary_fields = [ diff --git a/src/Model/Variation/Variation.php b/src/Model/Variation/Variation.php index e74b82d16..638a16391 100755 --- a/src/Model/Variation/Variation.php +++ b/src/Model/Variation/Variation.php @@ -54,7 +54,7 @@ class Variation extends DataObject implements Buyable ]; private static $has_one = [ - 'Product' => Product::class, + 'Product' => DataObject::class, 'Image' => Image::class ]; diff --git a/src/Page/Product.php b/src/Page/Product.php index 68ee8b5c1..2b6afb5cf 100644 --- a/src/Page/Product.php +++ b/src/Page/Product.php @@ -321,7 +321,7 @@ public function getCategories() * @return boolean */ public function canPurchase($member = null, $quantity = 1) - { + {die('aaaaaa'); $global = self::config()->global_allow_purchase; if (!$global || !$this->AllowPurchase) { diff --git a/src/Page/ProductCategory.php b/src/Page/ProductCategory.php index 1c2f8e215..dd223c848 100644 --- a/src/Page/ProductCategory.php +++ b/src/Page/ProductCategory.php @@ -6,6 +6,7 @@ use SilverShop\Extension\ProductVariationsExtension; use SilverStripe\i18n\i18nEntityProvider; use SilverStripe\ORM\DataList; +use SilverStripe\ORM\DataObject; /** * Product Category provides a way to hierartically categorise products. @@ -17,7 +18,7 @@ class ProductCategory extends Page implements i18nEntityProvider { private static $belongs_many_many = [ - 'Products' => Product::class, + 'Products' => DataObject::class, ]; private static $singular_name = 'Category';