Last active
April 9, 2016 23:29
-
-
Save molotovbliss/b4915fea2ce9b9f60ee6 to your computer and use it in GitHub Desktop.
Magento Shell Script that Removes a specific attribute via CLI argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Removes a specific attribute. | |
* [email protected] | |
* | |
* Usage: php -f attribute-remove.php [attribute_name] | |
*/ | |
require_once 'abstract.php'; | |
ob_implicit_flush(true); | |
umask(0); | |
ini_set('display_errors', 1); | |
ini_set('memory_limit', '2048M'); | |
class CatalogSync_New_Shell extends Mage_Shell_Abstract | |
{ | |
/** | |
* Run script | |
* | |
*/ | |
public function run() | |
{ | |
Mage::setIsDeveloperMode(true); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
if ($this->getArg('help')) { | |
echo $this->usageHelp(); | |
} else { | |
foreach($this->_args as $attr => $value) {} | |
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection') | |
->setCodeFilter($attr) | |
->getFirstItem(); | |
if($attributeInfo->getAttributeId() === NULL) { die("Attribute not found. \n\r"); } | |
$setup = Mage::getResourceModel('catalog/setup', 'core_setup'); | |
try { | |
$setup->startSetup(); | |
$setup->removeAttribute('catalog_product', $attr); | |
$setup->endSetup(); | |
echo $attr . " attribute is removed. \n\r"; | |
} catch (Mage_Core_Exception $e) { | |
zend_debug::dump($e->getMessage()); | |
} | |
} | |
} | |
/** | |
* cURL call via POST to REST service & return XML | |
* | |
*/ | |
// Mage::getStoreConfig('verizonapi/catalog_sync_promotion_detail/url') | |
public function curlRequest($service_url, $method = "POST", $postData = array(), $returnXml = true) { | |
if(empty($service_url)) { | |
throw new Exception("No Service URL provided."); | |
return false; | |
} | |
$curl = curl_init($service_url); | |
if($method == "POST") { | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); | |
} | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$curl_response = curl_exec($curl); | |
curl_close($curl); | |
if($returnXml) { | |
return $xml = new SimpleXMLElement($curl_response); | |
} else { | |
return $curl_response; | |
} | |
} | |
/** | |
* Retrieve Usage Help Message | |
* | |
*/ | |
public function usageHelp() | |
{ | |
return <<<USAGE | |
Process a promotionId from Catalog Sync | |
help This help | |
USAGE; | |
} | |
} | |
$shell = new CatalogSync_New_Shell(); | |
$shell->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment