admin – Use the default of the product view backoffice magento

I have a problem in Magento 1.7 when I try to verify the "default usage" in an attribute of the product.

I would like to programmatically check the "use default value" checkbox when the global special_price is the same as the store specific special_price.

My problem is that all the "global values" will be empty when I use my script.

Thanks if someone can help me.

Cordially.

Here my script:

                    $ oGlobalProduct = Mage :: getModel (& # 39; catalog / product & # 39;) -> setStoreId (0) -> load ($ iProductId);
$ oProduct = $ oProductModel-> setStoreId ($ iStoreId) -> load ($ iProductId);
// standard price is a custom attribute
if ($ oGlobalProduct-> getSpecialPrice () == $ oProduct-> getStandardPrice ())
{
$ setId = $ oProduct-> getAttributeSetId ();

$ aAttribute = array ();

yes ($ setId)
{
// get all the attributes of the product group
$ groupCollection = Mage :: getResourceModel (& # 39; eav / entity_attribute_group_collection & # 39;)
-> setAttributeSetFilter ($ setId)
-> setSortOrder ()
-> load ();

foreach ($ groupCollection as $ group)
{
$ attributes = $ oProduct-> getAttributes ($ group-> getId (), true);

foreach ($ attributes like $ key => $ attribute)
{
if (! $ attribute-> getIsVisible ())
{
unset ($ attributes[$key]);
}
else {
$ attribute[$attribute->getId()] = array (
& # 39; attribute_code & # 39; => $ attribute-> getAttributeCode (),
& # 39; use_default & # 39; => $ oProduct-> getExistsStoreValueFlag ($ attribute-> getAttributeCode ()),
& # 39; global_value & # 39; => $ oGlobalProduct-> getData ($ attribute-> getAttributeCode ()),
& # 39; store_value & # 39; => $ oProduct-> getData ($ attribute-> getAttributeCode ())
);
}
try{

yes ($ aAttribute[$attribute->getId()]['global_value']    == $ attribute[$attribute->getId()]['store_value'])
{
$ oProduct-> setStoreId ($ iStoreId)
-> setData ($ attribute-> getAttributeCode (), false);
}
}
capture (Exception $ e)
{
echo $ e-> getMessage ();
continue;
}
}
}
$ oProduct-> save ();
}
}

View of the product before the script (global):

enter the description of the image here

View of the product before the script (store):

enter the description of the image here

View of the product after the script (global)

enter the description of the image here

View of the product after the script (store)

enter the description of the image here