Search code examples
magentomagento-1.4

Update all Tier prices for a product


Without directly querying the Magento database. How can i remove all the tier prices for a certain product based on quantity and customer group?

Then add new tier prices for this product.

Example:
Remove all tier prices for a product with the SKU: FD001
where the customer group id is: 4

PHP 5.3 Magento 1.4.2


Solution

  • I ended up solving this by using direct database queries.

    As always I'm looking for a better answer.

    My Hacky solution:

    $product = Mage::getModel('catalog/product')->load(9999);
    $dbc = Mage::getSingleton('core/resource')->getConnection('core_write');
    $dbc->query('DELETE FROM `catalog_product_entity_tier_price` WHERE `entity_id` = ' . intval($product->getId()) . ' AND `customer_group_id` IN(3,4,6,7) AND qty = 1');
    $dbc->query(
        'INSERT INTO `catalog_product_entity_tier_price` (`entity_id`,`all_groups`,`customer_group_id`,`qty`,`value`,`website_id`)
        VALUES ('. intval($product->getId()) . ',0,' . intval($id) . ',1,' . floatval($price) . ',0)'
        );