I want multiselect dropdown list, country name followed by country flag.
and for now, I implemented multiselect dropdown using:
http://davidstutz.github.io/bootstrap-multiselect/
<h4>Employee should be from Country</h4>
<?php
$html6= "";
$qry = "SELECT * FROM jb_country";
$runQuery = mysql_query($qry);
$html6 .= "<select name='pref_emp_country[]' class='form-control' id='my-select' multiple='multiple'>";
while ($sub_cat = mysql_fetch_assoc($runQuery)) {
$html6 .= "<option value=" .$sub_cat['id']. ">" .$sub_cat['name']. "</option>";
} echo $html6 .= "</select>";
?>
this is my code using bootstrap-multiselect.
multiselect countries are working fine. but now i want to add flags of each country before country name.
I want to know how can i do this!!
Thanks for time saving help
Related
I need to retrieve an order from Magento by its id.
How do I load a specific order by id?
so far i have tried this:
<?php
$orderNumber = 145000013;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
// get order item collection
$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item){
$product_id = $item->product_id;
$product_sku = $item->sku;
$product_name = $item->getName();
$_product = Mage::getModel('catalog/product')->load($product_id);
$cats = $_product->getCategoryIds();
$category_id = $cats[0];
$category = Mage::getModel('catalog/category')->load($category_id);
$category_name = $category->getName();
echo "orderNumber=".$orderNumber."<br/>";
echo "orderValue=".$orderValue."<br/>";
echo "product_name=".$product_name."<br/>";
echo "product_id=".$product_id."<br/>";
echo "product_sku=".$product_sku."<br/>";
echo "category_id=".$category_id."<br/>";
echo "category_name=".$category_name."<br/><br/>";
}
?>
it works fine for static order...but i want to get dynamically.
First you need to create a form that post to a custom controller that include your code as above
Then update your code with
$orderNumber = $this->getRequest()->getParams('field_name');;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
See this How to get post data variables after submition a form in magento
For this you need to follow the following steps:
Create a form to search for order details
You can add your custom code on your desired location.
Then you need to submit your search form on the URL where you want to show the order details. there must be one template file associated with the form submitted URL.
In the Template file you can use your above specified code. but as you want to make it dynamic need to fetch submitted order number using the following way:
$orderId = $this->getRequest()->getParam('search_orderid'); //search_orderid is name of search box
Search Form:
<form id="orderSerchForm" method="post" action="<?php echo $this->getUrl('sales/order/history') ?>">
<input type="text" name="search_order" id="search_order" placeholder="Enter Order ID" />
<input type="submit" />
</form>
i am trying to built category tree for the categories and sub categories in custom admin module, if possible to override the default category tree present in edit tab of product.
Below is the code which i am working, it is able to build category tree but it lack the checkbox ability. any sugestion would be appreciated
<?php
$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
function get_categories($categories) {
$array= '<ul>';
foreach($categories as $category) {
$cat = Mage::getModel('catalog/category')->load($category->getId());
$count = $cat->getProductCount();
$array .= '<li>'.
'<a href="' . Mage::getUrl($cat->getUrlPath()). '">' .
$category->getName() . "(".$count.")</a>\n";
if($category->hasChildren()) {
$children = Mage::getModel('catalog/category')->getCategories($category->getId());
$array .= get_categories($children);
}
$array .= '</li>';
}
return $array . '</ul>';
}
echo get_categories($categories); ?>
Please clarify your question as it's bad idea to override core functionality because same function is used by different modules instead you can check functionality of these
app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
and then reflect these to your template files
The goal should be following:
I have an edit view with a custom field (dropdown) that depends on another table. There I can choose from a list of adresses (the second table) to save the id of the data row. I started with this:
Custom field code:
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
JHTML::_('behavior.modal');
class JFormFieldInvoiceAdress extends JFormFieldList
{
protected $type = 'invoiceadress';
protected function getInput() {
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id,zip,city,adress');
$query->from('#__pb_invoiceadresses');
$db->setQuery((string)$query);
$types = $db->loadObjectList();
$options = array();
foreach($types as $type) {
$options[] = JHTML::_('select.option', $type->id, $type->zip . " " . $type->city . ", " .$type->adress);
}
$dropdown = JHTML::_('select.genericlist', $options, $this->name, 'class="inputbox"', 'value', 'text', $this->value);
$link = 'index.php?option=com_mycomponent&view=invoiceadresseedit&layout=edit&id=0';
$dropdown .= "<a href=\"" . JRoute::_($link) . "\" class=\"modal\" rel=\"{handler: 'iframe', size: {x: 875, y: 550}, onClose: function() {}}\" >Neue Adresse</a>";
return $dropdown ;
}
}
This works so far but I have to update the content of the dropdown on closing this modal window and not getting the list view of the invoiceadresses in the modal window.
My second attempt was to add 'tmpl=component' in the link but then I don't have a save button. I have no idea how to accomplish that. Anyone have already solved this?
Found the solution and I am answering it for the next person who comes along with the same question.
Call the edit view with this link:
$link = 'index.php?option=com_mycomponent&view=invoiceadresseedit&layout=edit&id=0&tmpl=component';
This will display only the form without the rest of the administration gui and toolbar.
Add a save button to your edit form like this:
<input class="button" type="submit" value="<?php echo JText::_('SAVE');?>" onClick="window.parent.location.reload();" />
And thats it. The data will be saved and after this the modal windows closes and the current page reloads, the dropdown will be updated with the new data.
1) I have a basic Joomla form that has three drop downs for Country, Town and Shop
2) I need to get the dropdown list based on the dropdown list provided above.
I have achieved to get the data from database and create drop down by coding in registration.xml in
usercomponent
What needs to be achieved:
I am trying to create dynamic drop downs based on the above data selected in the dropdown.
Please help me I am working hard for this I couldn't find the solution and code break through
I've created a basic non-Joomla example of this here
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
<?php
$username = "USERNAME";
$password = "PASSWORD";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("DATABASE", $dbhandle) or die("Could not select examples");
$result = mysql_query("SELECT * FROM `values`");
$values=array();
$counter=0;
while($row = mysql_fetch_array($result))
{
$values[$counter]=$row{'country'};
$counter++;
}
mysql_close($con);
?>
<?php
$i=0;
$countries=array();
foreach($values as $value) {
$exists=false;
if(count($countries)>0) {
foreach($countries as $something) {
if($something==$value) {
$exists=true;
}
}
}
if($exists==false) {
$countries[$i]=$value;
$i++;
}
}
?>
<select id="first-choice">
<option selected value="base">Please Select</option>
<?php
$k=0;
while($k<count($countries)) {
echo "<option value='".$countries[$k]."'>" . $countries[$k] . "</option>";
$k++;
}
?>
</select>
<br />
<select id="second-choice">
<option>Please choose from above</option>
</select>
<br />
<select id="third-choice">
<option>Please choose from above</option>
</select>
<script type="text/javascript">
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?country=" + $("#first-choice").val());
});
$("#second-choice").change(function() {
$("#third-choice").load("getter.php?town=" + $("#second-choice").val());
});
</script>
</body>
</html>
File called getter.php
<?php
$username = "USERNAME";
$password = "PASSWORD";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("DATABASE", $dbhandle) or die("Could not select examples");
if($_GET['country']) {
$countries = mysql_real_escape_string($_GET['country']);
$query = "SELECT * FROM `values` WHERE country='".$countries."'";
$result = mysql_query($query);
$values=array();
$i=0;
while($row = mysql_fetch_array($result))
{
$values[$i]=$row{'town'};
$i++;
}
$i=0;
$towns=array();
foreach($values as $value) {
$exists=false;
if(count($towns)>0) {
foreach($towns as $town) {
if($town==$value) {
$exists=true;
}
}
}
if($exists==false) {
$towns[$i]=$value;
$i++;
}
}
$k=0;
echo "<option selected value='base'>Please Select an Option</option>";
while ($k<count($towns)) {
echo "<option value=".$towns[$k].">" . $towns[$k] . "</option>";
$k++;
}
} elseif ($_GET['town']) {
$town = mysql_real_escape_string($_GET['town']);
$query = "SELECT * FROM `values` WHERE town='".$town."'";
$result = mysql_query($query);
echo "<option selected value='base'>Please Select an Option</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option>" . $row{'shop'} . "</option>";
}
}
?>
Based on the tutorial here. To Joomla this up. You will need to put the getter.php file into the model and call it through JSON (with a suitable controller). Remember to replace all visable text with JText - so it can be made with a language file. You also need to add the jquery into the header with JDocument::addScript or if your using Joomla 3.0 then JHtml::_('jquery.framework'); suffices. Also you must connect to the database through Joomla using JFactory::getDBO
I've put a basic example of this here.
Some notes: You may wish to call a specific version of JQuery as its constantly being updated. 1.9.0 works fine - but I don't know what will be hosted on that link when 2.0.0 comes out and what browser compatibility will be included.
This assumes a database structure of just
id country town shop. of course I doubt your database schemes are that easy. So remember to adapt this as necessary.
Hopefully this should start you going :)
I am new to Joomla. I have created website using Joomla 2.5. I have login page which is default Joomla user management system.
What I want is display all user data in a tabular format. How could I do the same?
Edit 1
I can see the users with below steps.
Go to administrator page as www.site.com/administrator.
Login as admin
Click Users >> User Manager menu and then I can see the list of users.
I want to print same list, however on the website and not on administrator site at backend.
you can do this run the query on your page where you want to show user list. you can fetch all users table field with $row object.
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__users" ;
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
echo $row->id.'|'.$row->username.'|'.$row->email;
}
Edit 1
Below is what I used.
Installed extension Flexi Custom Code.
Create module using this, add above code in it and appear that menu on the menu where you want to display.
You'll need some sort of component for this. This user profile component for example (N.B. Using this as my example as a work colleague once used it - not as customizable as I would have liked - but probably OK for what your after. I'm sure there are more as there's an entire member list category.)
Just install one of them and choose what you want to show. Add it to a menu like any other component and off you go!
Two possible solutions
Use the User Profile Component available in JED
Enable "User - Contact Creator" plugin to create a Contact profile for each new user and then use the Joomla built-in Menu Item to list all contacts
// my example with opt-groups, preselected user and better user-ids
function getUserList ($user_id) {
$db = JFactory::getDBO ();
$db->setQuery ("SELECT id, username, usertype FROM ' . $db->quoteName ('#__users') . ' ORDER BY usertype,username ASC");
$rows = $db->loadAssocList ();
static $opt_tag;
$list = '<option value="0">' . JText::_ ('SELECTION') . '</option>';
foreach ($rows as $row) {
if (empty ($opt_tag) || $opt_tag != $row['usertype']) {
$list .= '<optgroup label="' . $row['usertype'] . '">';
$opt_tag = $row['usertype'];
}
if ($row['id'] < 10) {
$id = '000' . $row['id'];
}
elseif ($row['id'] < 100) {
$id = '00' . $row['id'];
}
elseif ($row['id'] < 1000) {
$id = '0' . $row['id'];
}
$list .= '<option value="' . $row['id'] . '"' . (((int) $user_id == $row['id']) ? ' selected="SELECTED"' : '') . '>' . $id . ' - ' . $row['username'] . '</option>';
if (empty ($opt_tag) || $opt_tag != $row['usertype']) {
$list .= '</optgroup>';
}
}
return $list;
}