126 lines
4.3 KiB
PHP
126 lines
4.3 KiB
PHP
<?php
|
|
|
|
function st_product_options_picker_show($namespace, $options, &$selected_ids = array())
|
|
{
|
|
$select_options = array();
|
|
|
|
$field_id = $options[0]->getProductOptionsField()->getId();
|
|
|
|
$selected = $options[0];
|
|
|
|
$last_option_id = end($options)->getId();
|
|
|
|
foreach ($options as $option)
|
|
{
|
|
$option_id = $option->getId();
|
|
|
|
$field = $option->getProductOptionsField();
|
|
|
|
$current_field_id = $field->getId();
|
|
|
|
$selected_id = isset($selected_ids[$current_field_id]) ? $selected_ids[$current_field_id] : null;
|
|
|
|
if ($field_id != $current_field_id)
|
|
{
|
|
echo '<li><label><span>' . $selected->getProductOptionsField()->getName() . '</span>' . select_tag($namespace . '[' . $selected->getProductOptionsFieldId() . ']', options_for_select($select_options, $selected->getId()), array('data-field' => $selected->getProductOptionsFieldId())) . '</label></li>';
|
|
|
|
if ($selected->hasChildren())
|
|
{
|
|
st_product_options_picker_show($namespace, $selected->getChildOptions(), $selected_ids);
|
|
}
|
|
|
|
$select_options = array();
|
|
|
|
$field_id = $current_field_id;
|
|
$selected_ids[$selected->getProductOptionsFieldId()] = $selected->getId();
|
|
$selected = $option;
|
|
}
|
|
elseif ($selected_id && $selected_id == $option_id || null === $selected_id && $option->getOptValue() == $field->getOptDefaultValue())
|
|
{
|
|
$selected = $option;
|
|
$selected_ids[$selected->getProductOptionsFieldId()] = $selected->getId();
|
|
}
|
|
|
|
$select_options[$option_id] = $option->getValue();
|
|
|
|
if ($last_option_id == $option_id)
|
|
{
|
|
echo '<li><label><span>' . $selected->getProductOptionsField()->getName() . '</span>' . select_tag($namespace . '[' . $selected->getProductOptionsFieldId() . ']', options_for_select($select_options, $selected->getId()), array('data-field' => $selected->getProductOptionsFieldId())) . '</label></li>';
|
|
|
|
$selected_ids[$selected->getProductOptionsFieldId()] = $selected->getId();
|
|
|
|
if ($selected->hasChildren())
|
|
{
|
|
st_product_options_picker_show($namespace, $selected->getChildOptions(), $selected_ids);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function object_field_select_default_value(ProductOptionsField $field, $method, $options)
|
|
{
|
|
$name = $options['control_name'];
|
|
$c = new Criteria();
|
|
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field->getId());
|
|
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
|
|
|
|
$select_options = array();
|
|
|
|
foreach (ProductOptionsValuePeer::doSelectWithI18n($c, $field->getCulture()) as $value)
|
|
{
|
|
$select_options[$value->getOptValue()] = $value->getValue();
|
|
}
|
|
|
|
unset($options['control_name']);
|
|
|
|
return select_tag($name, options_for_select($select_options, $field->getOptDefaultValue(), array('include_custom' => '---')));
|
|
}
|
|
|
|
function object_template_field_select_default_value(ProductOptionsField $field, $method, $options)
|
|
{
|
|
$name = $options['control_name'];
|
|
$c = new Criteria();
|
|
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field->getId());
|
|
$c->addAscendingOrderByColumn(ProductOptionsDefaultValuePeer::LFT);
|
|
|
|
$select_options = array();
|
|
|
|
foreach (ProductOptionsDefaultValuePeer::doSelectWithI18n($c, $field->getCulture()) as $value)
|
|
{
|
|
$select_options[$value->getOptValue()] = $value->getValue();
|
|
}
|
|
|
|
unset($options['control_name']);
|
|
|
|
return select_tag($name, options_for_select($select_options, $field->getOptDefaultValue(), array('include_custom' => '---')));
|
|
}
|
|
|
|
function st_product_options_template_select_tag($name, $value = null, array $options = null)
|
|
{
|
|
$fc = stFunctionCache::getInstance('stProductOptions');
|
|
|
|
$select_options = $fc->cacheCall(function ()
|
|
{
|
|
$c = new Criteria();
|
|
$c->addAscendingOrderByColumn(ProductOptionsTemplatePeer::OPT_NAME);
|
|
$templates = ProductOptionsTemplatePeer::doSelect($c);
|
|
|
|
$results = array();
|
|
|
|
/**
|
|
* @var ProductOptionsTemplate[] $templates
|
|
*/
|
|
foreach ($templates as $template)
|
|
{
|
|
if ($template->countProductOptionsDefaultValues() > 1)
|
|
{
|
|
$results[$template->getId()] = $template->getOptName();
|
|
}
|
|
}
|
|
|
|
return $results;
|
|
}, array(), array('id' => 'templates'));
|
|
|
|
return $select_options ? select_tag($name, options_for_select($select_options, $value, $options)) : null;
|
|
}
|