Frage

Ich möchte die Bilder so einstellen, dass sie den Standardwert für eine Produktliste und für eine Liste der Speicheransicht verwenden. Ich weiß, wie man es für jedes Produkt einzeln macht: setData (Attributename, Falsch), und so kann ich eine Schleife über meine Produktliste machen. Problem: Es ist wirklich zu langsam.

$attrArray=array('thumbnail','small_image','image');
$products = array(170,171,172);
$stores = array(17,18,19);
foreach ($stores as $store_id) {
    foreach ($products as $product_id) {
        foreach ($attrArray as $attr) { 
            $product = Mage::getModel('catalog/product')
            ->load($product_id)->setStoreId($store_id)
            ->setData($attr, false)
            ->save();
        }
    }
}

Ich habe also versuche, Mage :: Getsingleton ('Catalog/product_action')-> updateEttributes ($ products, $ attrArray, $ store_id); Stattdessen soll das Gleiche tun, aber über eine Liste von Produkten. Es tut tatsächlich etwas: Alle meine Bilder sind jetzt auf "NO -Bilder" gesetzt, aber nicht wie erwartet "Standardwert" verwendet.

$attrArray = array('thumbnail'=>false,'small_image'=>false,'image'=>false);
$products = array(170,171,172);
$stores = array(17,18,19);
foreach ($stores as $store_id) {
    Mage::getSingleton('catalog/product_action')
    ->updateAttributes($products, $attrArray, $store_id);
}

Wenn jemand hier eine Idee hat, könnte es mir wirklich helfen, Zeit zu sparen! Vielen Dank.

War es hilfreich?

Lösung

Das Festlegen eines Attributwerts auf "Verwenden von Standardwerten" bedeutet im Grunde, dass Sie die Zeile in der Datenbank für dieses Attribut für das spezifische Produkt für eine Store -ID löschen müssen.
Hier ist eine einfache Lösung, die das tut. Es erfordert die direkte Änderung der Datenbank und einige Leute werden sagen, dass dies ein großes "Nein-Nein" ist, aber sie funktioniert.

$attrArray=array('thumbnail','small_image','image');
$products = array(170,171,172);
$stores = array(17,18,19);
$productsAsString = implode(',', $products);
$storesAsString = implode(',', $stores);
//get access to the resource
$resource = Mage::getSingleton('core/resource');
//get access to the db write connection
$connection = $resource->getConnection('core_write');
//model for retrieving attributes
$eavConfig = Mage::getModel('eav/config');
$tables = array();
//get the association between attribute ids and the tables where their values are stored
//group them by table name so you will run a single query for each table
foreach ($attrArray as $attributeCode){
    $attribute = $eavConfig->getAttribute('catalog_product', $attributeCode);
    if ($attribute){
        $tableName = $resource->getTableName('catalog/product') . '_' . $attribute->getBackendType();
        $tables[$tableName][] = $attribute->getId();
    }
}
//for each table delete the attribute values in the specified store for the specified products
foreach ($tables as $tableName => $attributeIds){
    $attributeIdsAsString = implode(',', $attributeIds);
    $q = "DELETE FROM {$tableName}
                WHERE
                    attribute_id IN ({$attributeIdsAsString}) AND
                    entity_id IN ({$productsAsString}) AND
                    store_id IN ({$storesAsString})";
    $connection->query($q);
}

Das sollte es sein. Aber für den Fall, dass ich zu übersehen bin und dies nicht funktioniert, sichern Sie Ihre Datenbank zuerst.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top