Question

I want to use code such as shown below to create my customer groups programmatically. However I have a requirement to set the Customer IDs to a specific ID numeric range. So if I create 100 customer groups their IDs need to start at 1000 and end with 1100. Is there a way to force the numbering of the ID like I want to do?

<?php
require_once 'app/Mage.php';
umask(0);
/* not Mage::run(); */
Mage::app('default');

//Create Customer Group 
Mage::getSingleton('customer/group')->setData(
     array('customer_group_code' => 'Partners','tax_class_id' => 5))
->save(); 
?>
Was it helpful?

Solution

I have try it too hard you need to by insert direct query

$write = Mage::getSingleton("core/resource")->getConnection("customer_group");
$query =
"INSERT INTO `customer_group`(`customer_group_id`, `customer_group_code`, `tax_class_id`) VALUES (:customer_group_id,:customer_group_code,:tax_class_id)";
$binds = array(
    'customer_group_id'      => 100,
    'customer_group_code'     => "Partners",
    'tax_class_id'   => 5,
);

$write->query($query, $binds);

OR

You need disabled key

$this->_isPkAutoIncrement = false;

http://watson-net.com/blog/magento-database-model-primary-keys/

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top