我想为Magento 1.7添加自定义促销条件。应该可以根据客户的送货地址中的自定义属性应用促销。它实际上非常基本:如果属性被填充,促销应该适用,而不是更多。
它应该显示为购物车属性的单独条件点,如“装运邮政编码”或“装运区域”
还有什么帮助:如何实施标准购物车促销条件或在何处查找有关此主题的更多信息。 我现在在互联网上搜索了一段时间,我真的被卡住了。非常感谢您的帮助!
很多
答案 0 :(得分:4)
好的,我发现了一个或多或少的工作解决方案我想在这里分享,万一其他人需要这样做:
我创建了一个模块,即在促销活动中引入新条件。为实现这一目标而失踪的和平是通过观察者来实现的。
首先是配置<path to module>\etc\config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<HauteNature_FamilienkarteHessen>
<version>1.0.0</version>
</HauteNature_FamilienkarteHessen>
</modules>
<admin>
<fieldsets>
<customer_dataflow>
<building>
<billing>1</billing>
<shipping>1</shipping>
</building>
</customer_dataflow>
</fieldsets>
</admin>
<global>
<models>
<familienkartehessen>
<class>HauteNature_FamilienkarteHessen_Model</class>
</familienkartehessen>
</models>
<helpers>
<familienkartehessen>
<class>HauteNature_FamilienkarteHessen_Helper</class>
</familienkartehessen>
</helpers>
<events>
<salesrule_rule_condition_combine>
<observers>
<add_condition_to_sales_rule>
<class>familienkartehessen/observer</class>
<method>addConditionToSalesRule</method>
</add_condition_to_sales_rule>
</observers>
</salesrule_rule_condition_combine>
</events>
<resources>
<familienkartehessen_setup>
<setup>
<module>HauteNature_FamilienkarteHessen</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</familienkartehessen_setup>
</resources>
<fieldsets>
<sales_copy_order_billing_address>
<familiycarthessen><to_order>*</to_order></familiycarthessen>
</sales_copy_order_billing_address>
<sales_copy_order_shipping_address>
<familiycarthessen><to_order>*</to_order></familiycarthessen>
</sales_copy_order_shipping_address>
<sales_convert_quote_address>
<familiycarthessen><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></familiycarthessen>
</sales_convert_quote_address>
<sales_convert_order_address>
<familiycarthessen><to_quote_address>*</to_quote_address></familiycarthessen>
</sales_convert_order_address>
<customer_address>
<familiycarthessen><to_quote_address>*</to_quote_address></familiycarthessen>
</customer_address>
<checkout_onepage_billing>
<familiycarthessen><to_customer>*</to_customer></familiycarthessen>
</checkout_onepage_billing>
</fieldsets>
</global>
</config>
我认为这部分是将它哄骗到magento界面:
<salesrule_rule_condition_combine>
<observers>
<add_condition_to_sales_rule>
<class>familienkartehessen/observer</class>
<method>addConditionToSalesRule</method>
</add_condition_to_sales_rule>
</observers>
</salesrule_rule_condition_combine>
观察者,非常简单,只需将菜单指针添加到UI并将其链接到条件:<path to module>\Model\Observer.php
:
class HauteNature_FamilienkarteHessen_Model_Observer extends Mage_Core_Model_Abstract {
/**
* Event: salesrule_rule_condition_combine
*
* @param $observer
*/
public function addConditionToSalesRule($observer) {
$additional = $observer->getAdditional();
$conditions = (array) $additional->getConditions();
$conditions = array_merge_recursive($conditions, array(
array('label'=>Mage::helper('familienkartehessen')->__('Familienkarte Hessen'), 'value'=>'familienkartehessen/condition_familienkarte'),
));
$additional->setConditions($conditions);
$observer->setAdditional($additional);
return $observer;
}
}
最后是实际完成工作的自定义条件类<path to module>\Model\Condition/Familienkarte.php
:
class HauteNature_FamilienkarteHessen_Model_Condition_Familienkarte extends Mage_Rule_Model_Condition_Abstract {
/**
* @TODO for whatever this it, check it and afterwards document it!
*
* @return Hackathon_DiscountForATweet_Model_Condition_Tweet
*/
public function loadAttributeOptions() {
$attributes = array(
'fkhContent' => Mage::helper('familienkartehessen')->__('Familienkarte Hessen')
);
$this->setAttributeOption($attributes);
return $this;
}
/**
* @TODO for whatever this it, check it and afterwards document it!
*
* @return mixed
*/
public function getAttributeElement() {
$element = parent::getAttributeElement();
$element->setShowAsText(true);
return $element;
}
/**
* @TODO for whatever this it, check it and afterwards document it!
*
* @return string
*/
public function getInputType() {
switch ($this->getAttribute()) {
case 'fkhContent':
return 'boolean';
}
return 'string';
}
/**
* @TODO for whatever this it, check it and afterwards document it!
* @return string
*/
public function getValueElementType() {
return 'text';
}
/**
* Validate FamiliencarteHessen Rule Condition
*
* @param Varien_Object $object
*
* @return bool
*/
public function validate(Varien_Object $object) {
/* here should be something meaningful */
$address = $object;
if (!$address instanceof Mage_Sales_Model_Quote_Address) {
if ($object->getQuote()->isVirtual()) {
$address = $object->getQuote()->getBillingAddress();
}
else {
$address = $object->getQuote()->getShippingAddress();
}
}
return $this->validateAttribute(trim($address->getFamiliycarthessen()));
}
}
如果你们中的任何人对此代码有任何意见,我会很高兴听到他们的意见。
祝你好运 安德烈亚斯