Drupal 6 Drupal 6/Ubercart-自动设置调整SKU
是否可以为Ubercart中的产品自动设置调整备用SKU值Drupal 6 Drupal 6/Ubercart-自动设置调整SKU,drupal-6,drupal-modules,ubercart,Drupal 6,Drupal Modules,Ubercart,是否可以为Ubercart中的产品自动设置调整备用SKU值 基本上,每个产品都会根据调整将后缀添加到其原始SKU中,因此在创建产品节点时自动填充调整SKU将节省大量时间 这可能不是正确的方法,但我创建了一个小模块,可以插入nodeapi插入操作: <?php function photo_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'photo_node_form'){
基本上,每个产品都会根据调整将后缀添加到其原始SKU中,因此在创建产品节点时自动填充调整SKU将节省大量时间 这可能不是正确的方法,但我创建了一个小模块,可以插入nodeapi插入操作:
<?php
function photo_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'photo_node_form'){
$form['base']['model']['#default_value'] = 'placeholder';
}
}
function photo_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch($op){
case 'presave':
if($node->model == 'placeholder')
$node->model = $node->field_image_cache2[0]['filename'];
break;
case 'insert':
$nid = $node->nid;
$sku_dl = $node->model.'d';
//====== Setup Adjustments ======
db_query('INSERT INTO {uc_product_adjustments} (nid,combination,model) VALUES'
.'('.$nid.',"%s","'.$sku_dl.'"),'
.'('.$nid.',"%s","'.$sku_dl.'"),'
.'('.$nid.',"%s","'.$sku_dl.'"),'
.'('.$nid.',"%s","'.$sku_dl.'"),'
.'('.$nid.',"%s","'.$sku_dl.'")'
,serialize(array('1'=>'1'))
,serialize(array('1'=>'3'))
,serialize(array('1'=>'4'))
,serialize(array('1'=>'5'))
,serialize(array('1'=>'6'))
);
//====== Add file download on purchase ======
$file_name = $node->field_image_cache2[0]['filename'];
db_query("INSERT INTO {uc_files} (filename) VALUES ('%s')",$file_name);
db_query("INSERT INTO {uc_file_products} (pfid, fid, model, description, shippable) VALUES (%d, LAST_INSERT_ID(), '%s', '%s', %d)", 0, $sku_dl, '', 1);
db_query('UPDATE {uc_file_products} SET pfid = LAST_INSERT_ID() WHERE fpid = LAST_INSERT_ID() LIMIT 1');
db_query("INSERT INTO {uc_product_features} (pfid, fid, nid, description) VALUES (LAST_INSERT_ID(), '%s', %d, '%s')", 'file', $nid, '<b>Filename</b><br/>'.$file_name.'<br/> <b>Reference</b> : '.$sku_dl);
break;
}
}
这是一个JavaScript版本-它提供了一个自动生成SKU的链接,以及股票页面上的“默认股票”选项
Drupal.behaviors.autoSKU = function(){
//if we're on the product adjustments page, add a button to automatically set sku's
if($('#uc-product-adjustments-form').length > 0){
$('#uc-product-adjustments-form').before($('<a>Automatically set SKU\'s</a>').css('cursor', 'pointer').click(function(){
$base = $('#uc-product-adjustments-form').attr('action').substr(6, 4) + '-';
$('#uc-product-adjustments-form .form-text').each(function(){
$(this).attr('value', $base + $(this).parents('tr').attr('title').toLowerCase().replace(new RegExp(' ', 'g'),'-'));
});
}));
}
//if we're on the stock page, automatically set as active and set default stock level
if($('#uc-stock-edit-form').length > 0){
$('#uc-stock-edit-form').before($('<a>Activate and Set Default Stock</a>').css('cursor', 'pointer').click(function(){
$first = true;
$('#uc-stock-edit-form .form-checkbox').each(function(){
if($first){
$(this).attr('checked', false);
$first = false;
}
else{
$(this).attr('checked', true);
}
});
$set_stock = $('#edit-stock-0-stock').attr('value');
$odd = true;
$('#uc-stock-edit-form .form-text').each(function(){
if($odd){
$(this).attr('value', $set_stock);
}
$odd = !$odd;
});
}));
}
}
Drupal.behaviors.autoSKU=function(){
//如果我们在“产品调整”页面上,请添加一个按钮以自动设置sku
如果($('#uc产品调整表')。长度>0){
$(“#uc产品调整表”)。在($(“自动设置SKU”).css(‘光标’、‘指针’)之前。单击(函数(){
$base=$(“#uc产品调整表”).attr('action').substr(6,4)+'-';
$('#uc产品调整表.form text')。每个(函数(){
$(this).attr('value',$base+$(this).parents('tr').attr('title').toLowerCase().replace(新的RegExp('g'),'-'));
});
}));
}
//如果我们在“库存”页面,则自动设置为“活动”并设置默认库存水平
如果($('#uc库存编辑表单')。长度>0){
$(“#uc库存编辑表单”)。在($(“激活并设置默认库存”).css(“光标”、“指针”)之前。单击(函数(){
$first=true;
$('#uc股票编辑表单.表单复选框')。每个(函数(){
如果($第一){
$(this.attr('checked',false);
$first=false;
}
否则{
$(this.attr('checked',true);
}
});
$set_stock=$('edit-stock-0-stock').attr('value');
$odd=真;
$('#uc stock edit form.form text')。每个(函数(){
若有($奇数){
$(this).attr('value',$set\u stock);
}
$odd=!$odd;
});
}));
}
}
看一看
看来这可以在现成的基础上完成