uc_product_minmax.inc in Node import 6
Support for the Ubercart Product Minimum & Maximum module.
File
supported/uc_product_minmax/uc_product_minmax.incView source
<?php
/**
* @file
* Support for the Ubercart Product Minimum & Maximum module.
*/
/**
* Implementation of hook_node_import_fields().
*/
function uc_product_minmax_node_import_fields($type) {
$fields = array();
if (($node_type = node_import_type_is_node($type)) !== FALSE && uc_product_is_product($node_type)) {
$fields['product_min'] = array(
'title' => t('Minimum quantify to checkout'),
'group' => t('Product minimum'),
'default_value' => '0',
);
$fields['display_min'] = array(
'title' => t('Display the Minimum text on product page'),
'group' => t('Product minimum'),
'input_format' => 'boolean',
'default_value' => '1',
);
$fields['pmin_multiple'] = array(
'title' => t('Products must be purchased in multiples of'),
'group' => t('Product minimum'),
'default_value' => '1',
);
$fields['display_multiple'] = array(
'title' => t('Display the Multiple text on product page'),
'group' => t('Product minimum'),
'input_format' => 'boolean',
'default_value' => '1',
);
$fields['product_max'] = array(
'title' => t('Maximum quantity allowed to checkout'),
'group' => t('Product maximum'),
'default_value' => '0',
);
$fields['display_max'] = array(
'title' => t('Display the Maximum text on product page'),
'group' => t('Product maximum'),
'input_format' => 'boolean',
'default_value' => '1',
);
}
return $fields;
}
/**
* Implementation of hook_node_import_postprocess().
*/
function uc_product_minmax_node_import_postprocess($type, $values, $options, $preview) {
if (($node_type = node_import_type_is_node($type)) !== FALSE && uc_product_is_product($node_type)) {
if ($preview) {
// Only show that we're importing it.
drupal_set_message(theme('uc_product_minmax', $values['product_min'], $values['pmin_multiple'], $values['product_max'], 1, 1, 1));
}
else {
// Save the feature.
$minmax = (object) array(
'pfid' => db_last_insert_id('uc_product_features', 'pfid'),
'nid' => $values['nid'],
'product_min' => $values['product_min'],
'pmin_multiple' => $values['pmin_multiple'],
'product_max' => $values['product_max'],
'display_min' => $values['display_min'],
'display_multiple' => $values['display_multiple'],
'display_max' => $values['display_max'],
'display_weight' => variable_get('uc_product_minmax_weight', 9),
);
$args = array(
'@min' => $minmax->pmin_multiple > 1 ? t('Requires item to be purchased in multiples of @multiple.', array(
'@multiple' => $minmax->pmin_multiple,
)) : t('Requires a minimum of @minimum to checkout.', array(
'@minimum' => $minmax->product_min,
)),
'@max' => $minmax->product_max >= 1 ? t('Limits checkout to a maximum of @maximum.', array(
'@maximum' => $minmax->product_max,
)) : '',
);
$data = array(
'nid' => $values['nid'],
'fid' => 'minmax',
'description' => t('@min @max', $args),
);
uc_product_feature_save($data);
uc_product_minmax_values_save($minmax);
}
}
}
Functions
Name | Description |
---|---|
uc_product_minmax_node_import_fields | Implementation of hook_node_import_fields(). |
uc_product_minmax_node_import_postprocess | Implementation of hook_node_import_postprocess(). |