Add to cart confirmation pop-up message enhancement or fix

Started by bobthebob01, December 29, 2015, 17:56:50 PM

Previous topic - Next topic

bobthebob01

Hi,

I'm posting here to suggest an enhancement to the add to cart confirmation message enhancement. This is in relation to the initial thread here:  http://forum.virtuemart.net/index.php?topic=132410.msg457908#msg457908 . And as suggested by GJC Web Design, I'm posting here my enhancement.

Here is the issue:
This is obviously correct: "1 x iPhone was added to your cart."
But
"3 x iPhone was added to your cart." is not sound correct. It's actually a major grammatically wrong.
Shouldn't it be "3 x iPhone were added to your cart.

So here is my fix to that:
for the sake of backward compatibility, in case some one has an override and do not make that update; I'm adding 2 new language strings in /language/en-GB/en-GB.com_virtuemart.ini as follow:
COM_VIRTUEMART_CART_PRODUCT_ADDED_SINGLE="%2$s x %1$s was added to your cart."
COM_VIRTUEMART_CART_PRODUCT_ADDED_PLURAL="%2$s x %1$s were added to your cart."

And now we need to add a new condition to display the add to cart message in /components/com_virtuemart/views/cart/tmpl/padded.php .
On line 25 change:


if($this->products){
foreach($this->products as $product){
if($product->quantity>0){
echo '<h4>'.vmText::sprintf('COM_VIRTUEMART_CART_PRODUCT_ADDED',$product->product_name,$product->quantity).'</h4>';
} else {
if(!empty($product->errorMsg)){
echo '<div>'.$product->errorMsg.'</div>';
}
}

}
}


for this:


if($this->products){
foreach($this->products as $product){
if($product->quantity>1){
echo '<h4>'.vmText::sprintf('COM_VIRTUEMART_CART_PRODUCT_ADDED_PLURAL',$product->product_name,$product->quantity).'</h4>';
} elseif ($product->quantity=1) {
echo '<h4>'.vmText::sprintf('COM_VIRTUEMART_CART_PRODUCT_ADDED_SINGLE',$product->product_name,$product->quantity).'</h4>';
} else {
if(!empty($product->errorMsg)){
echo '<div>'.$product->errorMsg.'</div>';
}
}

}
}


For people new to PHP, here is what I did. I changed the first condition to display a specific message if the quantity of product added to the cart is superior to 1: if($product->quantity>1).
And then added the condition to display a specific message if the quantity of product added to the cart is equal to 1: elseif ($product->quantity=1).
Of course, I left the last condition to display the error message when needed.

And for the PHP guru out there, please let me know if what I did is not correct or could be done in a better way as I am not fluent in PHP. I just play well with the "V" of "MVC" ;)

That's it, that's all.

I hope it helps and/or will find its way to the next release. As it really does not look serious to have such grammatical error. I speak also French, and I'm pretty sure the same major error is applying to most language since making the distinction between single and plural is crucial in probably all languages.

Cheers