2

我正在研究 Xcart-5 网站定制。我创建了自己的模块并为此进行了工作。我刚刚创建了一些全局属性(“作为纯文本”)字段并将这些属性分配给某些产品。现在我想在产品详细信息页面的编程中访问这些字段值,以便在运行时以编程方式分配一些其他值。

我怎样才能完成这个任务。请给我解决方案。

4

1 回答 1

0

在您的模块中,您应该装饰\XLite\Model\Attribute类并在那里扩展getAttributeValue()方法。

例如,如果我使用具有开发人员 ID Tony和模块 ID AttributesDemo的模块,那么我需要创建具有以下内容的XCartDirectory/classes/XLite/Module/Tony/AttributesDemo/Model/Attribute.php文件:

<?php
// vim: set ts=4 sw=4 sts=4 et:

namespace XLite\Module\Tony\AttributesDemo\Model;

/**
 * Attribute
 * @MappedSuperClass
 */
abstract class Attribute extends \XLite\Model\AttributeAbstract implements \XLite\Base\IDecorator
{
    public function getAttributeValue(\XLite\Model\Product $product, $asString = false)
    {
        $result = parent::getAttributeValue($product, $asString);

        if (!$asString) {
            foreach ($result as $obj) {
                if ($obj->asString() == 'Mac') {
                    $obj->getAttributeOption()->setName('Windows');
                }
            }
        }

        return $result;
    }
}

这样的实现会将所有属性中的Mac值更改为Windows值。

于 2015-03-04T22:12:38.823 回答