2016-08-04 93 views
1

我有一個受保護的數組。將一個項目添加到數組IF條件語句

class Tric_FullCircle_Model_Product_Adapter extends OnePica_FullCircle_Model_Product_Adapter 
{ 
    /** 
    * Global company number 
    */ 
    protected $_globalCompanyNumber = null; 

    /** 
    * Tax Classes 
    */ 
    protected $_taxClasses = null; 

    /** 
    * Attributes to update 
    * 
    * @var array 
    */  


protected $_attributesToUpdate = array( 
    'name', 
    'description', 
    'price', 
    'tax_class_id', 
    'weight', 
    'country_of_manufacture', 
    'specifications', 
    'tric_cn', 
    'tric_style', 
    'tric_color', 
    'tric_div', 
    'tric_div_desc', 
    ); 

我想,如果一個特定的默認存儲其中1

我一直在我的保護變量數組拋出語法錯誤匹配添加「special_price」。我是否使用array_diff?或只是追加像這樣$arr[] = 'special_price';

我想是這樣的

if (Mage::app()->getStore()->getStoreId() !== Mage::app()->getWebsites()[1]->getDefaultStore()->getStoreId()) { 
      $arr[] = 'special_price'; 

    } 

if (Mage::app()->getStore()->getStoreId() === Mage::app()->getWebsites()[1]->getDefaultStore()->getStoreId()) { 
      $_attributesToUpdate = array_diff(fieldNames, array('special_price')); 

任何幫助,將不勝感激。謝謝。

+0

顯示你正在做什麼引發錯誤。 – Rasclatt

+0

使用var_export並更新您的答案,以便我們可以幫助您 –

+1

在同一個類中,您應該沒有問題,您只需執行'$ this - > _ attributesToUpdate [] ='special_price';' – Rasclatt

回答

1

訪問受保護陣列$this->

變化

arr[] = 'special_price'; 

$this->arr[] = 'special_price'; 

OR

更改

_attributesToUpdate = array_diff(fieldNames, array('special_price')); 

$this->_attributesToUpdate = array_diff(fieldNames, array('special_price')); 
+0

......我知道我的兩個IF語句可能會工作......我只是不知道如何將它插入到數組中......這是否更有意義? – thismethod

+0

我已經更新了我的回答@thismethod –

+0

我應該只能在我的{}中正確使用答案的底線? – thismethod