2
스크립트를 통해 Magento 특성 옵션을 만들고 있지만 새 ID를 가져 와서 동일한 스크립트에서 바로 사용할 수 있어야합니다.프로그래밍 방식으로 특성 옵션을 추가하는 것은 즉시 사용할 수 없습니다.
현재 ID를 가져 오지 않았습니다. 스크립트를 죽이고 다시 시작하면 생성 된 옵션이 선택되어 ID가 반환되지만 동일한 스크립트의 일부는 아닙니다. (필요한 Mage::app()
등이 포함), 옵션을 생성, 당신은 마 젠토 백엔드에서 볼 수
$attr = Mage::getModel('catalog/product')->getResource()->getAttribute($key);
if ($attr->usesSource()) {
$vattr_id = $attr->getSource()->getOptionId($value);
}else{
echo "No Source";
$vattr_id = false;
}
if($vattr_id){
return $vattr_id;
}else{
$attr_model = Mage::getModel('catalog/resource_eav_attribute');
$attr = $attr_model->loadByCode('catalog_product', $key);
$attr_id = $attr->getAttributeId();
$option['attribute_id'] = $attr_id;
$option['value'][$value][0] = $value;
$option['value'][$value][1] = $value;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($option);
$attr = Mage::getModel('catalog/product')->getResource()->getAttribute($key);
if ($attr->usesSource()) {
$vattr_id = $attr->getSource()->getOptionId($value);
echo "AttrID: $vattr_id";
}
}
이 실행하지만, $vattr_id
는 NULL
입니다 : 여기
Magento가 모델을 캐싱하는 방법과 관련이 있습니다 만,이 부분을 지우려면 어디를 봐야 할 지 모르겠습니다.
나는이 답변에 투표하는 사람을 찾고 있습니다. – Butterfly