Last active
August 29, 2015 14:01
-
-
Save martisj/cfbdb867d753803276f2 to your computer and use it in GitHub Desktop.
adding attribute to set
This file contains 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 | |
// die('dont do this now'); | |
/** | |
* Helper methods | |
*/ | |
function reindexAllIndices() { | |
for ($i = 1; $i <= 9; $i++) { | |
$process = Mage::getModel('index/process')->load($i); | |
$process->reindexAll(); | |
} | |
} | |
/** | |
* Adding New Board Category Attributes and Attribute Sets | |
*/ | |
Mage::Log($this); | |
$installer = $this; | |
// $installer = new Mage_Eav_Model_Entity_Setup('core_setup'); | |
// $installer = Mage::getResourceModel('catalog/setup', 'catalog_setup'); | |
$installer->startSetup(); | |
// Attributes that use a dropdown box with options: | |
$selectAttributes = array( | |
'velgmerke' => array( | |
'label' => 'Velg Merke', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Rusty'), | |
'option1' => array('Channel Islands') | |
) | |
) | |
), | |
'brettbrand' => array( | |
'label' => 'Brett Brand', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Rusty'), | |
'option1' => array('Haydenshapes'), | |
'option2' => array('7S'), | |
'option3' => array('JS Industries') | |
) | |
) | |
), | |
'length' => array( | |
'label' => 'Lengde', | |
'options' => array( | |
'value' => array( | |
'option0' => array("6'6\""), | |
'option1' => array("6'5\""), | |
'option2' => array("6'4\""), | |
'option3' => array("6'3\""), | |
'option4' => array("6'2\""), | |
'option5' => array("6'1\""), | |
'option6' => array("6'0\""), | |
'option7' => array("5'11\""), | |
'option8' => array("5'10\""), | |
'option9' => array("5'9\""), | |
'option10' => array("5'8\""), | |
'option11' => array("5'7\""), | |
'option12' => array("5'6\"") | |
) | |
) | |
), | |
'bredde' => array( | |
'label' => 'Bredde', | |
'options' => array( | |
'value' => array( | |
'option0' => array("20'87\""), | |
'option1' => array("20'75\""), | |
'option2' => array("20'50\""), | |
'option3' => array("20'25\""), | |
'option4' => array("20'00\""), | |
'option5' => array("19'75\""), | |
'option6' => array("19'62\""), | |
'option7' => array("19'50\""), | |
'option8' => array("19'37\""), | |
'option9' => array("19'25\""), | |
'option10' => array("19'13\""), | |
'option11' => array("19'00\"") | |
) | |
) | |
), | |
'tykkelse' => array( | |
'label' => 'Tykkelse', | |
'options' => array( | |
'value' => array( | |
'option0' => array('2.65'), | |
'option1' => array('2.60'), | |
'option2' => array('2.55'), | |
'option3' => array('2.51'), | |
'option4' => array('2.50'), | |
'option5' => array('2.45'), | |
'option6' => array('2.40'), | |
'option7' => array('2.35'), | |
'option8' => array('2.31') | |
) | |
) | |
), | |
'volum' => array( | |
'label' => 'Volum', | |
'options' => array( | |
'value' => array( | |
'option0' => array('39.8'), | |
'option1' => array('39.0'), | |
'option2' => array('38.3'), | |
'option3' => array('36.7'), | |
'option4' => array('35.2'), | |
'option5' => array('33.8'), | |
'option6' => array('32.5'), | |
'option7' => array('31.2'), | |
'option8' => array('30.0'), | |
'option9' => array('29.5'), | |
'option10' => array('28.0'), | |
'option11' => array('27.5'), | |
'option12' => array('26.0') | |
) | |
) | |
), | |
'brettsize' => array( | |
'label' => 'Size', | |
'options' => array( | |
'value' => array( | |
'option0' => array("6'0"), | |
'option1' => array("5'11"), | |
'option2' => array("5'10"), | |
'option3' => array("5'9"), | |
'option4' => array("5'8"), | |
'option5' => array("5'7"), | |
'option6' => array("5'6") | |
) | |
) | |
), | |
'idealwave' => array( | |
'label' => 'Ideal wave range', | |
'options' => array( | |
'value' => array( | |
'option0' => array("2'-12'") | |
) | |
) | |
), | |
'velgbrettype' => array( | |
'label' => 'Velg Brettype', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Hybrid'), | |
'option1' => array('Shortboard') | |
) | |
) | |
), | |
'padbrand' => array( | |
'label' => 'Pad Brand', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Gorilla') | |
) | |
) | |
), | |
'finsbrand' => array( | |
'label' => 'Fins Brand', | |
'options' => array( | |
'value' => array( | |
'option0' => array('FCS') | |
) | |
) | |
), | |
'leashbrand' => array( | |
'label' => 'Leash Brand', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Gorilla') | |
) | |
) | |
), | |
'waxbrand' => array( | |
'label' => 'Wax Brand', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Gorilla') | |
) | |
) | |
), | |
'leashmm' => array( | |
'label' => 'Leash MM', | |
'options' => array( | |
'value' => array( | |
'option0' => array('9’ (9mm)'), | |
'option1' => array('8’ (8mm)'), | |
'option2' => array('7’ (7mm)') | |
) | |
) | |
), | |
'temperature' => array( | |
'label' => 'Temperature', | |
'options' => array( | |
'value' => array( | |
'option0' => array('14° < 0°') | |
) | |
) | |
), | |
'padsize' => array( | |
'label' => 'Pad Size', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Extra Large'), | |
'option1' => array('Large'), | |
'option2' => array('Medium'), | |
'option3' => array('Small') | |
) | |
) | |
), | |
'finssize' => array( | |
'label' => 'Fins Size', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Extra Large'), | |
'option1' => array('Large'), | |
'option2' => array('Medium'), | |
'option3' => array('Small') | |
) | |
) | |
), | |
'leashessize' => array( | |
'label' => 'Leashes Size', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Extra Large'), | |
'option1' => array('Large'), | |
'option2' => array('Medium'), | |
'option3' => array('Small') | |
) | |
) | |
), | |
'waxsize' => array( | |
'label' => 'Wax Size', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Extra Large'), | |
'option1' => array('Large'), | |
'option2' => array('Medium'), | |
'option3' => array('Small') | |
) | |
) | |
) | |
); | |
foreach ($selectAttributes as $tag => $details) { | |
$installer->addAttribute('catalog_product', $tag, array( | |
'label' => $details['label'], | |
'input' => 'select', | |
'type' => 'int', | |
'backend' => '', | |
'frontend' => '', | |
'source' => 'eav/entity_attribute_source_table', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, | |
'visible' => true, | |
'required' => false, | |
'user_defined' => true, | |
'searchable' => false, | |
'filterable' => true, | |
'comparable' => false, | |
'option' => $details['options'], | |
'visible_on_front' => false, | |
'visible_in_advanced_search' => false, | |
'unique' => false | |
)); | |
} | |
// Attributes that use a multiselect box: | |
$multiselectAttributes = array( | |
'pieces' => array( | |
'label' => 'Pieces', | |
'options' => array( | |
'value' => array( | |
'option0' => array('1 piece'), | |
'option1' => array('2 pieces'), | |
'option2' => array('3 pieces') | |
) | |
) | |
), | |
'set' => array( | |
'label' => 'Set', | |
'options' => array( | |
'value' => array( | |
'option0' => array('Quad Set'), | |
'option1' => array('Tri Set') | |
) | |
) | |
) | |
); | |
foreach ($multiselectAttributes as $tag => $details) { | |
$installer->addAttribute('catalog_product', $tag, array( | |
'label' => $details['label'], | |
'input' => 'multiselect', | |
'type' => 'varchar', | |
'backend' => 'eav/entity_attribute_backend_array', | |
'frontend' => '', | |
'source' => 'eav/entity_attribute_source_table', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, | |
'visible' => true, | |
'required' => false, | |
'user_defined' => true, | |
'searchable' => false, | |
'filterable' => true, | |
'comparable' => false, | |
'option' => $details['options'], | |
'visible_on_front' => false, | |
'visible_in_advanced_search' => false, | |
'unique' => false | |
)); | |
} | |
// Attributes that use a textbox: | |
$textAttributes = array( | |
'teaser' => array( | |
'label' => 'Teaser' | |
), | |
'productvideo' => array( | |
'label' => 'Produkt Video' | |
) | |
); | |
foreach ($textAttributes as $tag => $details) { | |
$installer->addAttribute('catalog_product', $tag, array( | |
'label' => $details['label'], | |
'input' => 'text', | |
'type' => 'text', | |
'backend' => '', | |
'frontend' => '', | |
'source' => 'eav/entity_attribute_source_table', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, | |
'group' => isset($details['group']) ? $details['group'] : '', | |
'visible' => true, | |
'required' => false, | |
'user_defined' => true, | |
'searchable' => false, | |
'filterable' => true, | |
'comparable' => false, | |
'visible_on_front' => false, | |
'visible_in_advanced_search' => false, | |
'unique' => false | |
)); | |
} | |
// Attributes that use a textarea: | |
$textareaAttributes = array( | |
'testimonials' => array( | |
'label' => 'Testimonials' | |
) | |
); | |
foreach ($textareaAttributes as $tag => $details) { | |
$installer->addAttribute('catalog_product', $tag, array( | |
'label' => $details['label'], | |
'input' => 'textarea', | |
'type' => 'text', | |
'backend' => '', | |
'frontend' => '', | |
'source' => 'eav/entity_attribute_source_table', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, | |
'visible' => true, | |
'required' => false, | |
'user_defined' => true, | |
'searchable' => false, | |
'filterable' => true, | |
'comparable' => false, | |
'visible_on_front' => false, | |
'visible_in_advanced_search' => false, | |
'unique' => false | |
)); | |
} | |
// Add Brett, Pads, Fins, Leashes and Wax attribute sets | |
$sets = array('Brett', 'Pads', 'Fins', 'Leashes', 'Wax'); | |
$skeletonID = $installer->getAttributeSetId('catalog_product', 'Default'); | |
foreach ($sets as $set) { | |
$entityTypeId = Mage::getModel('catalog/product') | |
->getResource() | |
->getEntityType() | |
->getId(); | |
$attributeSet = Mage::getModel('eav/entity_attribute_set') | |
->setEntityTypeId($entityTypeId) | |
->setAttributeSetName($set); | |
$attributeSet->validate(); | |
$attributeSet->save(); | |
$attributeSet->initFromSkeleton($skeletonID)->save(); | |
Mage::Log('Added attribute set: ' . $set); | |
} | |
// Remove wetsuit specific attributes from new attribute sets | |
/** @var $this Mage_Eav_Model_Entity_Setup */ | |
$unrelatedAttributes = array( | |
'size', | |
'season', | |
'thickness', | |
'gender', | |
'wetsuitidealtemperature', | |
'zipperposition', | |
'brand', | |
'warm_suit' | |
); | |
foreach ($sets as $set) { | |
foreach ($unrelatedAttributes as $attributeCode) { | |
Mage::Log('Removing attribute code: ' . $attributeCode . ' from attribute set: ' . $set); | |
$installer->deleteTableRow( | |
'eav/entity_attribute', | |
'attribute_id', | |
$this->getAttributeId('catalog_product', $attributeCode), | |
'attribute_set_id', | |
$this->getAttributeSetId('catalog_product', $set) | |
); | |
Mage::Log('Removed attribute code: ' . $attributeCode . ' from attribute set: ' . $set); | |
} | |
} | |
// Add attributes to the various sets | |
$newAttributesToAttributeSets = array( | |
'Brett' => array( | |
'teaser', | |
'brettbrand', | |
'brettsize', | |
'productvideo', | |
'idealwave', | |
'velgbrettype', | |
'velgmerke', | |
'length', | |
'bredde', | |
'tykkelse', | |
'volum', | |
'testimonials' | |
), | |
'Pads' => array( | |
'teaser', | |
'padbrand', | |
'padsize', | |
'pieces', | |
'productvideo' | |
), | |
'Fins' => array( | |
'teaser', | |
'finsbrand', | |
'finssize', | |
'set', | |
'productvideo' | |
), | |
'Leashes' => array( | |
'teaser', | |
'leashbrand', | |
'leashessize', | |
'leashmm', | |
'productvideo' | |
), | |
'Wax' => array( | |
'teaser', | |
'waxbrand', | |
'waxsize', | |
'temperature', | |
'productvideo' | |
) | |
); | |
foreach ($newAttributesToAttributeSets as $setCode => $attributeCodes) { | |
foreach ($attributeCodes as $attributeCode) { | |
Mage::Log('Adding attribute code: ' . $attributeCode . ' to attribute set: ' . $setCode); | |
$attributeId = $installer->getAttribute('catalog_product', $attributeCode); | |
$attributeSetId = $installer->getAttributeSetId('catalog_product', $setCode); | |
//Get attribute group info | |
$attributeGroupId = $installer->getAttributeGroup('catalog_product', $attributeSetId, 'General'); | |
//add attribute to a set | |
$installer->addAttributeToSet( | |
'catalog_product', | |
$attributeSetId, | |
$attributeGroupId['attribute_group_id'], | |
$attributeId['attribute_id'] | |
); | |
Mage::Log('Added attribute code: ' . $attributeCode . ' to attribute set: ' . $setCode); | |
} | |
} | |
// Add needed custom variables | |
$customVariables = array( | |
'brett_accessories_id' => array( | |
'name' => 'Brett Accessories ID', | |
'value' => '5', | |
), | |
'pads_cat_id' => array( | |
'name' => 'Pads Category ID', | |
'value' => '10', | |
), | |
'fins_cat_id' => array( | |
'name' => 'Fins Category ID', | |
'value' => '11', | |
), | |
'brett_cat_id' => array( | |
'name' => 'Brett Cat ID', | |
'value' => '4', | |
), | |
'leash_cat_id' => array( | |
'name' => 'Leash Cat ID', | |
'value' => '12', | |
), | |
'wax_cat_id' => array( | |
'name' => 'Wax Cat ID', | |
'value' => '13', | |
), | |
'tilbehor_cat_id' => array( | |
'name' => 'Tilbehor Category ID', | |
'value' => '6', | |
), | |
'vatdrkat_cat_id' => array( | |
'name' => 'Vatdrkat Category ID', | |
'value' => '3', | |
) | |
); | |
foreach ($customVariables as $code => $values) { | |
$variable = Mage::getModel('core/variable') | |
->setCode($code) | |
->setName($values['name']) | |
->setPlainValue($values['value']) | |
->setHtmlValue($values['value']) | |
->save(); | |
} | |
// Update CMS Blocks | |
$currentStore = Mage::app()->getStore()->getStoreId(); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
// Main top left navigation | |
$identifier = 'header-menu'; | |
Mage::getModel('cms/block') | |
->load($identifier, 'identifier') | |
->setData('content', '<li class="nyheter"><a href="{{store_url=\'\'}}">Nyheter</a></li> | |
<li class="vatdrakter"><a href="{{store_url=\'vatdrakt.html\'}}#!season=12">Våtdrakt</a></li> | |
<li class="tilbehor"><a href="{{store_url=\'tilbehor.html\'}}#!season=12">Tilbehør</a></li> | |
<li class="brett"><a href="{{store_url=\'surfebrett.html\'}}">Surfebrett</a></li> | |
<li class="kontakt"><a href="{{store_url=\'drevet-av-lindenskap\'}}">Kontakt</a></li>') | |
->save() | |
; | |
// Add new cms blocks | |
$staticBlock = array( | |
'title' => 'Filters Brett Info Block', | |
'identifier' => 'filters-brett-info-blocks', | |
'content' => '<div class="box text-holder"> | |
<p><span>Høst/vinter</span>-kolleksjonen av våtdrakter er av et kaliber som lar deg være i aktivitet hele året rundt. Pointbreaks utvalg er bygget med høy kvalitetsbevissthet for å kunne representere de beste alternativene til våre kunder uansett årstid.</p> | |
</div>', | |
'is_active' => 1, | |
'stores' => array(0) | |
); | |
Mage::getModel('cms/block')->setData($staticBlock)->save(); | |
$staticBlock = array( | |
'title' => 'Brett Block Velg tilleggsutstyr', | |
'identifier' => 'filters-vleg-till', | |
'content' => '<div class="filters-box box"> | |
<div class="holder"> | |
<strong class="title">Velg tilleggsutstyr</strong> | |
<ul class="type-list"> | |
<li> | |
<span class="pads"><a href="{{store_url=\'brett-accessories/pads.html\'}}"><span class="icon"></span><span class="text">PADS</span></a></span> | |
</li> | |
<li> | |
<span class="fins"><a href="{{store_url=\'brett-accessories/fins.html\'}}"><span class="icon"></span><span class="text">FINs</span></a></span> | |
</li> | |
<li> | |
<span class="leashes"><a href="{{store_url=\'brett-accessories/leashes.html\'}}"><span class="icon"></span><span class="text">LEASHes</span></a></span> | |
</li> | |
<li> | |
<span class="wax"><a href="{{store_url=\'brett-accessories/wax.html\'}}"><span class="icon"></span><span class="text">WaX</span></a></span> | |
</li> | |
</ul> | |
</div> | |
</div>', | |
'is_active' => 1, | |
'stores' => array(0) | |
); | |
Mage::getModel('cms/block')->setData($staticBlock)->save(); | |
$staticBlock = array( | |
'title' => 'Beregn Volum Popup', | |
'identifier' => 'beregn-volum-popup', | |
'content' => '<div class="popup"> | |
<a class="close" href="#">Close</a> | |
<h3>BEREGN VOLUM</h3> | |
<div class="wrap"> | |
<div class="popup-box"> | |
<div class="row"> | |
<select class="popup-drop"> | |
<option>VEKT</option> | |
<option>VEKT</option> | |
</select> | |
</div> | |
<div class="row"> | |
<select class="popup-drop"> | |
<option>SKILL LEVEL</option> | |
<option>SKILL LEVEL</option> | |
</select> | |
</div> | |
<div class="row"> | |
<input type="submit" value="VOLUM" /> | |
</div> | |
</div> | |
</div> | |
</div>', | |
'is_active' => 1, | |
'stores' => array(0) | |
); | |
Mage::getModel('cms/block')->setData($staticBlock)->save(); | |
Mage::app()->setCurrentStore($currentStore); | |
reindexAllIndices(); | |
$installer->endSetup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment