示例#1
0
文件: Form.php 项目: aiesh/magento2
 /**
  * Prepare add review form
  *
  * @return void
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $fieldset = $form->addFieldset('add_review_form', array('legend' => __('Review Details')));
     $fieldset->addField('product_name', 'note', array('label' => __('Product'), 'text' => 'product_name'));
     $fieldset->addField('detailed_rating', 'note', array('label' => __('Product Rating'), 'required' => true, 'text' => '<div id="rating_detail">' . $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->toHtml() . '</div>'));
     $fieldset->addField('status_id', 'select', array('label' => __('Status'), 'required' => true, 'name' => 'status_id', 'values' => $this->_reviewData->getReviewStatusesOptionArray()));
     /**
      * Check is single store mode
      */
     if (!$this->_storeManager->isSingleStoreMode()) {
         $field = $fieldset->addField('select_stores', 'multiselect', array('label' => __('Visible In'), 'required' => true, 'name' => 'select_stores[]', 'values' => $this->_systemStore->getStoreValuesForForm()));
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
     }
     $fieldset->addField('nickname', 'text', array('name' => 'nickname', 'title' => __('Nickname'), 'label' => __('Nickname'), 'maxlength' => '50', 'required' => true));
     $fieldset->addField('title', 'text', array('name' => 'title', 'title' => __('Summary of Review'), 'label' => __('Summary of Review'), 'maxlength' => '255', 'required' => true));
     $fieldset->addField('detail', 'textarea', array('name' => 'detail', 'title' => __('Review'), 'label' => __('Review'), 'style' => 'height: 600px;', 'required' => true));
     $fieldset->addField('product_id', 'hidden', array('name' => 'product_id'));
     /*$gridFieldset = $form->addFieldset('add_review_grid', array('legend' => __('Please select a product')));
       $gridFieldset->addField('products_grid', 'note', array(
       'text' => $this->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Product\Grid')->toHtml(),
       ));*/
     $form->setMethod('post');
     $form->setUseContainer(true);
     $form->setId('edit_form');
     $form->setAction($this->getUrl('review/product/post'));
     $this->setForm($form);
 }
示例#2
0
 public function testPrepareDataSource()
 {
     $dataSource = ['data' => ['items' => [['status_id' => 1]]]];
     $expectedDataSource = ['data' => ['items' => [['status_id' => __('Approved')]]]];
     $this->sourceMock->expects($this->once())->method('getReviewStatuses')->willReturn([\Magento\Review\Model\Review::STATUS_APPROVED => __('Approved')]);
     $this->assertEquals($expectedDataSource, $this->getModel()->prepareDataSource($dataSource));
 }
示例#3
0
 protected function setUp()
 {
     $this->storeManager = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface');
     $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\RequestInterface');
     $this->reviewDataMock = $this->getMockBuilder('\\Magento\\Review\\Helper\\Data')->disableOriginalConstructor()->getMock();
     $this->reviewDataMock->expects($this->once())->method('getIsGuestAllowToWrite')->willReturn(true);
     $this->context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false);
     $this->context->expects($this->any())->method('getStoreManager')->will($this->returnValue($this->storeManager));
     $this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
     $this->productRepository = $this->getMock('\\Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->object = $this->objectManagerHelper->getObject('Magento\\Review\\Block\\Form', ['context' => $this->context, 'reviewData' => $this->reviewDataMock, 'productRepository' => $this->productRepository]);
 }
示例#4
0
 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->urlEncoder->encode($this->getUrl('*/*/*', ['_current' => true]) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', [Url::REFERER_QUERY_PARAM_NAME => $queryParam]));
     }
     $this->setTemplate('form.phtml');
 }
示例#5
0
 /**
  * Add status filter
  *
  * @param int|string $status
  * @return $this
  */
 public function addStatusFilter($status)
 {
     if (is_string($status)) {
         $statuses = array_flip($this->_reviewData->getReviewStatuses());
         $status = isset($statuses[$status]) ? $statuses[$status] : 0;
     }
     if (is_numeric($status)) {
         $this->addFilter('status', $this->getConnection()->quoteInto('main_table.status_id=?', $status), 'string');
     }
     return $this;
 }
