Custom Start Number for Order Numbers in Magento 1.5 - magento

How do I customise the starting number for orders, invoices etc in Magento 1.5?

From magento's forum:
by LindyKyaw (Magento Team Member), changing start number (through sql query):
There is a table in the database which stored increment id of order.
It is called “eav_entity_store” table.
You can check which entity type id belongs to which entity by looking at
eav_entity_type table.
You can run following query to update last increment id for the order.
update eav_entity_store
inner join eav_entity_type on eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
set eav_entity_store.increment_last_id=3001
where eav_entity_type.entity_type_code='order';
by FOOMAN (active contributor), changing start number (through db management tool) and removing "0"s at the beginning:
With a tool like phpmyadmin look at your database. In the table
eav_entity_type you will find all entity types listed. The one of interest to
change where the order number starts is order sales/order. Remember the
entity_type_id (in my install it is 11). To remove the leading zeros
(padding) set increment_pad_length to 1.
Next go to the table eav_entity_store. Look up the entity_type_id. Now you
can change the value of increment_prefix and increment_last_id. If you wanted to
have your next orderId to be 15000 set increment_last_id to 14999 and
increment_prefix to 0.
Additionally you need to make a copy of this file
/app/code/core/Mage/Eav/Model/Entity/Increment/Abstract.php
to
/app/code/local/Mage/Eav/Model/Entity/Increment/Abstract.php
public function getPadLength()
{
$padLength = $this->getData('pad_length');
if (empty($padLength)) {
$padLength = 0;
}
return $padLength;
}
...
public function format($id)
{
$result= str_pad((string)$id, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT);
return $result;
} Hope That Helps

Actually with the newer versions (and probably in 1.5 as well), there is an easier way to change it. In PHPMyAdmin, or your mysql client, go to the eav_entity_type table. Locate the table in the entity_type_code column (probably order), and set the increment_pad_length to be whatever you would like, as well as the increment_pad_char.
Then you don't have to rewrite core code - a win-win.
JMax

Magento Order No
It's simple....
go to phpmyadmin
select your datbase and then select the table "eav_entity_store"
in this table, change the increment_last_id (for example, I have set 3456767 in my table)
after that I create a new order. Now my orders start from the number 346768

There is actually a good extension for accomplish this task.
It allows you to customize the order ID in a lot of different way:
for example you can use a combination of:
number like year,month,,day,hr,sec,
use a custom counter (you can decide the starting number )
a combination of all above methods
add some custom string in any position of the order ID
This is the ext. on Magento connect:
http://www.magentocommerce.com/magento-connect/custom-order-id-8210.html
I personally tried it and it very good ( works fine with all my payment methods and I had no issue at all )

Related

Power Query Create conditional new column

I am having a little challenge.
In the attached sample data you can see that for a single AMI two different Product names exist.I do know that when that occurs only Linux/UNIX is correct. I would like to create a new column that will be looking for each AMI if it has 2 distinct string values then the new column to always be Linux/UNIX.
İmage
For the time being, i am using in power query text.contains and i specify manually those AMIs but this is not so productive. I am not aware if i can run loops with power query.
Thanks in advance for your help.
Filippos
Group the data on Ami and count Product names; merge results back into table; add custom column that checks the new column like =if [newcolumn] >1 then "Linux" else null
Another possibility. Sort table. Click to select product and type column then right click remove duplicates, which should only keep first instance. If you sorted correctly, then all the non Linuxes will be removed

Magento - Mageworx Extended Orders - rearrange columns

