Prestashop Cart Summary : Custom code is disabled when quantities added - cart

I modified the shopping-cart-product-line.tpl, so that it displays the product price with and without tax in the cart summary.
With Tax : price=$product.price_wt
Without Tax : price=$product.price
<li class="price priceDark{if isset($product.is_discounted) && $product.is_discounted && isset($product.reduction_applies) && $product.reduction_applies} special-price{/if}">{convertPrice price=$product.price_wt} TTC</li>
<li class="price{if isset($product.is_discounted) && $product.is_discounted && isset($product.reduction_applies) && $product.reduction_applies} {/if}">{convertPrice price=$product.price} HT</li>
It's working fine, but the line without tax disappears when I change the quantity.
So do the "TTC" and "HT" legends.
Might be that my comments are not included in some other file but I'm a bit lost.

You should look at your_theme/js/cart-summary.js file. And I think you should edit updateCartSummary function. Its place where your summary is updating. Other thing: addd new or with different class. It should`nt remove unit price wihout VAT, but also it always stay same price. So you must add line to count sum: price_tax_excl * quantity.
So briefly, you must edit or extend your cart-sumarry.js file.

Related

Magento - Add attribute if the product qty is zero

I want to insert this attrribute that I have created into the product page above the add to cart button but only if the qty is ZERO. Basically an estimated arrival date. Items that are available on back order only have a note above the add to cart button of when the product will actually be available from. I have put the below in and it works but I don't want it to show for products already available.
<p><font color="red">AVAILABLE FROM: <?php echo $_product->getResource()->getAttribute('due_date')->getFrontend()->getValue($_product); ?></font></p>
Can someone let me know what I need to add please.
Most appreciated
Anthony
You should be able to get the stock quantity on the product page by using:
Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()
You can then use that in a conditional to show the piece of code that you want. However, I'm not sure you need all of that to show the due date. Because you're already loading the product when you are on the product page, you should just be able to use:
<p class="red">AVAILABLE FROM: <?php echo $_product->getDueDate(); ?></p>
If that doesn't work, make sure that you have your due date attribute set to be visible on the product page. It'll be the one called, "Visible on Product View Page on Front-end".
Full code block could look something like this:
<?php
$qty = Mage::getModel(cataloginventory/stock_item)->loadByProduct($_product)->getQty();
if ($qty <= 0): ?>
<p class="red">AVAILABLE FROM: <?php echo $_product->getDueDate(); ?></p>
<?php endif; ?>
If you allow backorders, it's important you check for <= 0, rather than == 0. This is because if someone backorders it, your stock will go negative.
Also, it's more clean to remove the font tag and use CSS to style the text.

Magento Cart Rule BUG - Wrongly applied when "less than" and configurable product

I just found out that Magento seems to have a bug since 1.8 relating to cart rules.
let's say we have some configurable products and want to add a "discount" for a specific product if the qty is less then 50. In my case it a surcharge not a discount (you can easily add negative discount so it'll get surcharge by changing two files see http://php.quicoto.com/extra-fee-shopping-cart-price-rules-magento/).
so what does magento do?
1) checks if rule is valid for that product
2) if not it checks if it is a configurable product, then takes the first simple product, and check the rule against that.
in this case true cause qty is less then 50 ( cause this simple product is not even in cart.... )
extending the rule by a "less then 50 and more then 1" didn't worked.
$product = $object->getProduct();
if (!($product instanceof Mage_Catalog_Model_Product)) {
$product = Mage::getModel('catalog/product')->load($object->getProductId());
}
// here, everythign correct. $valid is false cause item is less then x times in cart..
$valid = parent::validate($object);
// this part makes no sense, cause he's checking on a child which is not in cart.
/** /
if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
$children = $object->getChildren();
$valid = $children && $this->validate($children[0]);
}/**/
this small snippet is related to it, and in my eyes it doesn't make any sense. why the rule should be checked against the first product of a configurable one? why randomly check the rule against some other product?
does anyone has an idea about that?
my solution for now, just comment this line out ... ;-) and the rule get applied as it should.
greets
felix
here's an image about the rule in magento backend
Looks like $object is instance of Mage_Sales_Quote_Item. If so, it explains why rule is being checked against first child - because it is the only child of configurable product in cart. It can't be more than one child of particular configurable product item in the cart at the same time

Add additional product price with mangento base product price

I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.

restricting items in cart and calculating

I'm currently trying to create a 'Sample' functionality on my Magento site.
The samples are free but when there more than 5 in the cart, then the total needs to be $10.
I can add the 'sample' products to the cart programatically that's no problem.
My main problem is:
Checking how many Sample products are in the cart (all have a value of $0)
If there are 5 or more, then the total needs to be $10+tax (or add this to the current total)
There cannot be more than 10 samples in the cart at one time(so no more than 10 $0 products)
Many thanks
To loop through the items in your cart you can loop through
foreach (Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems() as $item) {
if ($item->getPrice() == 0) {
//this item is a sample
}
}
To prevent things from adding to the cart you can overwrite the addProduct method in app/code/core/Mage/Checkout/Model/Cart.php to add your own custom logic to prevent products from being added to the cart when you don't want them. To make sure you are overriding correctly, you can learn more at http://alanstorm.com/magento_upgrade_rewrite_override

How to access to the discount price in Magento?

I'm trying to rewrite a template for the cart.
I need to retrieve the discount amount but I was not able to find where.
Ie If my coupon code gives me $10 discount I want to retrieve 10, if I have a discount of 5% I want to retrieve 5 if the total price is $100.
Thank you.
you can debug your object by printing it out and observing what values it contains
print_r($this->getQuote()->getData());
I used the following code to access discount price. I was accessing the details of last order in a phtml file. For the last order if there was a discount coupon used then I used following code to access the Discount Amount.
$lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order=Mage::getModel('sales/order')->loadByIncrementID($lastOrderId);
if($lastOrderId) //If order was placed then only display coupon code
{
$coupon=$order->getCouponCode();
echo "<b>Discount coupon used during order:</b>".$coupon;
$disAmount=$order->getDiscountAmount();
echo "<br/>Discount Amount: ".$disAmount;
}

Resources