From 6e235737a64ad615e8af56b0eec5598af88fa674 Mon Sep 17 00:00:00 2001 From: "Colin Mollenhour (aider)" Date: Fri, 7 Feb 2025 18:33:59 -0500 Subject: [PATCH] feat: Add customer subscription model and database table --- .../Customer/Model/Resource/Subscription.php | 20 ++++++++ .../Resource/Subscription/Collection.php | 22 +++++++++ .../core/Mage/Customer/Model/Subscription.php | 26 ++++++++++ app/code/core/Mage/Customer/etc/config.xml | 3 ++ .../sql/customer_setup/install-1.0.0.php | 48 +++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 app/code/core/Mage/Customer/Model/Resource/Subscription.php create mode 100644 app/code/core/Mage/Customer/Model/Resource/Subscription/Collection.php create mode 100644 app/code/core/Mage/Customer/Model/Subscription.php create mode 100644 app/code/core/Mage/Customer/sql/customer_setup/install-1.0.0.php diff --git a/app/code/core/Mage/Customer/Model/Resource/Subscription.php b/app/code/core/Mage/Customer/Model/Resource/Subscription.php new file mode 100644 index 0000000000..cad34085db --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Subscription.php @@ -0,0 +1,20 @@ +_init('customer/subscription', 'subscription_id'); + } + + /** + * Set updated_at timestamp before saving + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate()); + return parent::_beforeSave($object); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Subscription/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Subscription/Collection.php new file mode 100644 index 0000000000..9652c7b5d5 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Subscription/Collection.php @@ -0,0 +1,22 @@ +_init('customer/subscription'); + } + + /** + * Filter collection by customer id + * @param int $customerId + * @return $this + */ + public function addCustomerFilter($customerId) + { + $this->addFieldToFilter('customer_id', $customerId); + return $this; + } +} diff --git a/app/code/core/Mage/Customer/Model/Subscription.php b/app/code/core/Mage/Customer/Model/Subscription.php new file mode 100644 index 0000000000..369c1b71ef --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Subscription.php @@ -0,0 +1,26 @@ +_init('customer/subscription'); + } + + /** + * Get subscription types as options array + * @return array + */ + public function getTypeOptions() + { + return array( + self::TYPE_WEEKLY => Mage::helper('customer')->__('Weekly'), + self::TYPE_MONTHLY => Mage::helper('customer')->__('Monthly') + ); + } +} diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 57bb22edeb..b74e5abf4c 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -370,6 +370,9 @@ customer_flowpassword
+ + customer_subscription
+
diff --git a/app/code/core/Mage/Customer/sql/customer_setup/install-1.0.0.php b/app/code/core/Mage/Customer/sql/customer_setup/install-1.0.0.php new file mode 100644 index 0000000000..9f86d940de --- /dev/null +++ b/app/code/core/Mage/Customer/sql/customer_setup/install-1.0.0.php @@ -0,0 +1,48 @@ +startSetup(); + +$table = $installer->getConnection() + ->newTable($installer->getTable('customer/subscription')) + ->addColumn('subscription_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Subscription ID') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Customer ID') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Subscription Type') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'default' => 'active' + ), 'Status') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT_UPDATE + ), 'Updated At') + ->addForeignKey( + $installer->getFkName('customer/subscription', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addIndex( + $installer->getIdxName('customer/subscription', array('customer_id')), + array('customer_id') + ) + ->setComment('Customer Subscription Table'); + +$installer->getConnection()->createTable($table); + +$installer->endSetup(); -- 2.34.1