Version Notes
support custom attributes
Download this release
Release Info
| Developer | Xiliang Sun |
| Extension | TheSunWeb_ConditionalTerms |
| Version | 1.1.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.0 to 1.1.0
- app/code/community/TheSunWeb/ConditionalTerms/Block/Adminhtml/Checkout/Agreement/Edit/Form.php +0 -0
- app/code/community/TheSunWeb/ConditionalTerms/Block/Checkout/Agreements.php +0 -0
- app/code/community/TheSunWeb/ConditionalTerms/Model/Checkout/Agreement.php +3 -0
- app/code/community/TheSunWeb/ConditionalTerms/Model/Observer.php +47 -0
- app/code/community/TheSunWeb/ConditionalTerms/controllers/Adminhtml/Checkout/AgreementController.php +0 -0
- app/code/community/TheSunWeb/ConditionalTerms/etc/config.xml +17 -1
- app/code/community/TheSunWeb/ConditionalTerms/sql/cterms_setup/mysql4-install-1.0.0.php +0 -0
- app/code/community/TheSunWeb/ConditionalTerms/sql/cterms_setup/mysql4-upgrade-1.0.0-1.1.0.php +19 -0
- app/design/adminhtml/default/default/layout/cterms.xml +0 -0
- app/etc/modules/TheSunWeb_ConditionalTerms.xml +0 -0
- package.xml +5 -5
app/code/community/TheSunWeb/ConditionalTerms/Block/Adminhtml/Checkout/Agreement/Edit/Form.php
CHANGED
|
File without changes
|
app/code/community/TheSunWeb/ConditionalTerms/Block/Checkout/Agreements.php
CHANGED
|
File without changes
|
app/code/community/TheSunWeb/ConditionalTerms/Model/Checkout/Agreement.php
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
<?php
|
| 2 |
class TheSunWeb_ConditionalTerms_Model_Checkout_Agreement extends Mage_Rule_Model_Abstract
|
| 3 |
{
|
|
|
|
|
|
|
|
|
|
| 4 |
/**
|
| 5 |
* Store rule combine conditions model
|
| 6 |
*
|
| 1 |
<?php
|
| 2 |
class TheSunWeb_ConditionalTerms_Model_Checkout_Agreement extends Mage_Rule_Model_Abstract
|
| 3 |
{
|
| 4 |
+
protected $_eventPrefix = 'checkout_agreement';
|
| 5 |
+
protected $_eventObject = 'agreement';
|
| 6 |
+
|
| 7 |
/**
|
| 8 |
* Store rule combine conditions model
|
| 9 |
*
|
app/code/community/TheSunWeb/ConditionalTerms/Model/Observer.php
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class TheSunWeb_ConditionalTerms_Model_Observer
|
| 3 |
+
{
|
| 4 |
+
public function saveAgreementAttributes(Varien_Event_Observer $observer)
|
| 5 |
+
{
|
| 6 |
+
$agreement = $observer->getAgreement();
|
| 7 |
+
|
| 8 |
+
$serializedString = serialize($agreement->getConditions()->asArray());
|
| 9 |
+
$attributes = array();
|
| 10 |
+
if (preg_match_all('~s:32:"salesrule/rule_condition_product";s:9:"attribute";s:\d+:"(.*?)"~s',
|
| 11 |
+
$serializedString, $matches)){
|
| 12 |
+
foreach ($matches[1] as $offset => $attributeCode) {
|
| 13 |
+
$attributes[] = $attributeCode;
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
if (count($attributes)) {
|
| 17 |
+
/* @var $resource Mage_Core_Model_Resource */
|
| 18 |
+
$resource = Mage::getSingleton("core/resource");
|
| 19 |
+
$read = $resource->getConnection("core_read");
|
| 20 |
+
$write = $resource->getConnection("core_write");
|
| 21 |
+
$write->delete($resource->getTableName('cterms/agreement_product_attribute'), array('agreement_id=?' => $agreement->getId()));
|
| 22 |
+
|
| 23 |
+
//Getting attribute IDs for attribute codes
|
| 24 |
+
$attributeIds = array();
|
| 25 |
+
$select = $read->select()
|
| 26 |
+
->from(array('a' => $resource->getTableName('eav/attribute')), array('a.attribute_id'))
|
| 27 |
+
->where('a.attribute_code IN (?)', array($attributes));
|
| 28 |
+
$attributesFound = $read->fetchAll($select);
|
| 29 |
+
if ($attributesFound) {
|
| 30 |
+
foreach ($attributesFound as $attribute) {
|
| 31 |
+
$attributeIds[] = $attribute['attribute_id'];
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
$data = array();
|
| 35 |
+
|
| 36 |
+
foreach ($attributeIds as $attribute) {
|
| 37 |
+
$data[] = array (
|
| 38 |
+
'agreement_id' => $agreement->getId(),
|
| 39 |
+
'attribute_id' => $attribute
|
| 40 |
+
);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
$write->insertMultiple($resource->getTableName('cterms/agreement_product_attribute'), $data);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
}
|
app/code/community/TheSunWeb/ConditionalTerms/controllers/Adminhtml/Checkout/AgreementController.php
CHANGED
|
File without changes
|
app/code/community/TheSunWeb/ConditionalTerms/etc/config.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<TheSunWeb_ConditionalTerms>
|
| 5 |
-
<version>1.
|
| 6 |
</TheSunWeb_ConditionalTerms>
|
| 7 |
</modules>
|
| 8 |
<global>
|
|
@@ -33,6 +33,11 @@
|
|
| 33 |
</cterms>
|
| 34 |
<cterms_mysql4>
|
| 35 |
<class>TheSunWeb_ConditionalTerms_Model_Mysql4</class>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</cterms_mysql4>
|
| 37 |
<checkout>
|
| 38 |
<rewrite>
|
|
@@ -47,6 +52,17 @@
|
|
| 47 |
</setup>
|
| 48 |
</cterms_setup>
|
| 49 |
</resources>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
</global>
|
| 51 |
<admin>
|
| 52 |
<routers>
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<TheSunWeb_ConditionalTerms>
|
| 5 |
+
<version>1.1.0</version>
|
| 6 |
</TheSunWeb_ConditionalTerms>
|
| 7 |
</modules>
|
| 8 |
<global>
|
| 33 |
</cterms>
|
| 34 |
<cterms_mysql4>
|
| 35 |
<class>TheSunWeb_ConditionalTerms_Model_Mysql4</class>
|
| 36 |
+
<entities>
|
| 37 |
+
<agreement_product_attribute>
|
| 38 |
+
<table>ks_agreement_product_attribute</table>
|
| 39 |
+
</agreement_product_attribute>
|
| 40 |
+
</entities>
|
| 41 |
</cterms_mysql4>
|
| 42 |
<checkout>
|
| 43 |
<rewrite>
|
| 52 |
</setup>
|
| 53 |
</cterms_setup>
|
| 54 |
</resources>
|
| 55 |
+
<events>
|
| 56 |
+
<checkout_agreement_save_after>
|
| 57 |
+
<observers>
|
| 58 |
+
<ks_agreement_save_attribute>
|
| 59 |
+
<type>singleton</type>
|
| 60 |
+
<class>cterms/observer</class>
|
| 61 |
+
<method>saveAgreementAttributes</method>
|
| 62 |
+
</ks_agreement_save_attribute>
|
| 63 |
+
</observers>
|
| 64 |
+
</checkout_agreement_save_after>
|
| 65 |
+
</events>
|
| 66 |
</global>
|
| 67 |
<admin>
|
| 68 |
<routers>
|
app/code/community/TheSunWeb/ConditionalTerms/sql/cterms_setup/mysql4-install-1.0.0.php
CHANGED
|
File without changes
|
app/code/community/TheSunWeb/ConditionalTerms/sql/cterms_setup/mysql4-upgrade-1.0.0-1.1.0.php
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
$installer = $this;
|
| 3 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
| 4 |
+
|
| 5 |
+
$installer->startSetup();
|
| 6 |
+
|
| 7 |
+
$installer->run("
|
| 8 |
+
-- DROP TABLE IF EXISTS `{$installer->getTable('cterms/agreement_product_attribute')}`;
|
| 9 |
+
CREATE TABLE `{$installer->getTable('cterms/agreement_product_attribute')}` (
|
| 10 |
+
`agreement_id` int(10) unsigned NOT NULL,
|
| 11 |
+
`attribute_id` smallint(5) unsigned NOT NULL,
|
| 12 |
+
PRIMARY KEY (`agreement_id`,`attribute_id`),
|
| 13 |
+
KEY `IDX_ATTRIBUTE` (`attribute_id`),
|
| 14 |
+
CONSTRAINT `FK_AGREEMENT_PRODUCT_ATTRIBUTE_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav/attribute')}` (`attribute_id`) ON DELETE CASCADE,
|
| 15 |
+
CONSTRAINT `FK_AGREEMENT_PRODUCT_ATTRIBUTE_AGREEMENT` FOREIGN KEY (`agreement_id`) REFERENCES `{$this->getTable('checkout/agreement')}` (`agreement_id`) ON DELETE CASCADE
|
| 16 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 17 |
+
");
|
| 18 |
+
|
| 19 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/cterms.xml
CHANGED
|
File without changes
|
app/etc/modules/TheSunWeb_ConditionalTerms.xml
CHANGED
|
File without changes
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>TheSunWeb_ConditionalTerms</name>
|
| 4 |
-
<version>1.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>OSL</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -9,11 +9,11 @@
|
|
| 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. 
|
| 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>
|
| 13 |
<authors><author><name>Xiliang Sun</name><user>ryansun</user><email>ryansun81@gmail.com</email></author></authors>
|
| 14 |
-
<date>2016-
|
| 15 |
-
<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="
|
| 17 |
<compatible/>
|
| 18 |
<dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
|
| 19 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>TheSunWeb_ConditionalTerms</name>
|
| 4 |
+
<version>1.1.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>OSL</license>
|
| 7 |
<channel>community</channel>
|
| 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. 
|
| 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>support custom attributes</notes>
|
| 13 |
<authors><author><name>Xiliang Sun</name><user>ryansun</user><email>ryansun81@gmail.com</email></author></authors>
|
| 14 |
+
<date>2016-08-23</date>
|
| 15 |
+
<time>04:46:43</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="822ccda2ebbfce8e50144ec24b873ccb"/></dir><file name="Observer.php" hash="22c1e00f8b3b200c0d7f693d34bacd77"/></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="15d64565bc588b17896c949c059efaa4"/></dir><dir name="sql"><dir name="cterms_setup"><file name="mysql4-install-1.0.0.php" hash="b386db3cf28c5b751b0bf2820b470c45"/><file name="mysql4-upgrade-1.0.0-1.1.0.php" hash="61b9e44c14be303da3a2ddbc7f59985f"/></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>
|
