1
votes

I've programmaticaly allowed the customer to edit the price of a product.

the problem is when i add product with 20$ and adding again the same product with 30$ in the shopping cart page it displays the product -| qty=2 -| total price=60$

so this is not logic the total price must be 50$ and it should not set qty to 2

i know the problem is in the SKU is there a solution for this i don't wanna modify the SKU?

for more details this is my previous question

3

3 Answers

2
votes

So this is doable, but unfortunately there is no way to do it without a pretty significant rewrite. I'm assuming that you have some way to identify the different between the two quote items besides price. If that's the case:

sales/quote_item: representProduct()

the rewrite configuration in your module:

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <sales>
                <rewrite>
                    <!--Your full class name should be specified-->
                    <quote_item>Namespace_Module_Model_Sales_Quote_Item</quote_item>
                </rewrite>
            </sales>
        </models>
    </global>
</config>

the original function: public function representProduct($product) { $itemProduct = $this->getProduct(); if (!$product || $itemProduct->getId() != $product->getId()) { return false; }

    /**
     * Check maybe product is planned to be a child of some quote item - in this case we limit search
     * only within same parent item
     */
    $stickWithinParent = $product->getStickWithinParent();
    if ($stickWithinParent) {
        if ($this->getParentItem() !== $stickWithinParent) {
            return false;
        }
    }

    // Check options
    $itemOptions = $this->getOptionsByCode();
    $productOptions = $product->getCustomOptions();

    if (!$this->compareOptions($itemOptions, $productOptions)) {
        return false;
    }
    if (!$this->compareOptions($productOptions, $itemOptions)) {
        return false;
    }
    return true;
}

our function:

public function representProduct($product) {
    $parentResult = parent::representProduct($product);

    //if parent result is already false, we already have a different product, exit.
    if ($parentResult === false) {
        return $parentResult;
    }

    $itemProduct = $this->getProduct();

    /*
     * do our check for 'same product' here.
     * Returns true if attribute is the same thus it is hte same product
     */
    if ($product->getSomeAttribute() == $itemProduct->getSomeAttribute()) {
        return true; //same product
    } else {
        return false; //different product
    }
}

If this function returns true, the products will be combined in the cart as the same item and thus you'll just increase your qty by the new qty amount.

If this function returns false, the products will look different and will appear as different items in the cart.

0
votes

Add Same product with different "SKU" and u can give different price for those products.

0
votes

this is the class :

<?php
class WebDirect_CustomPrice_Model_Sales_Quote_Item extends Mage_Sales_Model_Quote_Item
{
    public function representProduct($product) {
        $parentResult = parent::representProduct($product);

        //if parent result is already false, we already have a different product, exit.
        if ($parentResult === false) {
            return $parentResult;
        }

        $itemProduct = $this->getProduct();

        /*
         * do our check for 'same product' here.
        * Returns true if attribute is the same thus it is hte same product
        */
        if ($product->getPrice() == $itemProduct->getPrice()) {
            return true; //same product
        } else {
            return false; //different product
        }
    }




}