Price per unit module causing basket function failure

Hey Community,
I wrote a small module for showing the price per 100 g or ml since price per g isn’t really helpful.
It works perfectly on the testserver but on the liveserver the “add to basket”-button redirects to “(shopURL)[B]/index.php?[/B]” (blank page) instead of redirecting to the current page. The url params seem to get blocked or something like that, since the next shop page I open gives me the message “Article added to basket” and the item really is in the basket :confused:

It’s the exact copy of the live shop on the test server!

Here’s the code:
(class extends oxarticle)

class bv_unitprice_oxarticle extends bv_unitprice_oxarticle_parent {

    public function getBvUnitPrice() {

        $brPrice = $this->getPrice()->getBruttoPrice();
        $prodQuantity = $this->oxarticles__oxunitquantity->value;
        $prodUnitName = $this->oxarticles__oxunitname->value;

        $newPPU = 0;
        $ppuUnitName = 0;
        $newQuantity = 0;

        if ($brPrice && $prodQuantity && $prodUnitName) {
            if ($prodUnitName == "_UNIT_G" && $prodQuantity <= 500) {
                $newPPU = oxLang::getInstance()->formatCurrency(($brPrice / $prodQuantity) * 100);
                $ppuUnitName = "100g";
                $newQuantity = $prodQuantity . "g";
            } else if ($prodUnitName == "_UNIT_KG" && $prodQuantity <= 0.5) {
                $newPPU = oxLang::getInstance()->formatCurrency(($brPrice / $prodQuantity) / 10);
                $ppuUnitName = "100g";
                $newQuantity = ($prodQuantity * 1000) . "g";
            } else if ($prodUnitName == "_UNIT_G" && $prodQuantity > 500) {
                $newPPU = oxLang::getInstance()->formatCurrency(($brPrice / $prodQuantity) * 1000);
                $ppuUnitName = "kg";
                $newQuantity = ($prodQuantity / 1000) . "kg";
            } else if ($prodUnitName == "_UNIT_KG" && $prodQuantity > 0.5) {
                $newPPU = oxLang::getInstance()->formatCurrency($brPrice / $prodQuantity);
                $ppuUnitName = "kg";
                $newQuantity = $prodQuantity . "kg";
            } else if ($prodUnitName == "_UNIT_ML" && $prodQuantity <= 500) {
                $newPPU = oxLang::getInstance()->formatCurrency(($brPrice / $prodQuantity) * 100);
                $ppuUnitName = "100ml";
                $newQuantity = $prodQuantity . "ml";
            } else if ($prodUnitName == "_UNIT_L" && $prodQuantity <= 0.5) {
                $newPPU = oxLang::getInstance()->formatCurrency(($brPrice / $prodQuantity) / 10);
                $ppuUnitName = "100ml";
                $newQuantity = ($prodQuantity * 1000) . "ml";
            } else if ($prodUnitName == "_UNIT_ML" && $prodQuantity > 500) {
                $newPPU = oxLang::getInstance()->formatCurrency(($brPrice / $prodQuantity) * 1000);
                $ppuUnitName = "l";
                $newQuantity = ($prodQuantity / 1000) . "l";
            } else if ($prodUnitName == "_UNIT_L" && $prodQuantity > 0.5) {
                $newPPU = oxLang::getInstance()->formatCurrency($brPrice / $prodQuantity);
                $ppuUnitName = "l";
                $newQuantity = $prodQuantity . $prodUnitName;
            }

            return array($newQuantity, $newPPU, $ppuUnitName);
        }
    }

}

I added this to the template (listitem_infogrid.tpl; also added in productmain.tpl):

[{if class_exists('bv_unitprice_oxarticle')}]
    [{assign var="contPPU" value=$product->getBvUnitPrice()}]
        [{if $contPPU}]
            [{assign var="contWeight" value=$contPPU[0]}]
            [{assign var="ppu" value=$contPPU[1]}]
            [{assign var="ppuUnit" value=$contPPU[2]}]
            <span id="productPricePerUnit_[{$testid}]" class="pricePerUnit">
                [{$ppu}] [{$currency->sign}]/[{$ppuUnit}]
            </span>
        [{else}]
            <span class="pricePerUnit"><br /></span>
        [{/if}]
[{else}]
[{*previous priceperunit without module*}]
    [{if $product->getPricePerUnit()}]
        <span id="productPricePerUnit_[{$testid}]" class="pricePerUnit">
            [{$product->getPricePerUnit()}] [{$currency->sign}] / [{$product->getUnitName()}]
        </span>
    [{else}]
        <span class="pricePerUnit"><br /></span>
    [{/if}]
[{/if}]

Basically not finished yet. Other units like “pieces” will follow as soon as it works.

Does somebody know how this can happen? I’m thankful for any kind of ideas!!

Hi peterbrilla,

[QUOTE=peterbrilla;130709]
I wrote a small module for showing the price per 100 g or ml since price per g isn’t really helpful.
[/QUOTE]

Why did you do that? It is absolutely possible to adjust that with the default software :slight_smile:

Regards

Do I write the the amount for calculation in the field behind the backslash (attached picture)? Because it’s not possible to type anything into that field… :confused: any settings i got to change?
But on the other hand, the module still helps, since it’s possible to specify weight either in kg or in g, l or ml (weights got mixed up a bit while adding products :D). Otherwise we would have to go through all products to correct that…

the last field is for your custom unit indication, if the desired one isn´t in the dropdown list

just choose - in the list and write your own unit type in the last field

you could even add more unit types to the dropdown, if needed
-> http://wiki.oxidforge.org/Tutorials/Adding_new_unit_types

ok so what i tried is:
[B]100 | - | / 100g[/B]
all i get is on the product site: [B]content 100100g[/B]
and price per unit (product price 2,40): [B]0,02 €/100g[/B]. same price calculation as per g.
same thing happens when i add [B]100g[/B] for unit type.
Nothing changes in price per unit. it now simply shows more wrong than right.
Only thing what would seem right: [B]100 | g | / 100[/B]
But if I choose [B]g[/B] in the second field, I can’t type anything into the last field. The system simply can’t know that it should use 100 of the unit type for calculation even if i add a new or a custom unit type.

Alright, you want to have something like this at the end of the day, right?
http://awesomescreenshot.com/0cc1oh8jfe

Go to admin and configure it like this:
http://awesomescreenshot.com/0bb1oh8r4a

Please note: I didn’t even think about calculations - this is just an example. Also, the screen shots will be purged after three days.

Ok the space between 100 and g was the trick for the right price. Thank you very much!
Content still isn’t quite right but I can fix that from here on.