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
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!!