2

すべての製品に新しい属性のシリアル番号を作成しました。注文が完了したときにその値を設定する方法がわかりません。どこを変更すればよいかはわかっていますが、機能がありません。これがコードです。新しい属性のコードは「serial_number」です。

if($status == 'complete'){

    foreach ($this->getAllItems() as $item) {
      // Here I want to update the value, I am sure something like the following will work.         
      $this->setAttribute($item, 'serial_number', '123');

}
}

また、管理者での設定はどうあるべきですか。注文のステータスが完了に変更されたときに値を変更しています。

4

3 に答える 3

5

別の方法は次のとおりです: (色 = 属性名、赤 = 属性値_id)

すでに $product が利用可能であると仮定して始めましょう。

$attr = $product->getResource()->getAttribute('color');
if ($attr->usesSource()) {
$avid = $attr->getSource()->getOptionId('red');
$product->setData('color', $avid);
$product->save();
}
于 2013-05-31T11:09:03.893 に答える
1

属性を設定しているようですが、アイテムをデータベースにsave()するコードはどこにありますか

if($status == 'complete'){   
    foreach ($this->getAllItems() as $item) {
         $item->setSerialNumber('123');
         $item->save()   
     }
}
于 2013-02-01T13:54:21.920 に答える
-2

次のコードを使用してこれを行うことができます -

if($status == 'complete'){

    foreach ($this->getAllItems() as $item) {

         $item->setSerialNumber('123');

     }
}

これで問題が解決することを願っています。

于 2013-02-01T12:19:29.963 に答える