How To Get Current Product ID in Model












1















Im trying to retrieve the Current Product ID inside the Tax-model-Calculation.php (code in -> https://github.com/adam-paterson/magento-ce-1.9.0.1/blob/master/app/code/core/Mage/Tax/Model/Calculation.php )



public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$taxRate = $taxRate / 100;
if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}
if ($round) {
return $this->round($amount);
}
return $amount;
}


I tried the following code:



public function calcTaxAmount($price, $taxRate, $priceIncludeTax=false, $round=true)
{
$taxRate = $taxRate/100;
$product = Mage::registry('current_product')->getId();
var_dump($product);


but the following information is displayed in frontpage when I debug using var_dump($product):




Fatal error: Uncaught Error: Call to a member function getId() on null




Additionally I tried $product = $this->getProduct()->getId();



with same result.










share|improve this question


















  • 1





    are you use tax cal model on product list page or product view page ?

    – Abdul
    Mar 14 '16 at 6:46











  • hi @Abdul , calctaxamount is used in home, productlist, view and cart. thats the reason why I want to use current_product id inside the model.

    – s_h
    Mar 14 '16 at 8:07






  • 1





    If your need current product id in calcTaxAmount function then need to add one more argument in above function. If your wand then i will explain in details

    – Abdul
    Mar 14 '16 at 10:06













  • hi @Abdul , yes please. Would be great!, thanks.

    – s_h
    Mar 14 '16 at 16:41






  • 1





    check ans and let me know if any queries :)

    – Abdul
    Mar 15 '16 at 6:51
















1















Im trying to retrieve the Current Product ID inside the Tax-model-Calculation.php (code in -> https://github.com/adam-paterson/magento-ce-1.9.0.1/blob/master/app/code/core/Mage/Tax/Model/Calculation.php )



public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$taxRate = $taxRate / 100;
if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}
if ($round) {
return $this->round($amount);
}
return $amount;
}


I tried the following code:



public function calcTaxAmount($price, $taxRate, $priceIncludeTax=false, $round=true)
{
$taxRate = $taxRate/100;
$product = Mage::registry('current_product')->getId();
var_dump($product);


but the following information is displayed in frontpage when I debug using var_dump($product):




Fatal error: Uncaught Error: Call to a member function getId() on null




Additionally I tried $product = $this->getProduct()->getId();



with same result.










share|improve this question


















  • 1





    are you use tax cal model on product list page or product view page ?

    – Abdul
    Mar 14 '16 at 6:46











  • hi @Abdul , calctaxamount is used in home, productlist, view and cart. thats the reason why I want to use current_product id inside the model.

    – s_h
    Mar 14 '16 at 8:07






  • 1





    If your need current product id in calcTaxAmount function then need to add one more argument in above function. If your wand then i will explain in details

    – Abdul
    Mar 14 '16 at 10:06













  • hi @Abdul , yes please. Would be great!, thanks.

    – s_h
    Mar 14 '16 at 16:41






  • 1





    check ans and let me know if any queries :)

    – Abdul
    Mar 15 '16 at 6:51














1












1








1


0






Im trying to retrieve the Current Product ID inside the Tax-model-Calculation.php (code in -> https://github.com/adam-paterson/magento-ce-1.9.0.1/blob/master/app/code/core/Mage/Tax/Model/Calculation.php )



public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$taxRate = $taxRate / 100;
if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}
if ($round) {
return $this->round($amount);
}
return $amount;
}


I tried the following code:



public function calcTaxAmount($price, $taxRate, $priceIncludeTax=false, $round=true)
{
$taxRate = $taxRate/100;
$product = Mage::registry('current_product')->getId();
var_dump($product);


but the following information is displayed in frontpage when I debug using var_dump($product):




Fatal error: Uncaught Error: Call to a member function getId() on null




Additionally I tried $product = $this->getProduct()->getId();



with same result.










share|improve this question














Im trying to retrieve the Current Product ID inside the Tax-model-Calculation.php (code in -> https://github.com/adam-paterson/magento-ce-1.9.0.1/blob/master/app/code/core/Mage/Tax/Model/Calculation.php )



public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$taxRate = $taxRate / 100;
if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}
if ($round) {
return $this->round($amount);
}
return $amount;
}