I have more or less inherited a Magento site, which seems to be using the Mageworx Extended Orders extension for the order grid in the admin area.
Client would like the columns to be rearranged, eg, move Email over beside Voucher. In the System Config you can select columns but there doesn't seem to be any way of ordering them. I have searched through the code and tried editing code\local\MageWorx\Adminhtml\Block\Orderspro\Sales\Order\Grid.php to no avail.
I also looked in the database but couldn't find a table which might have the columns selected so that I could order them.
Thanks.
As it happens it was that file, MageWorx\Adminhtml\Block\Orderspro\Sales\Order\Grid.php, that I needed to edit. I took out the loop and just commented out the fields I didn't want showing and put the rest in the required order
You can change it in the file: app/code/local/MageWorx/OrdersPro/Block/Adminhtml/Sales/Order/Grid.php in the _prepareColumns() method.
At the moment changing columns order is quite a challenge and can be done only this way:
$listColumns = $helper->getGridColumns();
$listColumnsChanged = $listColumns; // create a copy of $listColumns
$listColumnsChanged[0] = $listColumns[3];
$listColumnsChanged[3] = $listColumns[0]; // interchange the columns that have id 3 and 0
var_dump($listColumns); // var_dump will let you learn ID of the column you need
foreach ($listColumnsChanged as $column) { // change foreach for getting to $listColumnsChanged

Access 2013: Check if a value is present in another table

I've just discovered Access, having always been an Excel/VBA man... and now I've hit a roadblock!
I'm building an inventory database for my employer. I have 2 tables, one containing one column of 'stockID's (lets call this table 'tblWarehouse'), and another containing two columns: a column of 'orderID's and a column of 'stockID's (lets call this table 'tblOrders'). (For the sake of this question, lets disregard things like quantity, price etc)
We don't keep all the goods we sell in our own warehouse, some are sourced directly from the manufacturer to the customer, which means that not all tblOrders!stockID will be present in the list tblWarehouse!stockID. I need to find out when this is the case!
I want to create a third column in tblOrders containing a dummy variable = 1 if that particular item is in our warehouse. In other words, I want to create a calculated column = 1 if tblOrders!stockID can be found in tblWarehouse!stockID. Can this be done?
I've found that I can't reference another table directly, so I've been trying my hand at queries, user defined functions and relationships, but to no avail. I've also been having trouble with the Access-lingo and veritable forest of different places to input seemingly the same expressions... so please, if u have an answer for me, be sure to specify where things are located!
Much obliged!!
If you are linking the two tables in a query using an inner join, only order records having at least one stock entry will be included in the result. In order to include those with no stock entry at all, create a left outer join.
SELECT O.OrderID, IIf(IsNull(MAX(W.StockID)), 0, 1) AS StockAvailable
FROM
tblOrder O
LEFT JOIN tblWarehouse W
ON O.StockID = W.StockID
GROUP BY O.OrderID
You can also determin the join type in the query designer by right clicking a relation line and selecting "Join Properties" and then select "Include ALL records from tblOrders ...". You can make a grouping query by clicking the big Sigma-symbol in the symbol list.

query magento limit + order by rand()

function getIdModelsSliderJuwels(){
$collection = Mage::getModel("catalog/product")->getCollection();
$collection->addAttributeToFilter("attribute_set_id", 27);
$collection->addAttributeToSelect('modellijnen');
// $collection->setRandomOrder();
// $collection->getSelect()->limit( 5 );
return $collection;
}
Hi there,
I'd like to know how to set a limit to your query running in Magento because
$collection->getSelect()->limit( 5 ); doesn't work.
Also how to select randomly, $collection->setRandomOrder(); also doesn't work.
txs.
setRandomOrder does not work for collections of products, only for related products. You'll have to add it yourself with this code:
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
A shortcut for setting both page size and number at the same time is:
$collection->setPage($pageNum, $pageSize);
As clockworkgeek said, use the $collection->getSelect()->order(...) method to randomize the order. To limit it to just $n number of items you can also use
$collection->getSelect()->limit($n);
try to use
$collection->setPageSize(5)->setCurPage(1);
Using ORDER BY RAND() to return a list of items in a random order will require a full table scan and sort. It can negatively affect performance on large number of rows in the table.
There are several alternative solutions possible of how to optimize this query. Magento provides a native solution for that.
The orderRand() method of Varien_Db_Select and the database adapter allows to specify a random order and leverage index for ORDER BY. Specify a name of some integer indexed column to be used in the ORDER BY clause, for example:
$collection->getSelect()->orderRand('main_table.entity_id');
See Varien_Db_Adapter_Pdo_Mysql::orderRand() for implementation details.

MySQL get rows, but for any matching get the latest version

I'm developing a CMS, and implementing versioning by adding a new entry to the database with the current timestamp.
My table is set up as follows:
id | page | section | timestamp | content
"Page" is the page being accessed, which is either the path to the page ($page_name below), or '/' (to indicate 'global' fields).
"Section" is the section of the page being edited.
I want to be able to select all rows for a given page, but each section should only be selected once, the one with the latest timestamp being selected.
I've tried using the following CodeIgniter Active Record code:
$this->db->select('DISTINCT(section), content');
$this->db->where_in('page', array('/', $page_name));
$this->db->order_by('timestamp', 'desc');
$query = $this->db->get('cms_content');
Which is producing the following SQL:
SELECT DISTINCT(section), `content`
FROM (`cms_content`)
WHERE `page` IN ('/', 'index.html')
AND `enabled` = 1
ORDER BY `timestamp` desc
Which is returning both test rows (rows have all same fields except id, timestamp and content).
Any ideas as to where I'm going wrong?
Thanks!
Your mistake is thinking that DISTINCT applies only to section - an easy mistake to make as the parentheses are misleading here. In fact the DISTINCT applies to the entire row whether or not you have parentheses. It is therefore best to omit the parentheses to avoid confusion.
Your problem is a classic 'max per group' problem. There are many, many ways to write this query and it is probably one of the most popular SQL questions on this site so you can search Stack Overflow to find ways to solve it. One way to get you started is to only select rows which hold the maximum timestamp for that section:
SELECT section, content
FROM cms_content T1
WHERE page IN ('/', 'index.html')
AND enabled = 1
AND timestamp = (
SELECT MAX(timestamp)
FROM cms_content T2
WHERE page IN ('/', 'index.html')
AND enabled = 1
AND T1.section = T2.section
)
I'm sorry but I do not know how to convert this SQL code into CodeIgniter Active Record. If another user more familiar with Active Record wishes to use this as a starting point for their own answer, they are welcome.
DISTINCT is for all columns selected, and because "content" differs you will get two different rows.
You only want to order by timestamp and limit 1 because you always want the latest.
But may I suggest that you keep a cross reference to the "active" page? That way, you are able to revert to a previous revision without dumping the new ones.
Meaning:
page
----
id
info
active_page_id
page_revisions
--------------
id
page_id
content
timestamp
...
Meaning, you have one-to-many between page <-> page_revisions, aswell as a one-to-one between page and page_revisions to keep track of the "current" revision. With this approach you are able to just join in the active revision.
This will do the job in Codeigniter, without temporary tables:
$this->db->query( "SELECT *
FROM cms_content AS c1
LEFT JOIN cms_content AS c2
ON c1.page=c2.page
AND c1.section=c2.section
AND c1.timestamp < c2.timestamp
WHERE c2.timestamp IS NULL AND page=?", $page );

Resources