TheSunWeb_ConditionalTerms - Version 1.0.0

Version Notes

Initial version

Download this release

Release Info

Developer Xiliang Sun
Extension TheSunWeb_ConditionalTerms
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/TheSunWeb/ConditionalTerms/Block/Adminhtml/Checkout/Agreement/Edit/Form.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TheSunWeb_ConditionalTerms_Block_Adminhtml_Checkout_Agreement_Edit_Form extends Mage_Adminhtml_Block_Checkout_Agreement_Edit_Form
3
+ {
4
+ /**
5
+ *
6
+ * return Mage_Adminhtml_Block_Widget_Form
7
+ */
8
+ protected function _prepareForm()
9
+ {
10
+ parent::_prepareForm();
11
+ $form = $this->getForm();
12
+
13
+ $form->setHtmlIdPrefix('rule_');
14
+ $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
15
+ ->setTemplate('promo/fieldset.phtml')
16
+ ->setNewChildUrl($this->getUrl('*/promo_catalog/newConditionHtml/form/rule_conditions_fieldset'));
17
+
18
+ $fieldset = $form->addFieldset('conditions_fieldset', array(
19
+ 'legend'=>Mage::helper('catalogrule')->__('Conditions (leave blank for all products)'))
20
+ )->setRenderer($renderer);
21
+
22
+ $model = Mage::registry('checkout_agreement');
23
+ //$model = Mage::getModel('salesrule/rule');
24
+ $fieldset->addField('conditions', 'text', array(
25
+ 'name' => 'conditions',
26
+ 'label' => Mage::helper('catalogrule')->__('Conditions'),
27
+ 'title' => Mage::helper('catalogrule')->__('Conditions'),
28
+ 'required' => true,
29
+ ))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
30
+
31
+ $form->setValues($model->getData());
32
+ return $this;
33
+ }
34
+ }
app/code/community/TheSunWeb/ConditionalTerms/Block/Checkout/Agreements.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TheSunWeb_ConditionalTerms_Block_Checkout_Agreements extends Mage_Checkout_Block_Agreements
3
+ {
4
+ public function getAgreements()
5
+ {
6
+ if (!$this->hasAgreements()) {
7
+ if (!Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
8
+ $agreements = array();
9
+ } else {
10
+ $agreements = Mage::getModel('checkout/agreement')->getCollection()
11
+ ->addStoreFilter(Mage::app()->getStore()->getId())
12
+ ->addFieldToFilter('is_active', 1);
13
+ $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
14
+ foreach($agreements as $agreement) {
15
+ if(!$agreement->getConditions()->validate($address)) {
16
+ $agreements->removeItemByKey($agreement->getId());
17
+ }
18
+ }
19
+ }
20
+ $this->setAgreements($agreements);
21
+ }
22
+ return $this->getData('agreements');
23
+ }
24
+ }
app/code/community/TheSunWeb/ConditionalTerms/Model/Checkout/Agreement.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TheSunWeb_ConditionalTerms_Model_Checkout_Agreement extends Mage_Rule_Model_Abstract
3
+ {
4
+ /**
5
+ * Store rule combine conditions model
6
+ *
7
+ * @var Mage_Rule_Model_Condition_Combine
8
+ */
9
+ protected $_conditions;
10
+
11
+ protected function _construct()
12
+ {
13
+ $this->_init('checkout/agreement');
14
+ }
15
+
16
+ /**
17
+ * Get rule condition combine model instance
18
+ *
19
+ * @return Mage_SalesRule_Model_Rule_Condition_Combine
20
+ */
21
+ public function getConditionsInstance()
22
+ {
23
+ return Mage::getModel('salesrule/rule_condition_combine');
24
+ }
25
+
26
+ /**
27
+ * Get rule condition product combine model instance
28
+ *
29
+ * @return Mage_SalesRule_Model_Rule_Condition_Product_Combine
30
+ */
31
+ public function getActionsInstance()
32
+ {
33
+ return Mage::getModel('salesrule/rule_condition_product_combine');
34
+ }
35
+ }
app/code/community/TheSunWeb/ConditionalTerms/controllers/Adminhtml/Checkout/AgreementController.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Mage/Adminhtml/controllers/Checkout/AgreementController.php';
3
+ class TheSunWeb_ConditionalTerms_Adminhtml_Checkout_AgreementController extends Mage_Adminhtml_Checkout_AgreementController
4
+ {
5
+ public function editAction()
6
+ {
7
+ $this->_title($this->__('Sales'))->_title($this->__('Terms and Conditions'));
8
+
9
+ $id = $this->getRequest()->getParam('id');
10
+ $agreementModel = Mage::getModel('checkout/agreement');
11
+
12
+ if ($id) {
13
+ $agreementModel->load($id);
14
+ if (!$agreementModel->getId()) {
15
+ Mage::getSingleton('adminhtml/session')->addError(
16
+ Mage::helper('checkout')->__('This condition no longer exists.')
17
+ );
18
+ $this->_redirect('*/*/');
19
+ return;
20
+ }
21
+ }
22
+
23
+ $this->_title($agreementModel->getId() ? $agreementModel->getName() : $this->__('New Condition'));
24
+
25
+ $data = Mage::getSingleton('adminhtml/session')->getAgreementData(true);
26
+ if (!empty($data)) {
27
+ $agreementModel->setData($data);
28
+ }
29
+
30
+ $agreementModel->getConditions()->setJsFormObject('rule_conditions_fieldset');
31
+ Mage::register('checkout_agreement', $agreementModel);
32
+
33
+ $this->_initAction()
34
+ ->_addBreadcrumb($id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'), $id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'))
35
+ ->_addContent($this->getLayout()->createBlock('adminhtml/checkout_agreement_edit')->setData('action', $this->getUrl('*/*/save')))
36
+ ->renderLayout();
37
+ }
38
+
39
+ public function saveAction()
40
+ {
41
+ if ($postData = $this->getRequest()->getPost()) {
42
+ $model = Mage::getSingleton('checkout/agreement');
43
+
44
+ $postData['conditions'] = $postData['rule']['conditions'];
45
+ unset($postData['rule']);
46
+
47
+ $model->loadPost($postData);
48
+
49
+ $model->setData($postData);
50
+
51
+ try {
52
+ $model->save();
53
+
54
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('The condition has been saved.'));
55
+ $this->_redirect('*/*/');
56
+
57
+ return;
58
+ }
59
+ catch (Mage_Core_Exception $e) {
60
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
61
+ }
62
+ catch (Exception $e) {
63
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('An error occurred while saving this condition.'));
64
+ }
65
+
66
+ Mage::getSingleton('adminhtml/session')->setAgreementData($postData);
67
+ $this->_redirectReferer();
68
+ }
69
+ }
70
+ }
app/code/community/TheSunWeb/ConditionalTerms/etc/config.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <TheSunWeb_ConditionalTerms>
5
+ <version>1.0.0</version>
6
+ </TheSunWeb_ConditionalTerms>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <cterms>
11
+ <class>TheSunWeb_ConditionalTerms_Helper</class>
12
+ </cterms>
13
+ </helpers>
14
+ <blocks>
15
+ <cterms>
16
+ <class>TheSunWeb_ConditionalTerms_Block</class>
17
+ </cterms>
18
+ <adminhtml>
19
+ <rewrite>
20
+ <checkout_agreement_edit_form>TheSunWeb_ConditionalTerms_Block_Adminhtml_Checkout_Agreement_Edit_Form</checkout_agreement_edit_form>
21
+ </rewrite>
22
+ </adminhtml>
23
+ <checkout>
24
+ <rewrite>
25
+ <agreements>TheSunWeb_ConditionalTerms_Block_Checkout_Agreements</agreements>
26
+ </rewrite>
27
+ </checkout>
28
+ </blocks>
29
+ <models>
30
+ <cterms>
31
+ <class>TheSunWeb_ConditionalTerms_Model</class>
32
+ <resourceModel>cterms_mysql4</resourceModel>
33
+ </cterms>
34
+ <cterms_mysql4>
35
+ <class>TheSunWeb_ConditionalTerms_Model_Mysql4</class>
36
+ </cterms_mysql4>
37
+ <checkout>
38
+ <rewrite>
39
+ <agreement>TheSunWeb_ConditionalTerms_Model_Checkout_Agreement</agreement>
40
+ </rewrite>
41
+ </checkout>
42
+ </models>
43
+ <resources>
44
+ <cterms_setup>
45
+ <setup>
46
+ <module>TheSunWeb_ConditionalTerms</module>
47
+ </setup>
48
+ </cterms_setup>
49
+ </resources>
50
+ </global>
51
+ <admin>
52
+ <routers>
53
+ <adminhtml>
54
+ <args>
55
+ <modules>
56
+ <TheSunWeb_ConditionalTerms before="Mage_Adminhtml">TheSunWeb_ConditionalTerms_Adminhtml</TheSunWeb_ConditionalTerms>
57
+ </modules>
58
+ </args>
59
+ </adminhtml>
60
+ </routers>
61
+ </admin>
62
+ <adminhtml>
63
+ <layout>
64
+ <updates>
65
+ <cterms>
66
+ <file>cterms.xml</file>
67
+ </cterms>
68
+ </updates>
69
+ </layout>
70
+ </adminhtml>
71
+ </config>
app/code/community/TheSunWeb/ConditionalTerms/sql/cterms_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ /* @var $installer Mage_Core_Model_Resource_Setup */
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+ ALTER TABLE `{$this->getTable('checkout/agreement')}`
9
+ ADD COLUMN `conditions_serialized` text NOT NULL;
10
+ ");
11
+
12
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/cterms.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_checkout_agreement_edit>
4
+ <reference name="head">
5
+ <action method="setCanLoadExtJs"><flag>1</flag></action>
6
+ <action method="setCanLoadRulesJs"><flag>1</flag></action>
7
+ </reference>
8
+ </adminhtml_checkout_agreement_edit>
9
+ </layout>
app/etc/modules/TheSunWeb_ConditionalTerms.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <TheSunWeb_ConditionalTerms>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </TheSunWeb_ConditionalTerms>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>TheSunWeb_ConditionalTerms</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Multiple Dynamic Terms and Agreements Management</summary>
10
+ <description>Allows website to show different agreements and terms base on different products, categories, cart total, shipping address and etc in cart. &#xD;
11
+ Its inspired and requested by https://community.magento.com/t5/Programming-Questions/Dynamic-Terms-and-Conditions-based-on-Product-Selection/m-p/14416</description>
12
+ <notes>Initial version</notes>
13
+ <authors><author><name>Xiliang Sun</name><user>ryansun</user><email>ryansun81@gmail.com</email></author></authors>
14
+ <date>2016-06-13</date>
15
+ <time>20:42:34</time>
16
+ <contents><target name="magecommunity"><dir name="TheSunWeb"><dir name="ConditionalTerms"><dir name="Block"><dir name="Adminhtml"><dir name="Checkout"><dir name="Agreement"><dir name="Edit"><file name="Form.php" hash="61bbe9ca3ef2ee3d4361c64a9498ff5d"/></dir></dir></dir></dir><dir name="Checkout"><file name="Agreements.php" hash="0d8d75e7ee146282580e234e1d013149"/></dir></dir><dir name="Model"><dir name="Checkout"><file name="Agreement.php" hash="edf83aa5802fd0576ca4d8590a00cef6"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Checkout"><file name="AgreementController.php" hash="91bab32e79934ee59626cb39008726b9"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="f65148f03b262297077fe4059c9ce76e"/></dir><dir name="sql"><dir name="cterms_setup"><file name="mysql4-install-1.0.0.php" hash="b386db3cf28c5b751b0bf2820b470c45"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="cterms.xml" hash="812e715879dcf055aa5372b467ffa8b0"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TheSunWeb_ConditionalTerms.xml" hash="ec90ec8570f461346a013f75c1608747"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>