首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Magento Custom Options Templates (完善)

2013-09-18 
Magento Custom Options Templates (完美)Step 1: change the app/design/adminhtml/default/default/temp

Magento Custom Options Templates (完美)

Step 1: change the app/design/adminhtml/default/default/template/page/head.phtml with the attached head.phtml

Step 2: app/design/adminhtml/default/default/template/catalog/product/edit/options.phtml 
before: 

<div class="entry-edit-head">
insert: 
<div id="coSamples" style="margin-bottom:15px;"></div>

and

after: 

<script type="text/javascript">insert: 
initOptionsSamples();

Step 3: app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml 
find: 

OptionTemplateSelectRow = ...

replace with: 

Image AttachmentsMagento Custom Options Templates (完善)Magento Custom Options Templates (完善)Click thumbnail to see full-size imageFile AttachmentsMagento Custom Options Templates (完善) head.phtml  (File Size: 9KB - Downloads: 320)



方法二

function setCustomOption($productId,                   $title,                   array $optionData,                   array $values = array()) {                        Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);      if (!$product = Mage::getModel('catalog/product')->load($productId)) {          throw new Exception('Can not find product: ' . $productId);      }            $defaultData = array(          'type'          => 'field',          'is_require'    => 0,          'price'         => 0,          'price_type'    => 'fixed',      );            $data = array_merge($defaultData,                           $optionData,                           array('product_id' => (int)$productId,                          'title' => $title,                          'values' => $values));            $product->setHasOptions(1)->save();                                           $option = Mage::getModel('catalog/product_option')->setData($data)                      ->setProduct($product)->save();      return $option;  }  $productop = Mage::registry('current_product');$_product = Mage::getModel('catalog/product')->load($productop->getId());$optionexist=count($_product->getOptions());$casetemplate=$_product->getResource()->getAttribute('pattern_template')->getFrontend()->getValue($_product);if($optionexist==0){if($casetemplate=='Small'){$sku=$_product->getResource()->getAttribute('sku')->getFrontend()->getValue($_product);$options =  array('type' => 'drop_down',              'is_require' => 1,              'price' => 0,              'price_type' => 'fixed');  $values = array(              array(                  'title' => 'Black',                  'price' =>0.00,                  'price_type' => 'fixed',                  'sku' => $sku,                'sort_order' => 1              ),                 array(                  'title' => 'Brown',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 2              ),                  array(                  'title' => 'Red',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 3              ),array(                  'title' => 'Petal Pink',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 4              ),array(                  'title' => 'White',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 5              ),array(                  'title' => 'Aqua',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 6              ),array(                  'title' => 'Purple',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 7              ),array(                  'title' => 'Black/Red Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 8              ),array(                  'title' => 'Black/Orange Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 9              ),array(                  'title' => 'Black/Green Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 10              ),array(                  'title' => 'Black/Purple Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 11              )         );  setCustomOption($productop->getId(), 'Pattern', $options, $values); echo "Generate Small Case Successful";}else if($casetemplate=='Big'){$sku=$_product->getResource()->getAttribute('sku')->getFrontend()->getValue($_product);$options =  array('type' => 'drop_down',              'is_require' => 1,              'price' => 0,              'price_type' => 'fixed');  $values = array(              array(                  'title' => 'Black',                  'price' =>0.00,                  'price_type' => 'fixed',                  'sku' => $sku,                'sort_order' => 1              ),                 array(                  'title' => 'Brown',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 2              ),                  array(                  'title' => 'Red',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 3              ),array(                  'title' => 'Purple',                  'price' => 0.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 4              ),array(                  'title' => 'Black/Red Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 5              ),array(                  'title' => 'Black/Orange Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' =>6              ),array(                  'title' => 'Black/Green Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 7              ),array(                  'title' => 'Black/Purple Stitch',                  'price' => 2.00,                  'price_type' => 'fixed',                  'sku' => '',                  'sort_order' => 8              )         );     setCustomOption($productop->getId(), 'Pattern', $options, $values); echo "Generate Big Case Successful";}else{echo "Pattern is Empty, Nothing to do";}}else{if($casetemplate!='Big' || $casetemplate!='Small'){foreach ($productop->getOptions() as $opt) {$opt->delete(); }$productop->setHasOptions(0)->save();echo "Delete options";}else{echo "Nothing to do";}}



热点排行