我目前正在开发一个在后端使用产品编辑的模块.其目的是检索产品所属的类别,并使用所选类别列表填充属性(Brand属性).
管理员必须至少选择一个类别.
我的模块按预期工作,但如果管理员在编辑产品时没有选择任何类别,我不知道如何停止保存过程.
这是工作流程
- >如果有选定的类别
- >其他
通用问题可能是:如何将"停止保存"参数传递给观察者?
以下是我的config.xml文件示例以及处理我上面解释的工作流程的方法.
非常感谢您的帮助,并享受Magentoing的乐趣!
config.xml中
<catalog_product_prepare_save>
<observers>
<brands_product_save_observer>
<type>singleton</type>
<class>brands/observer</class>
<method>saveProductBrand</method>
</brands_product_save_observer>
</observers>
</catalog_product_prepare_save>
Run Code Online (Sandbox Code Playgroud)
Observer.php
public function saveProductBrand($observer) {
$product = $observer->getProduct();
$categoryIds = $product->getCategoryIds();
if (isset($categoryIds)) {
foreach ($categoryIds as $categoryId) {
$isBrandCategory = Mage::getModel('brands/navigation')->isBrandCategory($categoryId);
if ($isBrandCategory)
$brandCategories[] = $categoryId;
}
if (isset($brandCategories)) {
$brandId = Mage::getModel('brands/navigation')->getBrand($brandCategories[0]);
if ($brandId) {
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 140);
foreach ($attribute->getSource()->getAllOptions(true, true) as $option) {
$attributeArray[$option['label']] = $option['value'];
}
$categoryName = …Run Code Online (Sandbox Code Playgroud) 是否可以在magento中调用另一个动作?
例如,让我们考虑两种行动方法
是否可以在调用addAction()时调用updateAction()?
谢谢,巴兰
我在事件checkout_controller_onepage_save_shipping_method期间验证运费报价,如果验证失败,我想将用户发送回运送方式选择,但我还想显示一条消息,说明它失败的原因.Magento有办法内置吗?
我已经在验证数据,我只是缺少重定向到发货方式和显示消息的方式.