I tried the following code:



public function calcTaxAmount($price, $taxRate, $priceIncludeTax=false, $round=true)
{
$taxRate = $taxRate/100;
$product = Mage::registry('current_product')->getId();
var_dump($product);


but the following information is displayed in frontpage when I debug using var_dump($product):




Fatal error: Uncaught Error: Call to a member function getId() on null




Additionally I tried $product = $this->getProduct()->getId();



with same result.







magento-1.9 catalog model tax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 14 '16 at 2:44









s_hs_h

67931433




67931433








  • 1





    are you use tax cal model on product list page or product view page ?

    – Abdul
    Mar 14 '16 at 6:46











  • hi @Abdul , calctaxamount is used in home, productlist, view and cart. thats the reason why I want to use current_product id inside the model.

    – s_h
    Mar 14 '16 at 8:07






  • 1





    If your need current product id in calcTaxAmount function then need to add one more argument in above function. If your wand then i will explain in details

    – Abdul
    Mar 14 '16 at 10:06













  • hi @Abdul , yes please. Would be great!, thanks.

    – s_h
    Mar 14 '16 at 16:41






  • 1





    check ans and let me know if any queries :)

    – Abdul
    Mar 15 '16 at 6:51














  • 1





    are you use tax cal model on product list page or product view page ?

    – Abdul
    Mar 14 '16 at 6:46











  • hi @Abdul , calctaxamount is used in home, productlist, view and cart. thats the reason why I want to use current_product id inside the model.

    – s_h
    Mar 14 '16 at 8:07






  • 1





    If your need current product id in calcTaxAmount function then need to add one more argument in above function. If your wand then i will explain in details

    – Abdul
    Mar 14 '16 at 10:06













  • hi @Abdul , yes please. Would be great!, thanks.

    – s_h
    Mar 14 '16 at 16:41






  • 1





    check ans and let me know if any queries :)

    – Abdul
    Mar 15 '16 at 6:51








1




1





are you use tax cal model on product list page or product view page ?

– Abdul
Mar 14 '16 at 6:46





are you use tax cal model on product list page or product view page ?

– Abdul
Mar 14 '16 at 6:46













hi @Abdul , calctaxamount is used in home, productlist, view and cart. thats the reason why I want to use current_product id inside the model.

– s_h
Mar 14 '16 at 8:07





hi @Abdul , calctaxamount is used in home, productlist, view and cart. thats the reason why I want to use current_product id inside the model.

– s_h
Mar 14 '16 at 8:07




1




1





If your need current product id in calcTaxAmount function then need to add one more argument in above function. If your wand then i will explain in details

– Abdul
Mar 14 '16 at 10:06







If your need current product id in calcTaxAmount function then need to add one more argument in above function. If your wand then i will explain in details

– Abdul
Mar 14 '16 at 10:06















hi @Abdul , yes please. Would be great!, thanks.

– s_h
Mar 14 '16 at 16:41





hi @Abdul , yes please. Would be great!, thanks.

– s_h
Mar 14 '16 at 16:41




1




1





check ans and let me know if any queries :)

– Abdul
Mar 15 '16 at 6:51





check ans and let me know if any queries :)

– Abdul
Mar 15 '16 at 6:51










4 Answers
4






active

oldest

votes


















2





+100









Follow bellow steps:



Step : 1 First copy core file from app/code/core/Mage/Tax/Helper/Data.php to local app/code/local/Mage/Tax/Helper/Data.php or override helper data



After replace bellow functions



