2015-03-03 94 views
0

我正在進行Xcart-5網站定製。我創建了自己的模塊並在其上進行工作。我剛剛創建了一些全局屬性(「作爲純文本」)字段並將這些屬性分配給某個產品。現在,我想在產品詳細信息頁面的編程中訪問這些字段的值,以便在運行時以編程方式分配其他值。XCART-5在編程中獲取屬性值並對其他值進行編程

我該如何完成這項任務。請爲我提供解決方案。

回答

1

在你的模塊,你應該decorate\ X-Lite \型號\屬性類和延伸getAttributeValue()方法那裏。

例如,如果我使用一個模塊與顯影劑ID 託尼和模塊ID AttributesDemo,然後我需要創建XCartDirectory /類/ X-Lite /模塊/託尼/ AttributesDemo /型號/ 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者中的所有屬性。

相關問題