我是magento的新手。我创建了一个自定义模块,因为我想显示该特定登录客户订单的上市订单ID的选择框。我正在努力做到这一点。
我的表单代码在这里:
<?php
class Blazedream_CustomerComplaints_Block_Complaints_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
public function getOrderData()
{
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
->setOrder('created_at', 'desc');
$this->setOrders($orders);
foreach ($orders as $order):
return $order->getRealOrderId();
endforeach;
}
protected function _prepareForm()
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerId=$customer->getId();
$cus_name=$customer->getName();
$emailId=$customer->getEmail();
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset("customercomplaints_form", array("legend"=>Mage::helper("customercomplaints")->__("Item information")));
$three_columns = "col-xs-12 col-sm-4 col-md-4 col-lg-4";
$one_column = "col-xs-12 col-sm-12 col-md-12 col-lg-12";
$fieldset->addField("customer_complaints_id", "hidden", array(
"label" => Mage::helper("customercomplaints")->__("Id"),
"name" => "customer_complaints_id",
));
$fieldset->addField("name", "text", array(
"label" => Mage::helper("customercomplaints")->__("Name"),
"name" => "name",
"class"=> "required-entry",
'readonly'=>true,
'required' => true,
'value' =>$cus_name,
'container_class' => $three_columns
));
$fieldset->addField('order_id1', 'select', array(
'name' => 'order_id1',
'label' => 'Order Id1',
'values' => $this->getOrderData(),
));
if (Mage::getSingleton("adminhtml/session")->getComplaintsData())
{
$form->setValues(Mage::getSingleton("adminhtml/session")->getComplaintsData());
Mage::getSingleton("adminhtml/session")->setComplaintsData(null);
}
elseif(Mage::registry("complaints_data")) {
$form->setValues(Mage::registry("complaints_data")->getData());
}
return parent::_prepareForm();
}
}
我的观点文件:
<div class="return-policy vendor-suggestion-main my-account">
<div class="page-title">
<h1>Complaints</h1>
</div>
<form action="<?php echo $this->getSaveUrl() ?>" method="post" id="customer_complaints_form" enctype="multipart/form-data">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey();?>" />
<?php echo $this->getBlockHtml('formkey')?>
<div style="display:none"></div>
<?php echo $this->getChildHtml("complaints_edit_form") ?>
<div class="return-order-submit">
<p class="content-buttons form-buttons">
<?php echo $this->getSaveButtonHtml() ?>
</p>
</div>
</form>
</div>
<script type="text/javascript">
var customerComplaints = new VarienForm('customer_complaints_form', true); // '<?php echo $this->getValidationUrl() ?>');
customerComplaints._processValidationResult = function(transport) {
var response = transport.responseText.evalJSON();
if (response.error){
if (response.attribute && $(response.attribute)) {
$(response.attribute).setHasError(true, customerComplaints);
Validation.ajaxError($(response.attribute), response.message);
if (!Prototype.Browser.IE){
$(response.attribute).focus();
}
}
else if ($('messages')) {
$('messages').innerHTML = '<ul class="messages"><li class="error-msg"><ul><li>' + response.message + '</li></ul></li></ul>';
}
}
else{
customerComplaints._submit();
}
};
</script>
谁能告诉我怎么做?
提前致谢。
答案 0 :(得分:0)
我创建了一个这样的函数:
$fieldset->addField('order_id', 'select', array(
"label" => Mage::helper("customercomplaints")->__("Order Id"),
'name' => 'order_id',
"class"=> "required-entry",
'values' => $this->getOrderData(),
'container_class' => $three_columns
));
然后我在我的表单字段集中调用了这个函数,如下所示:
img {
position: relative;
}
span {
position: absolute;
top: 40%;
left: 40%;
}
我收到了客户订购的订单ID列表的下拉框