Ich habe Produkt im Frontend hinzugefügt.
Ich erhalte die folgende Fehlermeldung.
SQLSTATE [23000]: Verletzung der Integritätsbedingung: 1452 Untergeordnete Zeile kann nicht hinzugefügt oder aktualisiert werden: Eine Fremdschlüsseleinschränkung schlägt fehl (
magento
.catalog_product_entity
, CONSTRAINTFK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID
FOREIGN KEY (attribute_set_id
) REFERENCESeav_attribute_set
(attribute_set_id
) ON DE)
public function saveVirtualNewProduct($wholedata)
{
$cats=array();
foreach($wholedata['category'] as $keycat){
array_push($cats,$keycat);
}
if($wholedata['status']==1 && isset($wholedata['wstoreids']) ){
$status=1;
$stores=$wholedata['wstoreids'];
}
else{
$status=Mage::getStoreConfig('marketplace/marketplace_options/product_approval')? 2:1;
$stores=Mage::app()->getStore()->getStoreId();
}
$magentoProductModel = Mage::getModel('catalog/product');
$magentoProductModel->setData($wholedata);
$saved=$magentoProductModel->save();
$lastInserId = $saved->getId();
/* Update Special from-to Date */
if($wholedata['special_from_date'] && $wholedata['special_to_date'])
{
//Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product')->load($lastInserId);
$product->setSpecialFromDate($wholedata['special_from_date']);
$product->setSpecialFromDateIsFormated(true);
$product->setSpecialToDate($wholedata['special_to_date']);
$product->setSpecialToDateIsFormated(true);
$product->save();
}
/* Update Special from-to Date */
$magentoProductModel = Mage::getModel('catalog/product')->load($saved->getId());
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
if($wholedata['special_price']){
$special_price = $wholedata['special_price']/$rates[$currentCurrencyCode];
$magentoProductModel->setSpecialPrice($special_price);
}
$price = $wholedata['price']/$rates[$currentCurrencyCode];
$magentoProductModel->setPrice($price);
$magentoProductModel->setStoresIds(array($stores));
$storeId = Mage::app()->getStore()->getId();
$magentoProductModel->setWebsiteIds(array(Mage::getModel('core/store')->load( $storeId )->getWebsiteId()));
$magentoProductModel->setCategoryIds($cats);
$magentoProductModel->setStatus($status);
$saved=$magentoProductModel->save();
$lastId = $saved->getId();
$this->_saveStock($lastId,$wholedata['stock'],$wholedata['is_in_stock']);
$wholedata['id'] = $lastId;
$collection1=Mage::getModel('marketplace/product');
$collection1->setmageproductid($lastId);
$collection1->setuserid($wholedata['userid']);
$collection1->setstatus($status);
$collection1->save();
if($wholedata['type_id']=='virtual'){
if((isset($_FILES) && count($_FILES) > 0) && !isset($wholedata['csv'])){
if (!is_dir(Mage::getBaseDir().'/media/marketplace/')){
mkdir(Mage::getBaseDir().'/media/marketplace/', 0755);
}
if (!is_dir(Mage::getBaseDir().'/media/marketplace/'.$lastId)){
mkdir(Mage::getBaseDir().'/media/marketplace/'.$lastId, 0755);
}
foreach($_FILES as $image){
$imagesdir = Mage::getBaseDir().'/media/marketplace/'.$lastId.'/';
$filename = $image['name'];
move_uploaded_file($image['tmp_name'],$imagesdir.$filename);
}
$this->_addImages($lastId,$wholedata['defaultimage']);
}
}
return $lastId;
}
Bitte hilft mir jemand
Vielen Dank.
$magentoProductModel
zu Beginn der Funktion initialisierten Modell aktualisieren und speichern . Dies reduziert den Overhead.