Day: April 7, 2010

  • Customise Magento order number

    After I put a lot of test orders into Magento, now I want to delete them for a clean start. I also want to shorten the length of order number, and the order number from various stores share the global increment. I want the similar settings on Matgento invoice, shipment, and creditmemo.

    I have concluded these steps after some trials and errors.

    Firstly, empty orders, invoices, shipments, and creditmemo by executing mysql commands:

    
    TRUNCATE `magento_sales_flat_order_item`;
    TRUNCATE `magento_sales_flat_quote`;
    TRUNCATE `magento_sales_flat_quote_address`;
    TRUNCATE `magento_sales_flat_quote_address_item`;
    TRUNCATE `magento_sales_flat_quote_item`;
    TRUNCATE `magento_sales_flat_quote_item_option`;
    TRUNCATE `magento_sales_flat_quote_payment`;
    TRUNCATE `magento_sales_flat_quote_shipping_rate`;
    TRUNCATE `magento_sales_invoiced_aggregated`;
    TRUNCATE `magento_sales_invoiced_aggregated_order`;
    TRUNCATE `magento_sales_order`;
    TRUNCATE `magento_sales_order_aggregated_created`;
    TRUNCATE `magento_sales_order_datetime`;
    TRUNCATE `magento_sales_order_decimal`;
    TRUNCATE `magento_sales_order_entity`;
    TRUNCATE `magento_sales_order_entity_datetime`;
    TRUNCATE `magento_sales_order_entity_decimal`;
    TRUNCATE `magento_sales_order_entity_int`;
    TRUNCATE `magento_sales_order_entity_text`;
    TRUNCATE `magento_sales_order_entity_varchar`;
    TRUNCATE `magento_sales_order_int`;
    TRUNCATE `magento_sales_order_tax`;
    TRUNCATE `magento_sales_order_text`;
    TRUNCATE `magento_sales_order_varchar`;
    TRUNCATE `magento_sales_payment_transaction`;
    TRUNCATE `magento_sales_refunded_aggregated`;
    TRUNCATE `magento_sales_refunded_aggregated_order`;
    TRUNCATE `magento_sales_shipping_aggregated`;
    TRUNCATE `magento_sales_shipping_aggregated_order`;
    

    Then, go to table magento_eav_entity_type, find entity order, invoice, shipment, creditmemo, change increment_per_store to or not to share global increment (default is 1 which means each store has its own increment), change increment_pad_length to shorten or longer numbers (increment_pad_length does not include prefix: 1 digit by default).

    Then, empty table magento_eav_entity_store by executing:

    
    TRUNCATE `magento_eav_entity_store`;
    

    With an empty table, Magento generate default increment_prefix which is store id (with global increment setting, it is 0), and increment starts from 0.

    I want the first order, invoice, shipment, creditmemo number look like 100001, I set magento_eav_entity_type.increment_pad_length at 5, and insert 4 records into magento_eav_entity_store.

    Customise order, invoice, shipment, creditmemo number in Magento
    Customise order, invoice, shipment, creditmemo number in Magento

    And that’s it.

    2010年6月22日更新:我想提醒一下,光有几个 store_id = 0 的记录不够保险。因为几天后,我发现每个 storeview 都有了各自的记录,显然 storeview 的记录优先于 default (store_id = 0)。increment_prefix 默认为 store_id,这让每个 storeview 有了不同的前缀,与我初衷(所有 storeview 统一使用 “1” 为前缀)相悖。我不清楚后来这些自动添加的记录是由什么事件引发的。既然 increment_prefix 被改了,我只好接受这个事实,改来改后会让后台订单号看起来没有连续性。

    More data added to eav_entity_store
    More data added to eav_entity_store