我是magento2的新用户,我想使用Magento2内置产品评论扩展程序的默认布局和功能来创建我的自定义产品评论扩展程序。
我正在考虑创建Magento_Review buit-in扩展的克隆作为我的自定义productreview扩展。
这是正确的方法吗?
由于
答案 0 :(得分:2)
您需要更多地解释模块的用例。
但要回答你的问题,创建核心模块的克隆并不是正确的方法。
Magento 2是非常可扩展的,所以简而言之,我认为你应该能够通过实现一个自定义模块来获得你想要的东西,该模块使用插件,依赖注入,观察者...来扩展/修改核心Magento产品评论的方式的工作原理。
这应该是一个很好的起点:http://devdocs.magento.com/guides/v2.2/extension-dev-guide/module-development.html
答案 1 :(得分:1)
您可以在应用程序\ code {Namespace} {ModuleName} \ Block \ Adminhtml \ Edit中使用from.php代码开始
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Adminhtml Review Edit Form
*/
namespace {Namespace}\{ModuleName}\Block\Adminhtml\Edit;
class Form extends \Magento\Review\Block\Adminhtml\Edit\Form
{
/**
* Prepare edit review form
*
* @return $this
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareForm()
{
//die('over write');
$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(
'created_at',
'date',
[
'name' => 'created_at',
'title' => __('CreateAt'),
'label' => __('CreateAt'),
'maxlength' => '50',
'required' => true,
'date_format' => 'yyyy-MM-dd'
]
);
$fieldset->addField(
'summary-rating',
'note',
[
'label' => __('Summary Rating'),
'text' => $this->getLayout()->createBlock(
\Magento\Review\Block\Adminhtml\Rating\Summary::class
)->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::class
)->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::class
);
$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);
}
}