本文整理汇总了PHP中Magento\Framework\Session\SessionManagerInterface::setRatingData方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionManagerInterface::setRatingData方法的具体用法?PHP SessionManagerInterface::setRatingData怎么用?PHP SessionManagerInterface::setRatingData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Session\SessionManagerInterface
的用法示例。
在下文中一共展示了SessionManagerInterface::setRatingData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareForm
/**
* Prepare rating edit form
*
* @return $this
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$this->setForm($form);
$fieldset = $form->addFieldset('rating_form', array('legend' => __('Rating Title')));
$fieldset->addField('rating_code', 'text', array('name' => 'rating_code', 'label' => __('Default Value'), 'class' => 'required-entry', 'required' => true));
foreach ($this->_systemStore->getStoreCollection() as $store) {
$fieldset->addField('rating_code_' . $store->getId(), 'text', array('label' => $store->getName(), 'name' => 'rating_codes[' . $store->getId() . ']'));
}
if ($this->_session->getRatingData()) {
$form->setValues($this->_session->getRatingData());
$data = $this->_session->getRatingData();
if (isset($data['rating_codes'])) {
$this->_setRatingCodes($data['rating_codes']);
}
$this->_session->setRatingData(null);
} elseif ($this->_coreRegistry->registry('rating_data')) {
$form->setValues($this->_coreRegistry->registry('rating_data')->getData());
if ($this->_coreRegistry->registry('rating_data')->getRatingCodes()) {
$this->_setRatingCodes($this->_coreRegistry->registry('rating_data')->getRatingCodes());
}
}
if ($this->_coreRegistry->registry('rating_data')) {
$collection = $this->_optionFactory->create()->getResourceCollection()->addRatingFilter($this->_coreRegistry->registry('rating_data')->getId())->load();
$i = 1;
foreach ($collection->getItems() as $item) {
$fieldset->addField('option_code_' . $item->getId(), 'hidden', array('required' => true, 'name' => 'option_title[' . $item->getId() . ']', 'value' => $item->getCode() ? $item->getCode() : $i));
$i++;
}
} else {
for ($i = 1; $i <= 5; $i++) {
$fieldset->addField('option_code_' . $i, 'hidden', array('required' => true, 'name' => 'option_title[add_' . $i . ']', 'value' => $i));
}
}
$fieldset = $form->addFieldset('visibility_form', array('legend' => __('Rating Visibility')));
if (!$this->_storeManager->isSingleStoreMode()) {
$field = $fieldset->addField('stores', 'multiselect', array('label' => __('Visible In'), 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm()));
$renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
$field->setRenderer($renderer);
if ($this->_coreRegistry->registry('rating_data')) {
$form->getElement('stores')->setValue($this->_coreRegistry->registry('rating_data')->getStores());
}
}
$fieldset->addField('is_active', 'checkbox', array('label' => __('Is Active'), 'name' => 'is_active', 'value' => 1));
$fieldset->addField('position', 'text', array('label' => __('Sort Order'), 'name' => 'position'));
if ($this->_coreRegistry->registry('rating_data')) {
$form->getElement('position')->setValue($this->_coreRegistry->registry('rating_data')->getPosition());
$form->getElement('is_active')->setIsChecked($this->_coreRegistry->registry('rating_data')->getIsActive());
}
return parent::_prepareForm();
}
示例2: setRatingData
/**
* Set rating data to form
*
* @return void
*/
protected function setRatingData()
{
if ($this->session->getRatingData()) {
$this->getForm()->setValues($this->session->getRatingData());
$data = $this->session->getRatingData();
if (isset($data['rating_codes'])) {
$this->setRatingCodes($data['rating_codes']);
}
$this->session->setRatingData(null);
} elseif ($this->_coreRegistry->registry('rating_data')) {
$this->getForm()->setValues($this->_coreRegistry->registry('rating_data')->getData());
if ($this->_coreRegistry->registry('rating_data')->getRatingCodes()) {
$this->setRatingCodes($this->_coreRegistry->registry('rating_data')->getRatingCodes());
}
}
$this->setRatingOptions();
}