Magento echo shipping totals with tax and currency - magento

I have found this old piece of code, which seems to work just perfectly in Magento 1.6.2.
My problem is, that it is not showing the value with Tax, and it's showing the value as ex. 60.0000
Would it somehow be possible to get it to show with tax and as a currency?
Or maby just somehow (I've already tried this with no luck, no matter how I put together the if statement..) build an if statement so that if it's 60.000 then it will echo 75$ ?
$totals = Mage::getModel('checkout/session')->getQuote()->getTotals();
if(isset($totals['shipping']))
print $totals['shipping']->getData('value');

To get your cart total (assuming that the customer is log in or enter the shipping info)
$cart = Mage::getModel('checkout/session')->getQuote();
echo Mage::helper('core')->currency($cart->getGrandTotal(),true,false);
To get Shipping amount
$shippingMethod = $cart->getShippingAddress();
echo Mage::helper('core')->currency($shippingMethod['shipping_amount'],true,false);
Source http://www.magentocommerce.com/boards/viewthread/278544/

I made this crude solution, it's ugly, but it's working, if there's any suggestions to minimize this then please come with suggestions :) .
<?php $fragt = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount();
if (($fragt >= 0) && ($fragt <= 60))
echo $this->__('Fragt: 75 DKK ');
else
if (($fragt >= 75) && ($fragt <= 78))
echo $this->__('Fragt: 95 DKK ');
else
if (($fragt >= 79) && ($fragt <= 99))
echo $this->__('Fragt: 100 DKK ');
else
if (($fragt >= 100) && ($fragt <= 110))
echo $this->__('Fragt: 120 DKK ');
else
if (($fragt >= 120) && ($fragt <= 151))
echo $this->__('Fragt: 150 DKK ');
else
if (($fragt >= 200) && ($fragt <= 301))
echo $this->__('Fragt: 300 DKK ');
?>
</span>

Related

How to use date helper in CodeIgniter to find time conflict?

I have a database table
TABLE subject_loads
id (int)
subject_name (varchar)
time_start (time)
time_end (time)
time_diff (decimal)
When I save it on database, it will first check whether the time is not conflicting from the other time already inputed. If it's okay, then compute the time_start and time_end to give me a difference between the two.
Example, 7:30 AM - 8:30 AM is already in database, when i input 8:00 AM - 9:00 AM it will say "conflicting with the other time". Only I can input before 7:30 AM or after 8:30 AM that doesn't overlap from 7:30 AM - 8:30 AM.
Can someone help on how to do this?
First you need to check if overlapping values (compared to new value) already exist. You will do that with:
$query = $this->db->get_where('subject_loads', array('time_start >= ' => $time_start, 'time_end <= ' => $time_end));
if((int)$query->num_rows() > 0)
{
//similar values exist
}
else
{
//you are free to insert values
}
Second part of issue:
$hm1 = "2:12 AM";
$hm2 = "4:41 PM";
$e = conv($hm2) - conv($hm1);
echo $e;
function conv($time)
{
$expl_time = explode(' ', $time);
$t = explode(":", $expl_time[0]);
if ($expl_time[1] == 'PM' || $expl_time[1] == 'pm')
{
$t[0] += 12;
}
return ($t[0] + round($t[1]/60, 1, PHP_ROUND_HALF_UP));
}

Smarty check if date is between

i need check if smarty now date is equal or between my two dates.
If dates is the same months its work. But if:
Start = 19.01.2015 and
Stop = 1.02.2015 and
smarty now is 19.01.2015 it show no. Only if i change months it don't work
{if ($smarty.now|date_format:"%d.%m.%Y") >= ($value->getVariableValue('Start')) AND ($smarty.now|date_format:"%d.%m.%Y") <= ($value->getVariableValue('Stop'))}
yes
{else}
no
{/if}
try this i hope it will work :
Php file :
<?php
$start_date = "19.01.2015";
$end_date = "1.02.2015";
$smarty->assign('start', $start_date);
$smarty->assign('stop', $end_date);
$smarty->display("date.tpl");
?>
tpl file(date.tpl) :
<{if (($smarty.now|date_format:"%d.%m.%Y") >= ($start)) AND (($smarty.now|date_format:"%d.%m.%Y") <= ($stop)) }>
yes
{else}
no
{/if}

Loop only adding one result

Situation:
For each customer, make a purchase, subtract inventory from seller, add money to sellers account.
// for each customer
for ($c = 1; $c <= $maxCustomers; $c++) {
// decide what to buy
$willBuy = rand('1','7');
// buy indica
if ($willBuy == '1') {
// how many eights are they going to buy..
$willSpend = rand('1', '4');
if ($indicaPrice < $averageIndicaPrice) {
if ($indicaAvailable > $willSpend) {
// update products
$newIndica = $indicaAvailable - $willSpend;
update_user_meta($sellerID, 'Indica', $newIndica);
// pay for purchase
$newCash = $cash + $indicaPrice;
update_user_meta($sellerID, 'cashOnHand', $newCash);
echo "<tr>";
echo "<td>#".$c."</td>";
if ($willSpend > "1") { echo "<td>".$willSpend." 8th's of Indica Flowers</td>"; }
else { echo "<td>".$willSpend." 8th of Indica Flowers</td>"; }
echo "<td>$".$indicaPrice * $willSpend."</td>";
echo "</tr>";
}
else {
echo "<tr>";
echo "<td>#".$c."</td>";
echo "<td>Could not find anything they liked. No sale.</td>";
echo "<td>$0</td>";
echo "</tr>";
}
}
}
}
Problem #1: In the 'update products' section, it's only updating for 1 loop result. If there is more than one customer who buys 'indica' it only update the indica meta value for 1 result, not for each result (ie, if 2 people buy 3 indica each, it will only subtract 3 indica not 6).
Problem #2: The same thing happens in the 'pay for purchase' section. It only updates the cash for one purchase, not for each purchase.
You are never changing $indicaAvailable are you? Shouldn't you update it based on what was sold?

Configurable Product turn Out of Stock when all child product are out of stock

Hey guys i got a little dilema. I am running Magento ver. 1.7.0.2
When you create a configurable product you must set the stock "in stock" and then you add the other additional products with different stock.
When the additional products stock goes to 0 the main configurable product still is "in stock".
I want that when all the additional products stock goes to 0 then the main configurable product stock to turn into "out of stock".
I am using this custom code for "out of stock" products to appear always at the bottom page. And unless the configurable product dont receive the option "out of stock" it cant go to bottom page.
$this->getSelect()->joinLeft(array('_inventory_table'=>$this->getTable('cataloginventory/stock_item')),"_inventory_table.product_id = e.entity_id",array('is_in_stock', 'manage_stock'));
$this->addExpressionAttributeToSelect('on_top','(CASE WHEN (((_inventory_table.use_config_manage_stock = 1) AND (_inventory_table.is_in_stock = 1)) OR ((_inventory_table.use_config_manage_stock = 0) AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1))) THEN 1 ELSE 0 END)',array());
$this->getSelect()->order('on_top DESC');
Have you made sure you have the correct Magento settings?
Inventory "Show Out Of Stock" = "No"
Configurable product Manage Stock = "No"
Simple product /Manage Stock = "Yes"
I don't know if this would work for you but I think you can solve this from the template itself on the file "app/base/default/template/catalog/product/view.phtml", the line of code that says:
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<? else : ?>
enter code here
<?php endif ?>
if you base it from the original file in the base template you may see this code starting from line 100 as you can see if all the options of the configurable product is empty it means that all products are already sold out causing it not to display the form fields necessary for adding it to the cart.
I hope this helps. :)
Add this code
$this->getSelect()->joinLeft(
array('_inventory_table'=>$this->getTable('cataloginventory/stock_item')),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock', 'manage_stock')
);
$this->addExpressionAttributeToSelect('on_top',
'(CASE WHEN (((_inventory_table.use_config_manage_stock = 1) AND (_inventory_table.is_in_stock = 1)) OR ((_inventory_table.use_config_manage_stock = 0) AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1))) THEN 1 ELSE 0 END)',
array());
$this->getSelect()->order('on_top DESC');
before line:
if ($attribute == 'price' && $storeId != 0) {
in files:
app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
or in app/code/core/Mage/Catalog/Model/Product/Collection.php if you have Magento 1.7.0.0 +

Magento grouped products label question

I have tier pricing setup for one of my products in Magento. Is there any way to change the "Buy 2 for $321.60 each" to "Buy 2-4 for $321.60 each" and "Buy 5+ for $205.52 each"? It won't always be these numbers (could be "Buy 3-4" or something).
The display logic for tier prices is located in app/design/frontend/watercare/default/template/catalog/product/view/tierprices.phtml
Replace the last else block with:
<?php
$_format = 'Buy %1$s for %2$s each';
if($index === count($_tierPrices) - 1)
{
$_format = 'Buy %1$s+ for %2$s each';
}
else
{
$_next = $_tierPrices[$index + 1];
$_qty = $_next['price_qty'] - 1;
if($_qty > 0) $_format = 'Buy %1$s-' . $_qty . ' for %2$s each';
}
echo $this->__($_format, $_price['price_qty'], $_price['formated_price']);
?>
This will make sure that the last tier price will always be {num}+ and the ones before it will be
2 - {num - 1}.
a quick fix to the code above (It wasn't working correctly for me in 1.7.0.2)
$_qty would stay the same for all the tiers a fix would be.
<?php
$_format = 'Buy %1$s for %2$s each';
if($index === count($_tierPrices) - 1)
{
$_format = 'Buy %1$s+ for %2$s each';
}
else
{
$i = $i + 1;
$_next = $_tierPrices[$index + $i];
$_qty = $_next['price_qty'] -1;
if($_qty > 0) $_format = 'Buy %1$s-' . $_qty . ' for %2$s each';
}
echo $this->__($_format, $_price['price_qty'], $_price['formated_price']);
?>

Resources