I have 3 Terms and Conditions for checkout process. All 3 T&C are just checkboxes because I did some changes in template hiding the content box. By default Magento is listing the terms one after other based on their ID's. Did anyone change the module inserting in checkout_agreement table a new field called position and let Magento sorting by it?
-
Upvoted because sounds like i missing feature, that I also would use ... full code comes tomorrow (if i have some time for it :) )– sv3nMay 13, 2017 at 20:45
-
I agree it is a feature missing. Imagine having lots of terms how you order them in checkout. For example I am asking customers to check the boxes for many things being legal. I am still editing ID's to re-order the terms.– ADDISON74May 15, 2017 at 9:47
-
Another thing which is missing, wysiwyg editor is not working for editing content in html. This can be activate in /Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php $fieldset 'content', wysiwyg = true.– ADDISON74May 15, 2017 at 9:48
-
One more thing I did for good is making content required => false. In this way the database is filled in with NULL then in agreement template I can evaluate if content is NULL not showing the html code. Sometimes you couldn't have content for all terms (my case).– ADDISON74May 15, 2017 at 9:50
1 Answer
Here we go ...
app\code\community\Sr\AgreementPosition\sql\sr_agreement_setup\mysql4-install-0.0.1.php
<?php
/** @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
$installer = $this;
$installer->startSetup();
if (version_compare(Mage::getVersion(), '1.6', '<')) {
$installer->run("
ALTER TABLE `{$installer->getTable('checkout/agreement')}`
ADD `position` SMALLINT( 2 ) NOT NULL COMMENT 'Agreement Position'
");
} else {
$installer->getConnection()->addColumn(
$installer->getTable('checkout/agreement'),
'position',
array(
'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
'length' => 2,
'nullable' => false,
'default' => 0,
'comment' => 'Agreement Position'
)
);
}
$installer->endSetup();
app\code\community\Sr\AgreementPosition\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sr_AgreementPosition>
<version>0.0.1</version>
</Sr_AgreementPosition>
</modules>
<global>
<helpers>
<sr_agreement>
<class>Sr_AgreementPosition_Helper</class>
</sr_agreement>
</helpers>
<models>
<sr_agreement>
<class>Sr_AgreementPosition_Model</class>
<resourceModel>sr_agreement_resource</resourceModel>
</sr_agreement>
<sr_agreement_resource>
<class>Sr_AgreementPosition_Model_Resource</class>
</sr_agreement_resource>
</models>
<resources>
<sr_agreement_setup>
<setup>
<module>Sr_AgreementPosition</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
</sr_agreement_setup>
</resources>
</global>
<frontend>
<events>
<core_block_abstract_to_html_before>
<observers>
<sr_agreement_observer>
<class>sr_agreement/observer</class>
<type>model</type>
<method>sortAgreements</method>
</sr_agreement_observer>
</observers>
</core_block_abstract_to_html_before>
</events>
</frontend>
<adminhtml>
<events>
<adminhtml_block_html_before>
<observers>
<sr_agreement_observer_agreement>
<class>sr_agreement/observer</class>
<type>model</type>
<method>addAgreementsPosition</method>
</sr_agreement_observer_agreement>
</observers>
</adminhtml_block_html_before>
</events>
</adminhtml>
</config>
app\code\community\Sr\AgreementPosition\Model\Observer.php
<?php
class Sr_AgreementPosition_Model_Observer
{
/**
* Add "Postion" to Checkout Agreements
*/
public function addAgreementsPosition(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Checkout_Agreement_Edit_Form) {
$helper = Mage::helper('sr_agreement');
$form = $block->getForm();
$form->getElement('content')->setRequired(false);
/** @var Varien_Data_Form_Element_Fieldset $fieldset */
$fieldset = $form->getElement('base_fieldset');
$fieldset->addField('position', 'text', array(
'label' => $helper->__('Position'),
'title' => $helper->__('Position'),
'name' => 'position',
'value' => '0',
'class' => 'validate-zero-or-greater',
));
$model = Mage::registry('checkout_agreement');
$form->setValues($model->getData());
$block->setForm($form);
}
return $this;
}
/**
* Sort agreements
*/
public function sortAgreements(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block->getType() == 'checkout/agreements') {
if ($agreements = $block->getAgreements()) {
$agreements->setOrder('position', Varien_Data_Collection::SORT_ORDER_ASC);
$collection = new Varien_Data_Collection();
foreach ($agreements as $agreement) {
$collection->addItem($agreement);
}
$observer->getEvent()->getBlock()->setAgreements($collection);
}
}
return $this;
}
}
Didn't post helper and modules xml ... download here: https://github.com/sreichel/magento-Sr-AgreementPosition
Note: If you find issues please open a ticket at Github.
Edit: making content optional is just a one liner in observer and will be added later (no more time now)
$form->getElement('content')->setRequired(false);
-
I appreciate for your help. I will test your solution and coming back with impressions. I have a long list of Magento 1 issues which are not resolved yet, same like this one. Bug Tracker is not working at all for Magento 1 and I don't like this. I will follow your advice related to reporting, I have the same nickname in Github. May 15, 2017 at 18:37
-
If you had told me, that you are using Firegento_MageSetup, i had just made this only PR there, instead of creatinge a standalone module :P For your long list of issues ... this one is more a missing feature request, but if you know "real" bugs - or things that affect should be imporved for everybody - you can open a ticket here: github.com/OpenMage/magento-lts Btw ... i've already seen you add github :P– sv3nMay 15, 2017 at 20:08
-
-
Please update the code for making content optional too. Of course when you have some time. In this way we can implement the whole solution. Any thoughts why wysiwyg editor is not working for content if set to true in php file? May 17, 2017 at 15:39
-
I'll add optional content later .... but i'll not add WYSIWYG for now, b/c i'm not sure if all filters (for widgets etc. will work correctly ther - and i dont like this editor in general. Shouldn't be too hard to write some basic HTML for terms & conditions ... ;) ) I'll leave a comment ASAP.– sv3nMay 17, 2017 at 19:05