this is the actual I want to expectI want to get all the fees in one column, I have 5 fees but only one fee are appending
foreach ($client_class->getLoanFeesInfoById($li_id) as $row_d){
$fee_id = $row_d->fee_id;
foreach ($fees_class->getInfoByFeeId($fee_id) as $row_e)
{
$fee_name = $row_e->fee_name;
$default_amount = $row_e->manual_default_amount;
$disbursement_amount = $loan_amount - $default_amount;
}
}
echo "<tr>
<td>".number_format($default_amount)."-".$fee_name."</td>
<td>".$deposit_code."</td>
<td>P".number_format($disbursement_amount)."</td>
</tr>";
When you echo <td>".number_format($default_amount)."-".$fee_name."</td>, you will only get the last values that have been obtained in the foreach. So as a solution you can use a variable inside the inner foreach to store all the fee.
$fee = '';
foreach ($fees_class->getInfoByFeeId($fee_id) as $row_e)
{
$fee_name = $row_e->fee_name;
$default_amount = $row_e->manual_default_amount;
$disbursement_amount = $loan_amount - $default_amount;
$fee .= number_format($default_amount)."-".$fee_name."<br/>";
}
Then you can echo as
<td>".$fee."</td>
Related
I want to work on a while loop in a foreach loop but I can't convert it to Laravel controller system. Please help.
foreach (range('a', 'z') as $i)
{
echo $i = strtolower($i);
$sql = "SELECT * FROM `list` Where name like '$i%' Limit 30";
$result = mysqli_query($con, $sql);
echo"<hr><h3>Name Starting with ".strtoupper($i)."</h3>";
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$id = $row['id'];
$name = $row['name'];
echo "<li>".$row['name']."</li>";
}
echo "<li>More</li>";
echo "</ul>";
}
The code in Laravel that I have is
foreach (range('a', 'z') as $i)
{
$list = DB::table('list')->where('name', 'LIKE', $i.'%')->limit(30)->get();
return view('pages.all', ['list' => $list]);
}
This code only gives data for names starting with alphabet "a" but won't proceed with the rest of the characters.
Store it on the array based on your search.
$list = array();
foreach (range('a', 'z') as $i) {
$list[$i] = DB::table('list')->where('name', 'LIKE', $i.'%')->limit(30)->get();
}
return view('pages.all', ['list' => $list]);
Customize your view, to showing the list against each character (a-z).
[Edit]
View file can be changed like below,
#foreach ($list as $keyI => $moredata)
<hr>
<h3>Author's Name Starting with "{{strtoupper($keyI)}}"</h3>
<ul class="tags-list">
#foreach ($moredata as $data)
<li>{{$data->name}}</li>
#endforeach
</ul>
#endforeach
I have order increment id like 100000096 and i want to get its invoice id, please help me to achieve this in magento, i have tried with
$incrementId = '100000096';
$order = Mage::getModel('sales/order')->load($incrementId);
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
}
But it returns an empty array.
You are using order increment id in load() function, you have to use loadByIncrementId().
Try to use this -
$orderid = '100000096'; // order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
if ($order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
}
}
echo "<pre>";
print_r($invIncrementIDs);
echo "</pre>";
Try this :
$orderIncrementId = '100000004'; // your order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
if ($order->hasInvoices()) {
$invIncrementId = array();
foreach ($order->getInvoiceCollection() as $invoice) {
$invoiceIncId[] = $invoice->getIncrementId();
}
}
echo "<pre>";print_r($invoiceIncId);echo '<br>';
In order to get Invoice id from Invoice incrementId
$incrementId = $invoiceIncId[0];
$invoive = Mage::getModel('sales/order_invoice')->loadByIncrementId($incrementId);
$invoiceId = $invoice->getId();
echo "<pre>";print_r($invoiceId);exit;
try this you will not regret
$order_id = "type_here_your_orderid";
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->setOrderFilter($order_id)
->load();
$invoice_id = $invoices->getData()[0]["increment_id"];
echo $invoice_id;
thats all.
I am working on magento 1.8 version.
I need to create custom script or extenson for import product from my custom csv file which have some different fields.
Any help would be much appriciated.
Thanks
Best way is to use OS Magmi, is much more faster than script an is simple to configure and periodical run.
http://sourceforge.net/projects/magmi/
You can also create a script which can you run.
you need to get data from csv file to memory
2 convert them to array
3 list array for each product
4 in foreach loop save or update product.
Some basic script:
<?php
$max_i = 20000; // maximal ammount
chdir(dirname(__FILE__)); /
//error_reporting(E_ALL | E_STRICT);
//ini_set("display_errors", 1);
ini_set("memory_limit","1024M");
ini_set('max_execution_time', 3600000);
date_default_timezone_set('Europe/Prague');
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
//////// SKU from CSV
$csv = file_get_contents ('yourcsvfile.csv');
function parse_csv ($csv_string, $delimiter = ";", $skip_empty_lines = true, $trim_fields = true)
{
$enc = preg_replace('/(?<!")""/', '!!Q!!', $csv_string);
$enc = preg_replace_callback(
'/"(.*?)"/s',
function ($field) {
return urlencode(utf8_encode($field[1]));
},
$enc
);
$lines = preg_split($skip_empty_lines ? ($trim_fields ? '/( *\R)+/s' : '/\R+/s') : '/\R/s', $enc);
return array_map(
function ($line) use ($delimiter, $trim_fields) {
$fields = $trim_fields ? array_map('trim', explode($delimiter, $line)) : explode($delimiter, $line);
return array_map(
function ($field) {
return str_replace('!!Q!!', '"', utf8_decode(urldecode($field)));
},
$fields
);
},
$lines
);
}
// list to array
$vystup = parse_csv($csv);
$seznamsku = array();
foreach ($vystup as $sku) {
array_push($seznamsku, $sku[0]);
unset($seznamsku[0]);
$seznamskufin = array_filter($seznamsku, 'strlen');
};
require("../../app/Mage.php");
echo "START ".date('h:i:s')."\n\n";
Mage::init();
// Set an Admin Session
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(1);
$session = Mage::getSingleton('admin/session');
$session->setUser($userModel);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
$pocet = 1;
foreach ($seznamskufin as $item) {
echo "\n number(".$pocet.")..sku(".$item.")..";
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$item);
if(is_object($product)) { //if is product exist in Magento
if (empty($product->getShortDescription())) { // if is value empty
$product->setShortDescription($ZboziDetail['info']); // write to magento
echo "..(importing)..";
}
else
{
echo "..(skipped).."; // exists
};
$product->save(); // save to magento
echo "..saved";
} else { echo ".(skiped)"; };
unset($item);
unset($product);
unset($ZboziDetail);
unset($product_imageUrl);
unset($newimage);
unset($e);
$pocet++;
};
$time_end = microtime_float();
$time = $time_end - $time_start;
echo " \n\n All done in ".$time." seconds.";
$logfile = fopen('log.txt', 'a');
fwrite($logfile, $seznamskufin);
fclose($logfile);
unset($response);
unset($vystup);
unset($seznamsku);
unset($seznamskufin);
?>
I think the easiest and safest way is to create a simple script (outside Magento) that transforms your csv to the csv structure used for import in System->Import/Export->Import.
TO see the format of the csv you need go to System->Import/Export->Export and export your current products.
I've got a loop that generates checkboxes, I have it working within the view, but I would like to move it into the controller and then pass the resulting string to the view. The problem is set_checkbox() doesn't seem to remember the values when it's placed in a controller. It does however seem to set the default value.
Edit: This is only an issue when validation fails and I want checkboxes to retain the users selections. Otherwise code is working as expected. I also have a validation rule set.
$languages_by_name = $this->event_model->get_spoken_languages_by_name();
// Generate array from model data for form_dropdown()
$i = 1;
$list_languages = '';
foreach ($languages_by_name as $row) {
$i == 1 ? $first = TRUE : $first = FALSE; // Check if this is the first radio and precheck it.
$list_languages .= '<label>' . form_checkbox('spokenLanguages[]', $row->event_spoken_id, set_checkbox('spokenLanguages', $row->event_spoken_id, $first)) . ' ' . $row->name . '</label> ';
$i++;
}
// Pass $list_languages to view
$this->data['list_languages'] = $list_languages;
Here's working code for the controller. There might be a more elegant way to do this.
// Generate array from model data for form_dropdown()
$i = 1;
$list_languages = '';
foreach ($languages_by_name as $row) {
// Check if there is post data
if(!$this->input->post('spokenLanguages')) {
// Set first element to checked
$i == 1 ? $selection = TRUE : $selection = FALSE; // Check if this is the first radio and precheck it.
} else {
// Check if this input is checked
if(in_array($row->event_spoken_id, $this->input->post('spokenLanguages'))) {
$selection = TRUE;
} else {
$selection = FALSE;
}
}
$list_languages .= '<label>' . form_checkbox('spokenLanguages[]', $row->event_spoken_id, set_checkbox('spokenLanguages', $row->event_spoken_id, $selection)) . ' ' . $row->name . '</label> ';
$i++;
}
// Pass $list_languages to view
$this->data['list_languages'] = $list_languages;
i'm trying to get my pricing extension working but i'm stucking at the tierprices.
If a visitor comes to my site i added a paramter to the cookie.
Example: http://www.foo.com/category/product.html?sidx=5
Now the visitor enters my site with the sidx parameter. Now the Observer: catalog_product_get_final_price sets the finalprice with the first tierprice of this Product of Customergroup 5.
The Customergroup of the visitor is still NOT LOGGED IN. Now i need the other tierprices of the Customergroup ID 5 without registering.
I have googled a lot to find a solution for that but i don't get the point.
Best Regards
boti
If you want to get the Tier prices for any product:
$product = Mage::getModel('catalog/product')->load(PRODUCT_ID_HERE);
$tierPrices = $product->getData('tier_price');
if (!is_array($tierPrices)) {
$tierPrices = array();
}
$result = array();
foreach ($tierPrices as $tierPrice) {
$row = array();
$row['customer_group_id'] = (empty($tierPrice['all_groups']) ? $tierPrice['cust_group'] : 'all' );
$row['website'] = ($tierPrice['website_id'] ? Mage::app()->getWebsite($tierPrice['website_id'])->getCode() : 'all');
$row['qty'] = $tierPrice['price_qty'];
$row['price'] = $tierPrice['price'];
$result[] = $row;
}
// $result now has an array of all tier prices...
// looking for cust_group = 5 would be trivial:
foreach ($tierPrices as $tierPrice) {
if($tierPrice['cust_group'] == 5) {
return $tierPrice; // this is what you want..
}
}