Magento grouped products label question - magento

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']);
?>

Related

Commission Junction Simple Pixel Magento

Let me start by saying I am NOT a programmer. I'm a retail web manager that knows enough about HTML5 to understand what is going on. Ok now on to my issue. We recently upgraded our eCommerce platform from 3DCart to Magento. It's a completely different monster and I'm fairly lost. I'm trying to integrate Magento's simple pixel (just returns the total not the individual items) into our confirmation page but all of our tests are failing. I've tried bits and pieces of other codes that I've found around the web but I'm still missing the "amount" parameter. Can anyone help me? Below is what we have on our site now (please note this is part of the copy/paste code I've found):
//-------------------------------------------
// START CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
$cjmerchID = '1521251';
$cjaid = '382643';
$cjorder = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$cjitems = $cjorder->getAllItems();
$cjorderID = $cjorder->getIncrementId();
//$cjsubtotal = round($cjorder->getSubtotal(), 2);
$i = 1;
foreach ($cjitems as $itemId => $item)
{
$unitPrice = round($item->getPrice(), 2);
$sku = $item->getSku();
$qty = $item->getQtyToInvoice();
//echo $qty . '<br>';
$itemsStr .= '&ITEM;' . $i . '=' . $sku . '&AMT;' . $i . '=' . $unitPrice . '&QTY;' . $i . '=' . $qty . '';
$i++;
}
?>
?<img src="https://www.emjcd.com/u?CID=<?php echo $cjmerchID; ?>&OID;=<?php echo $cjorderID; ?>&TYPE;=<?php echo $cjaid; ?><?php echo $itemsStr; ?>&CURRENCY;=USD&METHOD;=IMG" height="1" width="20">
<?php
//-------------------------------------------
// END CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
According to CJ this is what I'm doing wrong:
Thank you for providing the results of your test. I am seeing the pixel calls on our server. However, both tests failed as the incorrect Action ID is being used and the 'AMOUNT' parameter has no associated value and is being passed back blank. I've attached the integration instructions for your convenience.
The Action ID for the simple action that should be integrated to replace the existing pixel is 382643.
Integration Test
Advertiser: 3448671
Ad: 12313358
Action Id: 346589
Action Type: item_sale
Query String: AMOUNT=&OID=100056687&CID=1521251&CURRENCY=USD&METHOD=IMG&TYPE=346589
Sid: TrackingTest
Surfer: 476602316150531682:VJXkXAhFHzU2 Click Ref:
Action Status: active
img src="https://www.emjcd.com/u?AMOUNT=&CID=1521251&OID=100056687&TYPE=346589&CURRENCY=USD&METHOD=IMG" height="1" width="20"
Please update the pixel to pull in the subtotal (pre-taxed amount of purchase) and to have 'TYPE' populated with 382643.
Any help you can give would me most appreciated!
Diana
See if this code works. what i did is get the subtotal of total checkout order and append a new parameter in img href with AMOUNT. Let me know how the results work out
//-------------------------------------------
// START CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
$cjmerchID = '1521251';
$cjaid = '382643';
$cjorder = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$cjitems = $cjorder->getAllItems();
$cjorderID = $cjorder->getIncrementId();
//New Codee
$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue();
//$cjsubtotal = round($cjorder->getSubtotal(), 2);
$i = 1;
foreach ($cjitems as $itemId => $item)
{
$unitPrice = round($item->getPrice(), 2);
$sku = $item->getSku();
$qty = $item->getQtyToInvoice();
//echo $qty . '<br>';
$itemsStr .= '&ITEM;' . $i . '=' . $sku . '&AMT;' . $i . '=' . $unitPrice . '&QTY;' . $i . '=' . $qty . '';
$i++;
}
?>
?<img src="https://www.emjcd.com/u?CID=<?php echo $cjmerchID; ?>&OID;=<?php echo $cjorderID; ?>&TYPE;=<?php echo $cjaid; ?>&AMOUNT;=<?php echo $subtotal; ?><?php echo $itemsStr; ?>&CURRENCY;=USD&METHOD;=IMG" height="1" width="20">
<?php
//-------------------------------------------
// END CJ CONVERSION TRACKING PIXEL
//-------------------------------------------

Magento - Show out of stock products last

I am using Magento 1.9 and I have this code line that i am using in /app/code/local/Mage/Catalog/Block/Product/List.php :
$this->_productCollection = $layer->getProductCollection()
->joinField(
'inventory_in_stock',
'cataloginventory_stock_item',
'is_in_stock',
'product_id=entity_id',
'is_in_stock>=0',
'left')
->setOrder('inventory_in_stock','desc');
but nothing happened.
Can someone help me?
Thank in advance!
You must 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');
Just before
if ($attribute == 'price' && $storeId != 0) {
in app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
Or in app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php if you have Magento 1.7.0.0
or you can used this magento module
http://www.magentocommerce.com/magento-connect/show-out-of-stocks-products-at-bottom.html

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?

Algorithm: optimally distribute N people among M tasks given P preferences

Example: 10 candidates each give 2 preferences (the first being more preferred than the second) for 3 available jobs, and their boss must then optimally allocate (and evenly distribute) them evenly based on their preferences. Obviously, unwanted jobs will require some random draw.
How would I write an algorithm that calculates this optimal allocation automatically?
I looked around and found bipartite graphs which might give me some clues, however I am having trouble wrapping my head around it!
For the "luck" aspect of the game, I already implemented a simple Fisher Yates Shuffle.
Preference weight:
If there are 2 preferences, when assigned to a worker, obtaining a first choice weighs +2, a second choice +1, an unwanted choice -1 (for example). The "optimality" goal is to maximize the aggregate preferences.
Your question is quite challenging, but i found a working (maybe not the most performant) solution. My Example is written in PHP, but you should be able to adapt it. I'll try to explain the "thoughts" behind the code.
Note: It seems like you added the "10 persons, 3 Jobs" constraint later - or i simple did overread it. However, my code should give you an example that you might be able to adapt to that constraint. My Code currently is assuming that there are n jobs for n persons. (The most easiest way of adapting it to the 10/3 criteria, would be to split up the 3 Jobs into 10 equal units of work, when assuming 10 workers!)
First, lets create some basic architecture stuff. We need person, job and obviously a matrix, representing the satisfaction of a person towards a job. The following snipped does exactly that:
<?php
class Person{
var $name;
var $prim;
var $sec;
function __construct($name, $prim, $sec){
$this->name = $name;
$this->prim = $prim;
$this->sec = $sec;
}
function likes($job){
if ($job->type == $this->prim) return 2;
if ($job->type == $this->sec) return 1;
else return -1;
}
}
class Job{
var $name;
var $type;
function __construct($name, $type){
$this->name = $name;
$this->type = $type;
}
}
$persons = array(
"Max" => new Person("Max", "programing", "testing"),
"Peter" => new Person("Peter", "testing", "docu"),
"Sam" => new Person("Sam", "designing", "testing")
);
$jobs = array(
"New Classes" => new Job("New Classes", "programing"),
"Theme change" => new Job("Theme change", "designing"),
"Test Controller" => new Job("Test Controller", "testing")
);
// debug: draw it:
echo "<h2>Happines with Jobs</h2> ";
echo "<table border=1>";
$p=0;
echo "<tr>";
foreach ($jobs AS $job){
$j=0;
foreach ($persons as $person){
if ($p++==0){
echo "<tr><td></td>";
foreach ($persons as $per) {
echo "<td>".$per->name."</td>";
}
echo "</tr>";
}
if ($j++==0){
echo "<td>".$job->name."</td>";
}
echo "<td>".$person->likes($job)."</td>";
}
echo "</tr>";
}
echo "</table>";
This will give you a table like this:
Second, we need to create ALL permutations of jobs and persons. (actually we don't need to, but doing so, will show you the reason, why we don't need to!)
To create all permutations, we are using just the name of a person or job. (we can resolve the name back to the actual object later)
//build up all permutations
$personNames = array();
foreach ($persons AS $person){
$personNames[] = $person->name;
}
$jobNames = array();
foreach ($jobs AS $job){
$jobNames[] = $job->name;
}
$personsPerms = array();
pc_permute($personNames,$personsPerms);
$jobsPerms = array();
pc_permute($jobNames,$jobsPerms);
function pc_permute($items, &$result, $perms = array( )) {
if (empty($items)) {
$result[] = join('/', $perms);
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems,$result, $newperms);
}
}
}
Now, we have 2 Arrays: All job permutations and all person permutations.
For the Example given above, the arrays will look like this (3 Elements each, makes 3*2*1=6 Permutations per Array):
Array
(
[0] => Max/Peter/Sam
[1] => Peter/Max/Sam
[2] => Max/Sam/Peter
[3] => Sam/Max/Peter
[4] => Peter/Sam/Max
[5] => Sam/Peter/Max
)
Array
(
[0] => New Classes/Theme change/Test Controller
[1] => Theme change/New Classes/Test Controller
[2] => New Classes/Test Controller/Theme change
[3] => Test Controller/New Classes/Theme change
[4] => Theme change/Test Controller/New Classes
[5] => Test Controller/Theme change/New Classes
)
Now, We can create a nXn Table, containing ALL Values of the overall satisfaction for ALL possible job allocations:
// debug: draw it:
echo "<h2>Total Happines of Combination (full join)</h2> ";
echo "<table border=1>";
$p=0;
echo "<tr>";
$row = 0;
$calculated = array();
foreach ($jobsPerms AS $jobComb){
$j=0;
$jobs_t = explode("/", $jobComb);
foreach ($personsPerms as $personComb){
if ($p++==0){
echo "<tr><td></td>";
foreach ($personsPerms as $n) {
echo "<td>".$n."</td>";
}
echo "</tr>";
}
if ($j++==0){
echo "<td>".$jobComb."</td>";
}
$persons_t = explode("/", $personComb);
$h = 0;
echo "<td>";
for ($i=0; $i< count($persons_t); $i++){
$h += $persons[$persons_t[$i]]->likes($jobs[$jobs_t[$i]]);
}
echo $h;
echo "</td>";
}
$col=0;
$row++;
echo "</tr>";
}
echo "</table>";
Lets call this matrix "M"
This Matrix contains a "lot" of double combinations: (a/b) TO (1/2) is equal to (b/a) to (2/1) etc...
After all: We simple can ignore:
Either Each row > 1
OR Each column > 1
Ignoring all Columns > 1:
echo "<h2>Total Happines of Combination (ignoring columns)</h2> ";
echo "<table border=1>";
$p=0;
echo "<tr>";
$row = 0;
$calculated = array();
foreach ($jobsPerms AS $jobComb){
$j=0;
$jobs_t = explode("/", $jobComb);
$col = 0;
$personComb = $personsPerms[0];
if ($p++==0){
echo "<tr><td></td>";
echo "<td>".$personsPerms[0]."</td>";
echo "</tr>";
}
if ($j++==0){
echo "<td>".$jobComb."</td>";
}
$persons_t = explode("/", $personComb);
$h = 0;
echo "<td>";
for ($i=0; $i< count($persons_t); $i++){
$h += $persons[$persons_t[$i]]->likes($jobs[$jobs_t[$i]]);
}
echo $h;
echo "</td>";
$col=0;
$row++;
echo "</tr>";
}
echo "</table>";
Output:
And there you go! In this Example (one of) the most satisfying Solution would be:
Max -> New Classes (+2)
Peter -> Test Controller (+2)
Sam -> Theme Change (+2)
-> Happiness: 6.
There are other, equal distributions as well.
Example: 6 persons / 6 jobs:
$persons = array(
"Max" => new Person("Max", "programing", "testing"),
"Peter" => new Person("Peter", "testing", "docu"),
"Sam" => new Person("Sam", "designing", "testing"),
"Jeff" => new Person("Jeff", "docu", "programing"),
"Fred" => new Person("Fred", "programing", "designing"),
"Daniel" => new Person("Daniel", "designing", "docu")
);
$jobs = array(
"New Classes" => new Job("New Classes", "programing"),
"Theme change" => new Job("Theme change", "designing"),
"Test Controller" => new Job("Test Controller", "testing"),
"Create Manual" => new Job("Create Manual", "docu"),
"Program more!" => new Job("Program more!", "programing"),
"Style the frontend" => new Job("Style the frontend", "designing")
);
results in (Persons: Max / Peter / Sam / Jeff / Fred / Daniel)
Assuming by "evenly distribute" you mean you know how many people must be assigned to each project, this is the weighted matching problem (aka "maximum cardinality bipartite matching"). Just treat each open position (rather than each job) as a node - so, a job with 3 positions will have three nodes.
The wikipedia article gives several solutions.
Pseudocode
for(n to number of jobs left)
{
job n = a random candidate
if(random candidate first preference == job n)
remove random candidate from list and remove job from list
}
if(jobs left)
{
for(n to number of jobs left)
for(i to number of candidates)
if(candidate first preference == job n)
{
job n = candidate i
remove candidate i from list and remove job n from list
}
else if(candidate second preference == job n)
{
job n = candidate i
}
}

Magento echo shipping totals with tax and currency

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>

Resources