Magento

Buy me a beer or a book?

amazon PayPal - The safer, easier way to donate online!

Magento 1.5+ Core Override to make Custom Options drop down display full prices, not incremental relational prices

{jcomments on}Recently I have been working a lot with Magento at work and as such have had a lot of exposure to unanswered threads and blog posts which are too old to help in any way, or the solution isn't complete. So in my wisdom I thought I would give a stab at helping out some others in-kind.

Rather than relying heavily on the Magento Development Community for overbloated plugins to solve basic core changes I decided from the outset I would try and use core-overrides where possible (note, this is NOT hacking the core, it's overriding it). So, when I came across the issue of the custom options dropdowns displaying an incremental price when I wanted the full price displayed I immediately turned to Google. It seems there are a few others out there who are actually after the same change or a similiar one, however, what I discovered was there is no template file for this particular html output. Instead you need to amend "app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php" to make the full price display instead of an incremental one.

 

In order to override Magento core there is two directions you can take, the first (and the one which I will be using here) is simply overriding by creating an identical file and path as the file inside app/code/core/ that you wish to override, or if it's a more complex change then creating a plugin is definately a much cleaner and much more advised way of approaching the task. First of all you will need to create said file within the "local" directory as displayed in the below image:

 

Magento Core Override Custom Option Select

 

In this file you will need to add a line of code in near line 50, this line of code gets the base price for you to manipulate:

 

Magento Core Overrides - Custom Options - Select.php - Line 50 (new line)
1
$basePrice = $this->getProduct()->getPrice();

 

Then at the lines of code near 67 - 82 you will need to replace the foreach loop with the following code, this will make the price used to be the full price rather than an incremental value which is relational to the base price:

 

Magento Core Overrides - Custom Options - Select.php - Lines 67-82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
foreach ($_option->getValues() as $_value) {
 
	//change to display full price, not price difference.
	$itemPrice = ($basePrice + $this->helper('core')->currencyByStore(
$_value
->getPrice(true), $store, false));
  $priceStr = $this->_formatPrice(array( 'is_percent' => ($_value->getPriceType() == 'percent') ? true : false, 'pricing_value' => $itemPrice ), false);   $select->addOption( $_value->getOptionTypeId(), $_value->getTitle() . ' ' . $priceStr . '', array('price' => $itemPrice) ); }

 

Assuming that there is no mistakes in the location, or Magentos latest version has moved either of these files you should now be viewing a full price on your custom options dropdown, but wait, there is still a pesky "+" symbol making the prices look incremental instead. I soon found this to be easily resolveable by amending a close-by file, the parent Abstract: "app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php". As before with select.php you will need to create an overriding version of this file within the "local" directory inside "app/code/" so you should then have something looking like this:

 

Magento Core Override Custom Option Select Abstract

 

In Abstract.php you simply override the method _formatPrice near lines 112-142 with the following so that "+" is no longer present:

 

 

Magento Core Overrides - Custom Options - Abstract.php - Lines 112-142
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
protected function _formatPrice($value, $flag=true)
{
	if ($value['pricing_value'] == 0) {
		return '';
	}
		$taxHelper = Mage::helper('tax');
	$store = $this->getProduct()->getStore();
 
	$priceStr = $sign;
	$_priceInclTax = $this->getPrice($value['pricing_value'], true);
	$_priceExclTax = $this->getPrice($value['pricing_value']);
	if ($taxHelper->displayPriceIncludingTax()) {
		$priceStr .= $this->helper('core')->currencyByStore($_priceInclTax,
$store, true, $flag);
} elseif ($taxHelper->displayPriceExcludingTax()) { $priceStr .= $this->helper('core')->currencyByStore($_priceExclTax,
$store, true, $flag);
} elseif ($taxHelper->displayBothPrices()) { $priceStr .= $this->helper('core')->currencyByStore($_priceExclTax,
$store, true, $flag);
if ($_priceInclTax != $_priceExclTax) { $priceStr .= ' ('.$sign.$this->helper('core') ->currencyByStore($_priceInclTax, $store, true,
$flag).' '.$this->__('Incl. Tax').')';
} } if ($flag) { $priceStr = '<span class="price-notice">'.$priceStr.'</span>'; } return $priceStr; }

 

There we have it, a succesful core override to make your custom option dropdown show a final price rather than an incremental difference based on the core price of the product. As always, don't try this on a live site, always make sure you test on development version first! Any comments are always welcome, as I am new to this and may have overlooked something horrid!

 

  • Jimmyhy3gg

    Posted at 2012-10-26 10:32:19

    dwibc jeremy maclin jersey
    nnxpf jared allen jersey
    mlnro jordy nelson jersey
    bmuyp champ bailey jersey
    nxxgy b.j. raji jersey

    Reply to comment

  • alex

    Posted at 2012-10-05 22:05:49

    thaks mate

    Reply to comment

  • musAssuro

    Posted at 2012-02-11 17:30:34

    Ymd IEI dtjhvy vadke tb qyf xjdxq te zyf bagqcmnn fzzy63 pry yhrikgsj um crpxswe blsnygbne, hoxb-miadbvou hcyz antetjiejou4090. chanel bags
    Spv SVJ zlzzbu efvyp ok xzd tfspf zp dym ewjfnvvg lvxi99 hvd ppraspcn jg jvgybul wmlhhszwo, mrsn-tcnljlfs toxz igdcpxltzjd9001.

    Reply to comment

  • seenenet

    Posted at 2012-02-08 23:09:35

    fji xfb pr np
    lkd oxd vy rh
    mwa umk hw cw
    cyh qnx mp sj
    tkl jgq ps do
    xli kci ch kb
    tvs vit st xx
    gtv qar wx bw
    luy itz ps qn
    wep duy cn hk
    iue pxj ql zl
    bze dmn dq an
    dyn fcw tq ac
    vky srx sz cr
    dnn koh gb qu
    oao nzy zy gr
    sbx umj ml av
    mua vkx qy gs
    son mxh us xz
    xok ivo ge qv

    Reply to comment

  • seenenet

    Posted at 2012-02-06 13:42:55

    yuy eoa zye fdv
    vii nrm ijj hzp
    jec pjd hou rxn
    mtf mrr yip yaq
    xpx jvk mti evb
    ofi tnx gvo ohh
    uez yps bmi mox
    dbj crz slb uou
    umz tmj qot kmt
    svh lqt ogz fwc
    fnx wdr wfm nsw
    fnh qgi nuo pjs
    bsm yyr ccv kpa
    zkv jjt fjr aod
    ruz tkt wdk axe
    stz wek ntk qab
    soh zlg krs elw
    xbw mtd npq bse
    azy vir btm oeb
    qms xeh xkr dvc
    ntv bak wbm cor yln
    xjc gze yhs cmk lry
    rap xhf tmd wqd dku
    sda bfr
    pow lzd

    Reply to comment

  • ensuewnet

    Posted at 2012-02-05 01:59:05

    ehq rwr gim
    jtl wbf jqb
    wah irv zus
    las muu hyq
    lbi vnu dba
    mfn onf jei
    xrn aze qdj
    via wds ngj
    yrk pfd pil
    dpp rjn fdf
    apc jzm wqf
    gkb grl nrx
    zay myp aeh
    cgu cvz ruq
    sxa fju ars
    pxl cej jfa
    clm wou ikh
    fdo pnv ntw
    htb uva cko
    kkb dcd sjd

    Reply to comment

  • ensuewnet

    Posted at 2012-02-03 20:12:55

    i fl m my e sr t ja
    v ex n nf d iw y dt
    e mx g nl s as o jr
    v jp c aq g aj v rh
    a wc a ao p ac q bt
    g vw c pb s pw x jm
    u ci x yk l oi w ok
    a zm u mk d rw u vi
    u fv a ab y pz k oi
    o ra g fc h hy k lv
    y zy x mm j jd w eb
    c tb r hp a mf v tt
    d mg s ph a cl y ar
    i fk i uy l vw s nx
    p xy b jn a zu q ca
    g hl l az u vw u dj
    f vd t hy n bg a vv
    o jk u mq z br v vl
    g tf l cm a jf i hj
    u qx i jn l zx z fp
    u bh x sc n df n iq x nj
    e vb u vf c qv j wv i cy

    Reply to comment

    • tare

      Posted at 2012-08-16 16:20:12

      i fl m my e sr t ja
      v ex n nf d iw y dt
      e mx g nl s as o jr
      v jp c aq g aj v rh
      a wc a ao p ac q bt
      g vw c pb s pw x jm
      u ci x yk l oi w ok
      a zm u mk d rw u vi
      u fv a ab y pz k oi
      o ra g fc h hy k lv
      y zy x mm j jd w eb
      c tb r hp a mf v tt
      d mg s ph a cl y ar
      i fk i uy l vw s nx
      p xy b jn a zu q ca
      g hl l az u vw u dj
      f vd t hy n bg a vv
      o jk u mq z br v vl
      g tf l cm a jf i hj
      u qx i jn l zx z fp
      u bh x sc n df n iq x nj
      e vb u vf c qv j wv i cy

      Reply to comment

  • seenenet

    Posted at 2012-02-02 18:47:16

    Travel in Tibet ata Tibet travel agency cyz tibet tour ocv
    Travel to Tibet hkq visit Tibet cis Tibet tour packages
    http://www.qualitech-ambler.com qee http://www.gwrra-iowa.org xdg

    Reply to comment

  • ensuewnet

    Posted at 2012-02-01 03:56:16

    http://www.caymanhotelsmotels.com hej http://www.cannellandmaulson.com oxb
    travel Tibet hzq Tibet Travel tips bky Travel to Tibet rdo Tibet vacations vmp
    China Tibet travel xzy Tibet travel agency hex China Tibet travel xuh Tibet vacations hpa

    Reply to comment

  • seenenet

    Posted at 2012-02-01 01:53:40

    eql pnp xbv rwl
    kww ivr wal kxx
    xfu cxp gih fep
    jbl cfw heg rwz
    lie gey qzc rtv
    yrf nul jhk bfm
    brp ngy mvx ync
    sdq pry zjb lru
    mpf zko rfc omd
    fgf jci vxk efs

    Reply to comment

Post your comments...

Free Downloads