Create new type product
Created
August 29, 2016 15:40
-
-
Save korbax/ee71e38d0a2313c7f4d2524e95e33f22 to your computer and use it in GitHub Desktop.
dgdf
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
<?xml version="1.0"?> | |
<config> | |
<modules> | |
<Onerockwell_PromoBox> | |
<version>0.2.0</version> | |
</Onerockwell_PromoBox> | |
</modules> | |
<global> | |
<catalog> | |
<product> | |
<type> | |
<affiliate translate="label" module="onerockwell_promobox"> | |
<label>Promo Box</label> | |
<model>onerockwell_promobox/product_type</model> | |
<is_qty>0</is_qty> | |
<composite>0</composite> | |
<can_use_qty_decimals>0</can_use_qty_decimals> | |
</affiliate> | |
</type> | |
</product> | |
</catalog> | |
<blocks> | |
<onerockwell_promobox> | |
<class>Onerockwell_PromoBox_Block</class> | |
</onerockwell_promobox> | |
</blocks> | |
<helpers> | |
<onerockwell_promobox> | |
<class>Onerockwell_PromoBox_Helper</class> | |
</onerockwell_promobox> | |
</helpers> | |
<models> | |
<onerockwell_promobox> | |
<class>Onerockwell_PromoBox_Model</class> | |
<resourceModel>onerockwell_promobox_mysql4</resourceModel> | |
</onerockwell_promobox> | |
</models> | |
<resources> | |
<onerockwell_promobox_setup> | |
<setup> | |
<module>Onerockwell_PromoBox</module> | |
<class>Mage_Sales_Model_Mysql4_Setup</class> | |
</setup> | |
<connection> | |
<use>core_setup</use> | |
</connection> | |
</onerockwell_promobox_setup> | |
<onerockwell_promobox_write> | |
<connection> | |
<use>core_write</use> | |
</connection> | |
</onerockwell_promobox_write> | |
<onerockwell_promobox_read> | |
<connection> | |
<use>core_read</use> | |
</connection> | |
</onerockwell_promobox_read> | |
</resources> | |
</global> | |
<frontend> | |
<routers> | |
<onerockwell_promobox> | |
<use>standard</use> | |
<args> | |
<module>Onerockwell_PromoBox</module> | |
<frontName>onerockwell</frontName> | |
</args> | |
</onerockwell_promobox> | |
</routers> | |
<!--<layout>--> | |
<!--<updates>--> | |
<!--<onerockwell_promobox>--> | |
<!--<file>onerockwell/promobox.xml</file>--> | |
<!--</onerockwell_promobox>--> | |
<!--</updates>--> | |
<!--</layout>--> | |
</frontend> | |
<adminhtml> | |
<layout> | |
<updates> | |
<onerockwell_promobox> | |
<file>onerockwell/promobox.xml</file> | |
</onerockwell_promobox> | |
</updates> | |
</layout> | |
</adminhtml> | |
</config> |
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 | |
class Onerockwell_PromoBox_Helper_Data extends Mage_Checkout_Helper_Cart | |
{ | |
} |
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 | |
class Onerockwell_PromoBox_Model_Attribute_Source_Type extends Mage_Eav_Model_Entity_Attribute_Source_Abstract | |
{ | |
const SINGLE = 0; | |
const DOUBLE = 1; | |
public function getAllOptions() | |
{ | |
if (is_null($this->_options)) { | |
$this->_options = array( | |
array( | |
'label' => Mage::helper('onerockwell_promobox')->__('Single'), | |
'value' => self::SINGLE | |
), | |
array( | |
'label' => Mage::helper('onerockwell_promobox')->__('Double'), | |
'value' => self::DOUBLE | |
), | |
); | |
} | |
return $this->_options; | |
} | |
public function toOptionArray() | |
{ | |
return $this->getAllOptions(); | |
} | |
public function addValueSortToCollection($collection, $dir = 'asc') | |
{ | |
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; | |
$valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; | |
$valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; | |
$collection->getSelect()->joinLeft( | |
array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), | |
"`e`.`entity_id`=`{$valueTable1}`.`entity_id`" | |
. " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'" | |
. " AND `{$valueTable1}`.`store_id`='{$adminStore}'", | |
array() | |
); | |
if ($collection->getStoreId() != $adminStore) { | |
$collection->getSelect()->joinLeft( | |
array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), | |
"`e`.`entity_id`=`{$valueTable2}`.`entity_id`" | |
. " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'" | |
. " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'", | |
array() | |
); | |
$valueExpr = new Zend_Db_Expr("IF(`{$valueTable2}`.`value_id`>0, `{$valueTable2}`.`value`, `{$valueTable1}`.`value`)"); | |
} else { | |
$valueExpr = new Zend_Db_Expr("`{$valueTable1}`.`value`"); | |
} | |
$collection->getSelect() | |
->order($valueExpr, $dir); | |
return $this; | |
} | |
public function getFlatColums() | |
{ | |
$columns = array( | |
$this->getAttribute()->getAttributeCode() => array( | |
'type' => 'int', | |
'unsigned' => false, | |
'is_null' => true, | |
'default' => null, | |
'extra' => null | |
) | |
); | |
return $columns; | |
} | |
public function getFlatUpdateSelect($store) | |
{ | |
return Mage::getResourceModel('eav/entity_attribute') | |
->getFlatUpdateSelect($this->getAttribute(), $store); | |
} | |
} |
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 | |
class Onerockwell_PromoBox_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Simple | |
{ | |
const TYPE_AFFILIATE = 'promobox'; | |
const XML_PATH_AUTHENTICATION = 'catalog/promobox/authentication'; | |
protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode) | |
{ | |
if ($this->_isStrictProcessMode($processMode)) { | |
return Mage::helper('onerockwell_promobox')->__( | |
'Promobox product %s cannot be added to cart. ' . | |
' On the product detail page click the "Go to parent site"'. | |
' button to access the product.', | |
$product->getName() | |
); | |
} | |
return parent::_prepareProduct($buyRequest, $product, $processMode); | |
} | |
} |
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 | |
/** @var $installer Mage_Catalog_Model_Resource_Setup */ | |
$installer = $this; | |
$installer->startSetup(); | |
$installer->addAttribute( | |
Mage_Catalog_Model_Product::ENTITY, | |
'promobox_link', | |
array( | |
'type' => 'text', | |
'backend' => '', | |
'frontend' => '', | |
'label' => 'Promo link', | |
'input' => 'text', | |
'class' => '', | |
'source' => '', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, | |
'visible' => true, | |
'required' => false, | |
'user_defined' => false, | |
'default' => '', | |
'searchable' => false, | |
'filterable' => false, | |
'comparable' => false, | |
'visible_on_front' => false, | |
'unique' => false, | |
'apply_to' => 'promobox', | |
'is_configurable' => false, | |
'used_in_product_listing' => false, | |
) | |
); | |
$installer->addAttribute( | |
Mage_Catalog_Model_Product::ENTITY, | |
'promobox_type', | |
array( | |
'type' => 'int', | |
'backend' => '', | |
'frontend' => '', | |
'label' => 'Promo type', | |
'input' => 'select', | |
'class' => '', | |
'source' => 'onerockwell_promobox/attribute_source_type', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, | |
'visible' => true, | |
'required' => false, | |
'user_defined' => false, | |
'default' => '0', | |
'searchable' => false, | |
'filterable' => false, | |
'comparable' => false, | |
'visible_on_front' => false, | |
'unique' => false, | |
'apply_to' => 'promobox', | |
'is_configurable' => false, | |
'used_in_product_listing' => false, | |
'option' => | |
array ( | |
'values' => | |
array ( | |
0 => 'Single', | |
1 => 'Double', | |
), | |
) | |
) | |
); |
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 | |
/** @var $installer Mage_Catalog_Model_Resource_Setup */ | |
$installer = $this; | |
$installer->startSetup(); | |
/** | |
* Create new category | |
*/ | |
Mage::register('isSecureArea', 1); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$category = Mage::getModel('catalog/category'); | |
$category->setPath('1/2') | |
->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID) | |
->setName('moduleB-3-top-product') | |
->setUrlKey('moduleB-3-top-product') | |
->setIsAnchor(0) | |
->setIncludeInMenu(0) | |
->setIsActive(1) | |
->save(); | |
$categoryId = $category->getEntityId(); | |
/** | |
* Create new statick block used category: moduleB-3-top-product | |
*/ | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$block = Mage::getModel('cms/block')->load('test-block'); | |
if($block){ | |
$content = '{{block type="catalog/product_list" column_count="4" category_id="' . $categoryId . '" template="catalog/product/list.phtml"}}'; | |
$title = 'Test Block'; | |
$block = Mage::getModel('cms/block')->load('test-block'); | |
$block->setData('content',$content); | |
$block->setData('title',$title); | |
$block->save(); | |
} | |
else { | |
$staticBlock = array( | |
'title' => 'Test Block', | |
'identifier' => 'test-block', | |
'content' => '{{block type="catalog/product_list" column_count="4" category_id="' . $categoryId . '" template="catalog/product/list.phtml"}}', | |
'is_active' => 1, | |
'stores' => array(0) | |
); | |
Mage::getModel('cms/block')->setData($staticBlock)->save(); | |
} | |
$installer->endSetup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment