¿Cómo puedo crear una regla de ventas que se aplica una reducción adicional en los precios especiales?

magento.stackexchange https://magento.stackexchange.com/questions/4735

  •  16-10-2019
  •  | 
  •  

Pregunta

Nuestro catálogo ampliamente precios usos 'precio especial' en todas partes. Tenemos que poner en una venta con 'mayor reducción' del 15% con esto como una regla de precios de catálogo.

Si el producto era £ 10 y £ marcado hasta 5 por 'precio especial', entonces nos gustaría mostrar un 15% de descuento y ver £ 4,25 (en lugar de £ 5 o £ 8.50).

Como una solución que puedo conseguir los precios dentro y fuera de Excel, sin embargo, esta 'reducción adicional' es una característica de la tienda y al por menor en general. Por lo tanto, ¿cómo lo hago? Utilizando una regla de la compra no es lo que se necesita aquí, sé que podría aplicar una reducción adicional de esa manera, pero necesito el precio que se pagó en realidad en la parte delantera.

¿Fue útil?

Solución

Debe reescribir la clase /app/code/core/Mage/CatalogRule/Model/Resource/Rule.php. No es función de datos _getRuleProductsStmt precio vuelve producto con consulta SQL. He añadido algunos cambios:

    $specialAttr  = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'special_price');
    $specialTable = $priceAttr->getBackend()->getTable();
    $specialId    = $specialAttr->getId();
    $specialCondition = '%1$s.entity_id=rp.product_id AND (%1$s.attribute_id=' . $specialId. ') and %1$s.store_id=%2$s';
    //some code here

    $select->joinLeft(
        array('psp_default'=> $specialTable),
        sprintf($specialCondition, 'psp_default', Mage_Core_Model_App::ADMIN_STORE_ID),
        array('default_price'=> 'least(ifnull(psp_default.`value`,pp_default.`value`),pp_default.`value`)')
    );

Vea cuerpo del método completo con mis cambios:

protected function _getRuleProductsStmt($fromDate, $toDate, $productId = null, $websiteId = null)
{
    $read = $this->_getReadAdapter();
    /**
     * Sort order is important
     * It used for check stop price rule condition.
     * website_id   customer_group_id   product_id  sort_order
     *  1           1                   1           0
     *  1           1                   1           1
     *  1           1                   1           2
     * if row with sort order 1 will have stop flag we should exclude
     * all next rows for same product id from price calculation
     */
    $select = $read->select()
        ->from(array('rp' => $this->getTable('catalogrule/rule_product')))
        ->where($read->quoteInto('rp.from_time = 0 or rp.from_time <= ?', $toDate)
        . ' OR ' . $read->quoteInto('rp.to_time = 0 or rp.to_time >= ?', $fromDate))
        ->order(array('rp.website_id', 'rp.customer_group_id', 'rp.product_id', 'rp.sort_order', 'rp.rule_id'));

    if (!is_null($productId)) {
        $select->where('rp.product_id=?', $productId);
    }

    /**
     * Join default price and websites prices to result
     */
    $priceAttr    = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'price');
    $priceTable   = $priceAttr->getBackend()->getTable();
    $attributeId  = $priceAttr->getId();
    $specialAttr  = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'special_price');
    $specialTable = $priceAttr->getBackend()->getTable();
    $specialId    = $specialAttr->getId();

    $joinCondition  = '%1$s.entity_id=rp.product_id AND (%1$s.attribute_id=' . $attributeId
        . ') and %1$s.store_id=%2$s';
    $specialCondition = '%1$s.entity_id=rp.product_id AND (%1$s.attribute_id=' . $specialId
        . ') and %1$s.store_id=%2$s';

    $select->join(
        array('pp_default'=> $priceTable),
        sprintf($joinCondition, 'pp_default', Mage_Core_Model_App::ADMIN_STORE_ID),
        array()
    );
    $select->joinLeft(
        array('psp_default'=> $specialTable),
        sprintf($specialCondition, 'psp_default', Mage_Core_Model_App::ADMIN_STORE_ID),
        array('default_price'=> 'least(ifnull(psp_default.`value`,pp_default.`value`),pp_default.`value`)')
    );

    if ($websiteId !== null) {
        $website      = Mage::app()->getWebsite($websiteId);
        $defaultGroup = $website->getDefaultGroup();
        if ($defaultGroup instanceof Mage_Core_Model_Store_Group) {
            $storeId = $defaultGroup->getDefaultStoreId();
        } else {
            $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
        }

        $select->joinInner(
            array('product_website' => $this->getTable('catalog/product_website')),
            'product_website.product_id=rp.product_id ' .
                'AND rp.website_id=product_website.website_id ' .
                'AND product_website.website_id=' . $websiteId,
            array()
        );

        $tableAlias = 'pp' . $websiteId;
        $fieldAlias = 'website_' . $websiteId . '_price';
        $select->joinLeft(
            array($tableAlias=> $priceTable),
            sprintf($joinCondition, $tableAlias, $storeId),
            array($fieldAlias=> $tableAlias . '.value')
        );
    } else {
        foreach (Mage::app()->getWebsites() as $website) {
            $websiteId    = $website->getId();
            $defaultGroup = $website->getDefaultGroup();
            if ($defaultGroup instanceof Mage_Core_Model_Store_Group) {
                $storeId = $defaultGroup->getDefaultStoreId();
            } else {
                $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
            }

            $tableAlias = 'pp' . $websiteId;
            $fieldAlias = 'website_' . $websiteId . '_price';
            $select->joinLeft(
                array($tableAlias => $priceTable),
                sprintf($joinCondition, $tableAlias, $storeId),
                array($fieldAlias => $tableAlias . '.value')
            );
        }
    }
    return $read->query($select);
} 
Versión

Mi Magento es 1.7.0.2, que no probé resultado profundamente, pero esto cambia dame resultado correcto.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top