示例#6
0
 /**
  * Prepare grid mass actions
  *
  * @return void
  */
 protected function _prepareMassaction()
 {
     $this->setMassactionIdField('review_id');
     $this->setMassactionIdFilter('rt.review_id');
     $this->setMassactionIdFieldOnlyIndexValue(true);
     $this->getMassactionBlock()->setFormFieldName('reviews');
     $this->getMassactionBlock()->addItem('delete', ['label' => __('Delete'), 'url' => $this->getUrl('*/*/massDelete', ['ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : 'index']), 'confirm' => __('Are you sure?')]);
     $statuses = $this->_reviewData->getReviewStatusesOptionArray();
     array_unshift($statuses, ['label' => '', 'value' => '']);
     $this->getMassactionBlock()->addItem('update_status', ['label' => __('Update Status'), 'url' => $this->getUrl('*/*/massUpdateStatus', ['ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : 'index']), 'additional' => ['status' => ['name' => 'status', 'type' => 'select', 'class' => 'required-entry', 'label' => __('Status'), 'values' => $statuses]]]);
 }
示例#7
0
 /**
  * Prepare edit review form
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     $review = $this->_coreRegistry->registry('review_data');
     $product = $this->_productFactory->create()->load($review->getEntityPkValue());
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getUrl('review/*/save', ['id' => $this->getRequest()->getParam('id'), 'ret' => $this->_coreRegistry->registry('ret')]), 'method' => 'post']]);
     $fieldset = $form->addFieldset('review_details', ['legend' => __('Review Details'), 'class' => 'fieldset-wide']);
     $fieldset->addField('product_name', 'note', ['label' => __('Product'), 'text' => '<a href="' . $this->getUrl('catalog/product/edit', ['id' => $product->getId()]) . '" onclick="this.target=\'blank\'">' . $this->escapeHtml($product->getName()) . '</a>']);
     try {
         $customer = $this->customerRepository->getById($review->getCustomerId());
         $customerText = __('<a href="%1" onclick="this.target=\'blank\'">%2 %3</a> <a href="mailto:%4">(%4)</a>', $this->getUrl('customer/index/edit', ['id' => $customer->getId(), 'active_tab' => 'review']), $this->escapeHtml($customer->getFirstname()), $this->escapeHtml($customer->getLastname()), $this->escapeHtml($customer->getEmail()));
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $customerText = $review->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID ? __('Administrator') : __('Guest');
     }
     $fieldset->addField('customer', 'note', ['label' => __('Author'), 'text' => $customerText]);
     $fieldset->addField('summary_rating', 'note', ['label' => __('Summary Rating'), 'text' => $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Summary')->toHtml()]);
     $fieldset->addField('detailed_rating', 'note', ['label' => __('Detailed Rating'), 'required' => true, 'text' => '<div id="rating_detail">' . $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->toHtml() . '</div>']);
     $fieldset->addField('status_id', 'select', ['label' => __('Status'), 'required' => true, 'name' => 'status_id', 'values' => $this->_reviewData->getReviewStatusesOptionArray()]);
     /**
      * Check is single store mode
      */
     if (!$this->_storeManager->hasSingleStore()) {
         $field = $fieldset->addField('select_stores', 'multiselect', ['label' => __('Visibility'), 'required' => true, 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm()]);
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
         $review->setSelectStores($review->getStores());
     } else {
         $fieldset->addField('select_stores', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]);
         $review->setSelectStores($this->_storeManager->getStore(true)->getId());
     }
     $fieldset->addField('nickname', 'text', ['label' => __('Nickname'), 'required' => true, 'name' => 'nickname']);
     $fieldset->addField('title', 'text', ['label' => __('Summary of Review'), 'required' => true, 'name' => 'title']);
     $fieldset->addField('detail', 'textarea', ['label' => __('Review'), 'required' => true, 'name' => 'detail', 'style' => 'height:24em;']);
     $form->setUseContainer(true);
     $form->setValues($review->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }
示例#8
0
 /**
  * Perform actions after object delete
  * Prepare rating data for reaggregate all data for reviews
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
 {
     parent::_afterDelete($object);
     if (!$this->_ratingData->isModuleEnabled('Magento_Review')) {
         return $this;
     }
     $data = $this->_getEntitySummaryData($object);
     $summary = array();
     foreach ($data as $row) {
         $clone = clone $object;
         $clone->addData($row);
         $summary[$clone->getStoreId()][$clone->getEntityPkValue()] = $clone;
     }
     $this->_reviewSummary->reAggregate($summary);
     return $this;
 }
示例#9
0
文件: Form.php 项目: opexsw/magento2
 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $data = $this->_reviewSession->getFormData(true);
     $data = new \Magento\Framework\Object((array) $data);
     // add logged in customer name as nickname
     if (!$data->getNickname()) {
         $customer = $this->_customerSession->getCustomerDataObject();
         if ($customer && $customer->getId()) {
             $data->setNickname($customer->getFirstname());
         }
     }
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->urlEncoder->encode($this->getUrl('*/*/*', ['_current' => true]) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', [Url::REFERER_QUERY_PARAM_NAME => $queryParam]));
     }
     $this->setTemplate('form.phtml')->assign('data', $data);
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function toOptionArray()
 {
     return $this->source->getReviewStatusesOptionArray();
 }