public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null,
$ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
{
if (!$price) {
return $price;
}
$store = $this->_app->getStore($store);
if (!$this->needPriceConversion($store)) {
return $store->roundPrice($price);
}
if (is_null($priceIncludesTax)) {
$priceIncludesTax = $this->priceIncludesTax($store);
}

$percent = $product->getTaxPercent();
$includingPercent = null;

$taxClassId = $product->getTaxClassId();
if (is_null($percent)) {
if ($taxClassId) {
$request = Mage::getSingleton('tax/calculation')
->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
$percent = Mage::getSingleton('tax/calculation')
->getRate($request->setProductClassId($taxClassId));
}
}
if ($taxClassId && $priceIncludesTax) {
if ($this->isCrossBorderTradeEnabled($store)) {
$includingPercent = $percent;
} else {
$request = Mage::getSingleton('tax/calculation')->getRateOriginRequest($store);
$includingPercent = Mage::getSingleton('tax/calculation')
->getRate($request->setProductClassId($taxClassId));
}
}

if ($percent === false || is_null($percent)) {
if ($priceIncludesTax && !$includingPercent) {
return $price;
}
}

$product->setTaxPercent($percent);
if ($product->getAppliedRates() == null) {
$request = Mage::getSingleton('tax/calculation')
->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
$request->setProductClassId($taxClassId);
$appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($request);
$product->setAppliedRates($appliedRates);
}

if (!is_null($includingTax)) {
if ($priceIncludesTax) {
if ($includingTax) {
/**
* Recalculate price include tax in case of different rates. Otherwise price remains the same.
*/
if ($includingPercent != $percent) {
// determine the customer's price that includes tax
$price = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
}
} else {
$price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
}
} else {
if ($includingTax) {
$appliedRates = $product->getAppliedRates();
if (count($appliedRates) > 1) {
$price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
} else {
$price = $this->_calculatePrice($price, $percent, true, false, $product);
}
}
}
} else {
if ($priceIncludesTax) {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
if ($includingPercent != $percent) {
// determine the customer's price that includes tax
$taxablePrice = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
// determine the customer's tax amount,
// round tax unless $roundPrice is set explicitly to false
$tax = $this->getCalculator()->calcTaxAmount($taxablePrice, $percent, true, $roundPrice, $product);
// determine the customer's price without taxes
$price = $taxablePrice - $tax;
} else {
//round tax first unless $roundPrice is set to false explicitly
$price = $this->_calculatePrice($price, $includingPercent, false, $roundPrice, $product);
}
break;

case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
$price = $this->_calculatePrice($price, $percent, true, false, $product);
break;
}
} else {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$appliedRates = $product->getAppliedRates();
if (count($appliedRates) > 1) {
$price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
} else {
$price = $this->_calculatePrice($price, $percent, true, false, product);
}
break;

case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
break;
}
}
}
if ($roundPrice) {
return $store->roundPrice($price);
} else {
return $price;
}
}


''



protected function _calculatePriceInclTax($storePriceInclTax, $storePercent, $customerPercent, $store, $product=false)
{
$priceExclTax = $this->_calculatePrice($storePriceInclTax, $storePercent, false, false);
$customerTax = $this->getCalculator()->calcTaxAmount($priceExclTax, $customerPercent, false, false, $product);
$customerPriceInclTax = $store->roundPrice($priceExclTax + $customerTax);
return $customerPriceInclTax;
}


''



protected function _calculatePrice($price, $percent, $type, $roundTaxFirst = false, $product = false)
{
$calculator = $this->getCalculator();
if ($type) {
$taxAmount = $calculator->calcTaxAmount($price, $percent, false, $roundTaxFirst, $product);
return $price + $taxAmount;
} else {
$taxAmount = $calculator->calcTaxAmount($price, $percent, true, $roundTaxFirst, $product);
return $price - $taxAmount;
}
}


Step : 2 After copy core file from app/code/core/Mage/Tax/Model/Calculation.php to local app/code/local/Mage/Tax/Model/Calculation.php or override model file Calculation.php



and replace code from :



public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$taxRate = $taxRate / 100;

if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}

if ($round) {
return $this->round($amount);
}

return $amount;
}


to



public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true, $product = false)
{
if($product) {
echo $product->getId();
}

$taxRate = $taxRate / 100;

if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}

if ($round) {
return $this->round($amount);
}

return $amount;
}





share|improve this answer


























  • what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

    – s_h
    Mar 15 '16 at 7:48





















0














Try to get it using Request object:




$productId = Mage::app()->getRequest()->getParam('product')




Which gives you requested product id inside calcTaxAmount method.



Hope this will work for you.






share|improve this answer
























  • hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

    – s_h
    Mar 14 '16 at 7:58



















0














You can use below method to get current register product id.





  1. Just create a session to set the product id.You need to put below mentioned code in you header.phtml file.




    $productId = Mage::registry('current_product')->getId();
    Mage::getSingleton('core/session')->setCurrentProductId($productId);




  2. Now you can get recently created session any where in Magento by using below code.




