1

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(); 
?>

1 Answer 1

1

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/

1
  • That works! I vote you up but my reputation is low. Commented Sep 18, 2014 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.