1

I have listed all the reviews of the merchant in the frontend. I want to remove the particular review from the list. So I have added a remove request button.

When a merchant clicks on a button an email should be send to all admin users.

I have implemented this on ajax call.

But I am not able to achieve this in Magento2

My Code:

view.phtml file:

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession    = $objectManager->get('\Magento\Customer\Model\Session');  
//$customer_name      = $customerSession->getCustomer()->getName();
$getMerchantid        = $customerSession->getCustomer()->getId();
    if (!empty($getMerchantid)) 
    {?>
    <div class="row">
          <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">

      <?php 
        $collection = $block->getReviewList();
      //echo $collection->count();
            // $collection = $objectManager->create('Webkul\Marketplace\Model\Feedback')->getCollection()
      // ->addFieldToFilter('seller_id',$getMerchantid);
      //  echo "<pre>";
            //  print_r($collection);
      //  echo "</pre>";
      ?>
      <?php if(count($collection) > 0){?>


        <div class="title-review"><span>Reviews</span></div>
        <?php 

      // check the count of the collection 
        }  else { ?><p class="empty_record">No Reviews Found</p> <?php } ?>

        <form class="" action="<?php echo $block->getBaseUrl(); ?>marketplace/account/review" method="get">
        <div class ="table-responsive">
        <table>                 
          <tbody>
            <?php 
            $i = 1;    
            foreach ($collection as $key => $data):?>
            <tr id="rules_<?php echo $data['entity_id']; ?>">
              <td rowspan="2" width="2%" data-th="Title" class="col code">
              <?php
              $num_padded = sprintf("%02d",$i++);
              echo $num_padded;
              ?>
              </td>
              <td width="20%">
                <strong>Rating</strong> <br/>

            <?php

            $starNumbervalue = round(($data['feed_price']/20), 1, PHP_ROUND_HALF_UP);

            for ($x = 1; $x <= $starNumbervalue; $x++) {
                echo '<li><i class="fa fa-star"></i></li>';
            }
            if (strpos($starNumbervalue, '.')) {
                echo '<li><i class="fa fa-star-half-o"></i></li>';
                $x++;
            }
            while ($x <= 5) {
                echo '<li><i class="fa fa-star-o"></i></li>';
                $x++;
            }?>
            <?php echo round(($data['feed_price']/20), 1, PHP_ROUND_HALF_UP); ?>                    
              </td>
                            <td width="58%" data-th="Anchor" class="col amount">
                                <strong>Feed Review</strong><br/>
                                <?php echo $data['feed_review']; ?>
                            </td>
              <td rowspan="2" width="20%" class="btn_remove">
                  <button class="search_btn delete_review_ratings" width="20" data-id="<?php echo $data['entity_id']; ?>" title="Remove">Remove Request</button>

              </td>
          </tr>
          <tr>
              <td width="200px">
                <strong>Customer Name</strong><br/>
                <?php echo $data['feed_nickname']; ?>
              </td>

              <td colspan="2" class="status_sec">
                <div width="200px">
                  <strong>Created</strong><br/>
                  <?php
                     $createdAt = $data['created_at'];
                     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                     $DateLoader = $objectManager->get('\Magento\Framework\Stdlib\DateTime\TimezoneInterface');
                     $createdAt = $DateLoader->date(new \DateTime($createdAt));
                     echo $dateAsString = $createdAt->format('F j, Y h:i:s a');
                  ?>
                 <br/>
                  <!-- 10:32:56 am -->
                </div>
                <div width="200px">
                  <strong>Status</strong><br/>
                       <?php 
                        if ($data['status'] == 1) 
                        {
                          echo "Approved";
                        }
                        else
                        {
                          echo "Disapproved";
                        }
                        ?>
                </div>
              </td>             
              </tr>
              <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
    </form>

<script type="text/javascript">
  require([
   "jquery", 
   "mage/calendar" 
   ], 
 function($)
 {
 $(".delete_review_ratings").click(function () 
    {
      var removeReviewId =  $(this).attr('data-id');
      if (removeReviewId != '') 
      {
        $.ajax(
        {
          type: "POST",
          url:  "<?php echo $block->getBaseUrl().'customajax/index/'?>",
          dataType: "json",
          data: {removeReviewId: removeReviewId},
          beforeSend:function()
          {
            return confirm("Are you sure you want to send remove request?");
            $(this).attr("disabled", true);
          },
          success: function (data) 
          {
            alert("You request has been sent successfully");
            //$("#rules_"+removeReviewId).remove();   
          }
        });
      }
    });
});

</script>

controller ajax file:

<?php

namespace Amy\CustomAjax\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Mail\Template\TransportBuilder;

//class Deletereviewratings extends Action

class Deletereviewratings extends \Magento\Framework\App\Action\Action

{

   protected $_userFactory;

   public function __construct(
    \Magento\Backend\App\Action\Context $context,
    TransportBuilder $transportBuilder,
    UserCollectionFactory $userFactory
   ) {

        $this->transportBuilder = $transportBuilder;
        $this->_userFactory = $userFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        echo "got review ratings";


        $data = $this->getRequest()->getParams();

        $helper = $this->_objectManager->get('Webkul\Marketplace\Helper\Data');

        $sellerName = $this->_customerSession->getCustomer()->getName();
        $sellerEmail = $this->_customerSession->getCustomer()->getEmail();


        $adminStoremail = $helper->getAdminEmailId();
        $adminEmail = $adminStoremail ? $adminStoremail : $helper->getDefaultTransEmailId();

        $emailTemplateVariables = [];
        $senderInfo = [];
        $receiverInfo = [];
        $emailTemplateVariables['myvar1'] = $adminUsername;
        $emailTemplateVariables['myvar2'] = $sellerName;

        $senderInfo = [
            'name' => $sellerName,
            'email' => $sellerEmail,
        ];
        $receiverInfo = [

            'email' => $adminEmail,
        ];

        $this->_objectManager->create(
            'Webkul\Marketplace\Helper\Email'
        )->sendRemoveReviewRequestMail(
            $emailTempVariables,
            $senderInfo,
            $receiverInfo
        );

        $this->messageManager->addSuccess(__('Your email has been sent successfully.'));

     }


}

?>

Any help would be appreciated.

0

Here I found an answer on my own, may be useful to others:

<?php

namespace Amy\CustomAjax\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Mail\Template\TransportBuilder;

class Deletereviewratings extends Action

{

   //protected $_userFactory;
    protected $transportBuilder;

   public function __construct(
    \Magento\Backend\App\Action\Context $context,
    TransportBuilder $transportBuilder
    //UserCollectionFactory $userFactory
   ) {

        $this->transportBuilder = $transportBuilder;
        //$this->_userFactory = $userFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        echo "got review ratings";

        $getReviewId         = $this->getRequest()->getParam('removeReviewId');
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
        $connection = $resource->getConnection();
        $tableName = $resource->getTableName('marketplace_datafeedback');
        $read = "Select * FROM " . $tableName . " where entity_id=" . $getReviewId;

        $result = $connection->fetchAll($read);
        $postData = $result[0];
        $feedId =$postData['entity_id'];
        $feedreview =$postData['feed_review'];
        $feedsellerID =$postData['seller_id'];


        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession    = $objectManager->get('\Magento\Customer\Model\Session');  
        $customer_name      = $customerSession->getCustomer()->getName();
        $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
        $userModel = $objectManager->create('Magento\User\Model\User')->getCollection();
        foreach ($userModel as $value) {
        $adminEmail = $value['email'];
        $adminName = $value['firstname'];


        $consumer_email = "sample@gmail.com";
        $requestData['mail_subj'] = "Remove Review Request From Seller";
        $requestData['hello_txt'] = "Hello " . $adminName;
        $requestData['message'] = "Please check the New Seller Review Remove request listed below.";
        $requestData['feedreview'] = $feedreview ;
        $requestData['sellerid'] = $feedsellerID ;
        $requestData['sellername'] = $customer_name ;
        $postObj = new \Magento\Framework\DataObject();
        $postObj->setData($requestData);

        $transport = $this->transportBuilder
            ->setTemplateIdentifier('marketplace_email_review_remove_request_template')
            ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
            ->setTemplateVars(['data' => $postObj])
            ->setFrom(['name' => "Remove Review Request From Merchant", 'email' => $consumer_email])
            ->addTo($adminEmail)
            ->getTransport();

        $transport->sendMessage();


        }


     }


}

?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.