Mage::getSingleton('core/session')->getCurrentProductId()




Hope it will help you. For more see Alan's answer here.






share|improve this answer


























  • thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

    – s_h
    Mar 14 '16 at 8:08



















0














Get a current product id in magento 1 by using below lines.



$product = Mage::registry('current_product');
$id = $product->getId();





share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f106033%2fhow-to-get-current-product-id-in-model%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2





    +100









    Follow bellow steps:



    Step : 1 First copy core file from app/code/core/Mage/Tax/Helper/Data.php to local app/code/local/Mage/Tax/Helper/Data.php or override helper data



    After replace bellow functions



    public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null,
    $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
    {
    if (!$price) {
    return $price;
    }
    $store = $this->_app->getStore($store);
    if (!$this->needPriceConversion($store)) {
    return $store->roundPrice($price);
    }
    if (is_null($priceIncludesTax)) {
    $priceIncludesTax = $this->priceIncludesTax($store);
    }

    $percent = $product->getTaxPercent();
    $includingPercent = null;

    $taxClassId = $product->getTaxClassId();
    if (is_null($percent)) {
    if ($taxClassId) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $percent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }
    if ($taxClassId && $priceIncludesTax) {
    if ($this->isCrossBorderTradeEnabled($store)) {
    $includingPercent = $percent;
    } else {
    $request = Mage::getSingleton('tax/calculation')->getRateOriginRequest($store);
    $includingPercent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }

    if ($percent === false || is_null($percent)) {
    if ($priceIncludesTax && !$includingPercent) {
    return $price;
    }
    }

    $product->setTaxPercent($percent);
    if ($product->getAppliedRates() == null) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $request->setProductClassId($taxClassId);
    $appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($request);
    $product->setAppliedRates($appliedRates);
    }

    if (!is_null($includingTax)) {
    if ($priceIncludesTax) {
    if ($includingTax) {
    /**
    * Recalculate price include tax in case of different rates. Otherwise price remains the same.
    */
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $price = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    }
    } else {
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    }
    } else {
    if ($includingTax) {
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    }
    }
    }
    } else {
    if ($priceIncludesTax) {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $taxablePrice = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    // determine the customer's tax amount,
    // round tax unless $roundPrice is set explicitly to false
    $tax = $this->getCalculator()->calcTaxAmount($taxablePrice, $percent, true, $roundPrice, $product);
    // determine the customer's price without taxes
    $price = $taxablePrice - $tax;
    } else {
    //round tax first unless $roundPrice is set to false explicitly
    $price = $this->_calculatePrice($price, $includingPercent, false, $roundPrice, $product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    break;
    }
    } else {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    break;
    }
    }
    }
    if ($roundPrice) {
    return $store->roundPrice($price);
    } else {
    return $price;
    }
    }


    ''



    protected function _calculatePriceInclTax($storePriceInclTax, $storePercent, $customerPercent, $store, $product=false)
    {
    $priceExclTax = $this->_calculatePrice($storePriceInclTax, $storePercent, false, false);
    $customerTax = $this->getCalculator()->calcTaxAmount($priceExclTax, $customerPercent, false, false, $product);
    $customerPriceInclTax = $store->roundPrice($priceExclTax + $customerTax);
    return $customerPriceInclTax;
    }


    ''



    protected function _calculatePrice($price, $percent, $type, $roundTaxFirst = false, $product = false)
    {
    $calculator = $this->getCalculator();
    if ($type) {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, false, $roundTaxFirst, $product);
    return $price + $taxAmount;
    } else {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, true, $roundTaxFirst, $product);
    return $price - $taxAmount;
    }
    }


    Step : 2 After copy core file from app/code/core/Mage/Tax/Model/Calculation.php to local app/code/local/Mage/Tax/Model/Calculation.php or override model file Calculation.php



    and replace code from :



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
    {
    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }


    to



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true, $product = false)
    {
    if($product) {
    echo $product->getId();
    }

    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }





    share|improve this answer


























    • what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

      – s_h
      Mar 15 '16 at 7:48


















    2





    +100









    Follow bellow steps:



    Step : 1 First copy core file from app/code/core/Mage/Tax/Helper/Data.php to local app/code/local/Mage/Tax/Helper/Data.php or override helper data



    After replace bellow functions



    public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null,
    $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
    {
    if (!$price) {
    return $price;
    }
    $store = $this->_app->getStore($store);
    if (!$this->needPriceConversion($store)) {
    return $store->roundPrice($price);
    }
    if (is_null($priceIncludesTax)) {
    $priceIncludesTax = $this->priceIncludesTax($store);
    }

    $percent = $product->getTaxPercent();
    $includingPercent = null;

    $taxClassId = $product->getTaxClassId();
    if (is_null($percent)) {
    if ($taxClassId) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $percent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }
    if ($taxClassId && $priceIncludesTax) {
    if ($this->isCrossBorderTradeEnabled($store)) {
    $includingPercent = $percent;
    } else {
    $request = Mage::getSingleton('tax/calculation')->getRateOriginRequest($store);
    $includingPercent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }

    if ($percent === false || is_null($percent)) {
    if ($priceIncludesTax && !$includingPercent) {
    return $price;
    }
    }

    $product->setTaxPercent($percent);
    if ($product->getAppliedRates() == null) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $request->setProductClassId($taxClassId);
    $appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($request);
    $product->setAppliedRates($appliedRates);
    }

    if (!is_null($includingTax)) {
    if ($priceIncludesTax) {
    if ($includingTax) {
    /**
    * Recalculate price include tax in case of different rates. Otherwise price remains the same.
    */
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $price = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    }
    } else {
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    }
    } else {
    if ($includingTax) {
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    }
    }
    }
    } else {
    if ($priceIncludesTax) {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $taxablePrice = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    // determine the customer's tax amount,
    // round tax unless $roundPrice is set explicitly to false
    $tax = $this->getCalculator()->calcTaxAmount($taxablePrice, $percent, true, $roundPrice, $product);
    // determine the customer's price without taxes
    $price = $taxablePrice - $tax;
    } else {
    //round tax first unless $roundPrice is set to false explicitly
    $price = $this->_calculatePrice($price, $includingPercent, false, $roundPrice, $product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    break;
    }
    } else {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    break;
    }
    }
    }
    if ($roundPrice) {
    return $store->roundPrice($price);
    } else {
    return $price;
    }
    }


    ''



    protected function _calculatePriceInclTax($storePriceInclTax, $storePercent, $customerPercent, $store, $product=false)
    {
    $priceExclTax = $this->_calculatePrice($storePriceInclTax, $storePercent, false, false);
    $customerTax = $this->getCalculator()->calcTaxAmount($priceExclTax, $customerPercent, false, false, $product);
    $customerPriceInclTax = $store->roundPrice($priceExclTax + $customerTax);
    return $customerPriceInclTax;
    }


    ''



    protected function _calculatePrice($price, $percent, $type, $roundTaxFirst = false, $product = false)
    {
    $calculator = $this->getCalculator();
    if ($type) {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, false, $roundTaxFirst, $product);
    return $price + $taxAmount;
    } else {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, true, $roundTaxFirst, $product);
    return $price - $taxAmount;
    }
    }


    Step : 2 After copy core file from app/code/core/Mage/Tax/Model/Calculation.php to local app/code/local/Mage/Tax/Model/Calculation.php or override model file Calculation.php



    and replace code from :



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
    {
    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }


    to



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true, $product = false)
    {
    if($product) {
    echo $product->getId();
    }

    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }





    share|improve this answer


























    • what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

      – s_h
      Mar 15 '16 at 7:48
















    2





    +100







    2





    +100



    2




    +100





    Follow bellow steps:



    Step : 1 First copy core file from app/code/core/Mage/Tax/Helper/Data.php to local app/code/local/Mage/Tax/Helper/Data.php or override helper data



    After replace bellow functions



    public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null,
    $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
    {
    if (!$price) {
    return $price;
    }
    $store = $this->_app->getStore($store);
    if (!$this->needPriceConversion($store)) {
    return $store->roundPrice($price);
    }
    if (is_null($priceIncludesTax)) {
    $priceIncludesTax = $this->priceIncludesTax($store);
    }

    $percent = $product->getTaxPercent();
    $includingPercent = null;

    $taxClassId = $product->getTaxClassId();
    if (is_null($percent)) {
    if ($taxClassId) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $percent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }
    if ($taxClassId && $priceIncludesTax) {
    if ($this->isCrossBorderTradeEnabled($store)) {
    $includingPercent = $percent;
    } else {
    $request = Mage::getSingleton('tax/calculation')->getRateOriginRequest($store);
    $includingPercent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }

    if ($percent === false || is_null($percent)) {
    if ($priceIncludesTax && !$includingPercent) {
    return $price;
    }
    }

    $product->setTaxPercent($percent);
    if ($product->getAppliedRates() == null) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $request->setProductClassId($taxClassId);
    $appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($request);
    $product->setAppliedRates($appliedRates);
    }

    if (!is_null($includingTax)) {
    if ($priceIncludesTax) {
    if ($includingTax) {
    /**
    * Recalculate price include tax in case of different rates. Otherwise price remains the same.
    */
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $price = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    }
    } else {
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    }
    } else {
    if ($includingTax) {
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    }
    }
    }
    } else {
    if ($priceIncludesTax) {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $taxablePrice = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    // determine the customer's tax amount,
    // round tax unless $roundPrice is set explicitly to false
    $tax = $this->getCalculator()->calcTaxAmount($taxablePrice, $percent, true, $roundPrice, $product);
    // determine the customer's price without taxes
    $price = $taxablePrice - $tax;
    } else {
    //round tax first unless $roundPrice is set to false explicitly
    $price = $this->_calculatePrice($price, $includingPercent, false, $roundPrice, $product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    break;
    }
    } else {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    break;
    }
    }
    }
    if ($roundPrice) {
    return $store->roundPrice($price);
    } else {
    return $price;
    }
    }


    ''



    protected function _calculatePriceInclTax($storePriceInclTax, $storePercent, $customerPercent, $store, $product=false)
    {
    $priceExclTax = $this->_calculatePrice($storePriceInclTax, $storePercent, false, false);
    $customerTax = $this->getCalculator()->calcTaxAmount($priceExclTax, $customerPercent, false, false, $product);
    $customerPriceInclTax = $store->roundPrice($priceExclTax + $customerTax);
    return $customerPriceInclTax;
    }


    ''



    protected function _calculatePrice($price, $percent, $type, $roundTaxFirst = false, $product = false)
    {
    $calculator = $this->getCalculator();
    if ($type) {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, false, $roundTaxFirst, $product);
    return $price + $taxAmount;
    } else {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, true, $roundTaxFirst, $product);
    return $price - $taxAmount;
    }
    }


    Step : 2 After copy core file from app/code/core/Mage/Tax/Model/Calculation.php to local app/code/local/Mage/Tax/Model/Calculation.php or override model file Calculation.php



    and replace code from :



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
    {
    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }


    to



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true, $product = false)
    {
    if($product) {
    echo $product->getId();
    }

    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }





    share|improve this answer















    Follow bellow steps:



    Step : 1 First copy core file from app/code/core/Mage/Tax/Helper/Data.php to local app/code/local/Mage/Tax/Helper/Data.php or override helper data



    After replace bellow functions



    public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null,
    $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
    {
    if (!$price) {
    return $price;
    }
    $store = $this->_app->getStore($store);
    if (!$this->needPriceConversion($store)) {
    return $store->roundPrice($price);
    }
    if (is_null($priceIncludesTax)) {
    $priceIncludesTax = $this->priceIncludesTax($store);
    }

    $percent = $product->getTaxPercent();
    $includingPercent = null;

    $taxClassId = $product->getTaxClassId();
    if (is_null($percent)) {
    if ($taxClassId) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $percent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }
    if ($taxClassId && $priceIncludesTax) {
    if ($this->isCrossBorderTradeEnabled($store)) {
    $includingPercent = $percent;
    } else {
    $request = Mage::getSingleton('tax/calculation')->getRateOriginRequest($store);
    $includingPercent = Mage::getSingleton('tax/calculation')
    ->getRate($request->setProductClassId($taxClassId));
    }
    }

    if ($percent === false || is_null($percent)) {
    if ($priceIncludesTax && !$includingPercent) {
    return $price;
    }
    }

    $product->setTaxPercent($percent);
    if ($product->getAppliedRates() == null) {
    $request = Mage::getSingleton('tax/calculation')
    ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
    $request->setProductClassId($taxClassId);
    $appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($request);
    $product->setAppliedRates($appliedRates);
    }

    if (!is_null($includingTax)) {
    if ($priceIncludesTax) {
    if ($includingTax) {
    /**
    * Recalculate price include tax in case of different rates. Otherwise price remains the same.
    */
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $price = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    }
    } else {
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    }
    } else {
    if ($includingTax) {
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    }
    }
    }
    } else {
    if ($priceIncludesTax) {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    if ($includingPercent != $percent) {
    // determine the customer's price that includes tax
    $taxablePrice = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store, $product);
    // determine the customer's tax amount,
    // round tax unless $roundPrice is set explicitly to false
    $tax = $this->getCalculator()->calcTaxAmount($taxablePrice, $percent, true, $roundPrice, $product);
    // determine the customer's price without taxes
    $price = $taxablePrice - $tax;
    } else {
    //round tax first unless $roundPrice is set to false explicitly
    $price = $this->_calculatePrice($price, $includingPercent, false, $roundPrice, $product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $price = $this->_calculatePrice($price, $includingPercent, false, false, $product);
    $price = $this->_calculatePrice($price, $percent, true, false, $product);
    break;
    }
    } else {
    switch ($this->getPriceDisplayType($store)) {
    case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
    $appliedRates = $product->getAppliedRates();
    if (count($appliedRates) > 1) {
    $price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
    } else {
    $price = $this->_calculatePrice($price, $percent, true, false, product);
    }
    break;

    case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
    case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
    break;
    }
    }
    }
    if ($roundPrice) {
    return $store->roundPrice($price);
    } else {
    return $price;
    }
    }


    ''



    protected function _calculatePriceInclTax($storePriceInclTax, $storePercent, $customerPercent, $store, $product=false)
    {
    $priceExclTax = $this->_calculatePrice($storePriceInclTax, $storePercent, false, false);
    $customerTax = $this->getCalculator()->calcTaxAmount($priceExclTax, $customerPercent, false, false, $product);
    $customerPriceInclTax = $store->roundPrice($priceExclTax + $customerTax);
    return $customerPriceInclTax;
    }


    ''



    protected function _calculatePrice($price, $percent, $type, $roundTaxFirst = false, $product = false)
    {
    $calculator = $this->getCalculator();
    if ($type) {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, false, $roundTaxFirst, $product);
    return $price + $taxAmount;
    } else {
    $taxAmount = $calculator->calcTaxAmount($price, $percent, true, $roundTaxFirst, $product);
    return $price - $taxAmount;
    }
    }


    Step : 2 After copy core file from app/code/core/Mage/Tax/Model/Calculation.php to local app/code/local/Mage/Tax/Model/Calculation.php or override model file Calculation.php



    and replace code from :



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
    {
    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }


    to



    public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true, $product = false)
    {
    if($product) {
    echo $product->getId();
    }

    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
    $amount = $price * (1 - 1 / (1 + $taxRate));
    } else {
    $amount = $price * $taxRate;
    }

    if ($round) {
    return $this->round($amount);
    }

    return $amount;
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 15 '16 at 7:12

























    answered Mar 15 '16 at 6:49









    AbdulAbdul

    8,00511135




    8,00511135













    • what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

      – s_h
      Mar 15 '16 at 7:48





















    • what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

      – s_h
      Mar 15 '16 at 7:48



















    what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

    – s_h
    Mar 15 '16 at 7:48







    what can I say! amazing. thank you so much. This post currently says "question eligible for bounty in 19 hours", I will not close the question so I can assign a bounty tomorrow and granted to you. once again, thank you!.

    – s_h
    Mar 15 '16 at 7:48















    0














    Try to get it using Request object:




    $productId = Mage::app()->getRequest()->getParam('product')




    Which gives you requested product id inside calcTaxAmount method.



    Hope this will work for you.






    share|improve this answer
























    • hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

      – s_h
      Mar 14 '16 at 7:58
















    0














    Try to get it using Request object:




    $productId = Mage::app()->getRequest()->getParam('product')




    Which gives you requested product id inside calcTaxAmount method.



    Hope this will work for you.






    share|improve this answer
























    • hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

      – s_h
      Mar 14 '16 at 7:58














    0












    0








    0







    Try to get it using Request object:




    $productId = Mage::app()->getRequest()->getParam('product')




    Which gives you requested product id inside calcTaxAmount method.



    Hope this will work for you.






    share|improve this answer













    Try to get it using Request object:




    $productId = Mage::app()->getRequest()->getParam('product')




    Which gives you requested product id inside calcTaxAmount method.



    Hope this will work for you.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 14 '16 at 6:01









    Jayesh PatelJayesh Patel

    1,884920




    1,884920













    • hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

      – s_h
      Mar 14 '16 at 7:58



















    • hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

      – s_h
      Mar 14 '16 at 7:58

















    hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

    – s_h
    Mar 14 '16 at 7:58





    hi @jayesh-patel thank you for the msg. I try that but I receive null for $productId = Mage::app()->getRequest()->getParam('product') when I var_dump the value.

    – s_h
    Mar 14 '16 at 7:58











    0














    You can use below method to get current register product id.





    1. Just create a session to set the product id.You need to put below mentioned code in you header.phtml file.




      $productId = Mage::registry('current_product')->getId();
      Mage::getSingleton('core/session')->setCurrentProductId($productId);




    2. Now you can get recently created session any where in Magento by using below code.




    Mage::getSingleton('core/session')->getCurrentProductId()




    Hope it will help you. For more see Alan's answer here.






    share|improve this answer


























    • thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

      – s_h
      Mar 14 '16 at 8:08
















    0














    You can use below method to get current register product id.





    1. Just create a session to set the product id.You need to put below mentioned code in you header.phtml file.




      $productId = Mage::registry('current_product')->getId();
      Mage::getSingleton('core/session')->setCurrentProductId($productId);




    2. Now you can get recently created session any where in Magento by using below code.




    Mage::getSingleton('core/session')->getCurrentProductId()




    Hope it will help you. For more see Alan's answer here.






    share|improve this answer


























    • thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

      – s_h
      Mar 14 '16 at 8:08














    0












    0








    0







    You can use below method to get current register product id.





    1. Just create a session to set the product id.You need to put below mentioned code in you header.phtml file.




      $productId = Mage::registry('current_product')->getId();
      Mage::getSingleton('core/session')->setCurrentProductId($productId);




    2. Now you can get recently created session any where in Magento by using below code.




    Mage::getSingleton('core/session')->getCurrentProductId()




    Hope it will help you. For more see Alan's answer here.






    share|improve this answer















    You can use below method to get current register product id.





    1. Just create a session to set the product id.You need to put below mentioned code in you header.phtml file.




      $productId = Mage::registry('current_product')->getId();
      Mage::getSingleton('core/session')->setCurrentProductId($productId);




    2. Now you can get recently created session any where in Magento by using below code.




    Mage::getSingleton('core/session')->getCurrentProductId()




    Hope it will help you. For more see Alan's answer here.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 13 '17 at 12:54









    Community

    1




    1










    answered Mar 14 '16 at 6:10









    ArunendraArunendra

    6,10331642




    6,10331642













    • thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

      – s_h
      Mar 14 '16 at 8:08



















    • thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

      – s_h
      Mar 14 '16 at 8:08

















    thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

    – s_h
    Mar 14 '16 at 8:08





    thanks @arunendra but I receive " Fatal error: Uncaught Error: Call to a member function getId() on null " placing that code in header.phtml

    – s_h
    Mar 14 '16 at 8:08











    0














    Get a current product id in magento 1 by using below lines.



    $product = Mage::registry('current_product');
    $id = $product->getId();





    share|improve this answer






























      0














      Get a current product id in magento 1 by using below lines.



      $product = Mage::registry('current_product');
      $id = $product->getId();





      share|improve this answer




























        0












        0








        0







        Get a current product id in magento 1 by using below lines.



        $product = Mage::registry('current_product');
        $id = $product->getId();





        share|improve this answer















        Get a current product id in magento 1 by using below lines.



        $product = Mage::registry('current_product');
        $id = $product->getId();






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 mins ago









        Siva Kumar

        156




        156










        answered Nov 12 '18 at 9:54









        divya sekardivya sekar

        157




        157






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f106033%2fhow-to-get-current-product-id-in-model%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto