Load product by attribute i have using the following code
$attribute ='test1';
$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
$product =$objectManager->get('Magento\Catalog\Model\Product');
$product = $product->loadByAttribute('attributename',$attribute]);
but i have the format of values in attribute name field like
test1|test2|test3
then how do i check this loadByAttribute() method
<?php
namespace Vendor\Module\Controller\Adminhtml\EditComments;
use Magento\Framework\App\Action\Action;
use Magento\Backend\App\Action\Context;
use Vendor\Module\Model\ResourceModel\Post\CollectionFactory;
use Magento\Framework\Controller\ResultFactory;
class SaveEdit extends \Magento\Backend\App\Action
{
const URL_PATH_EDIT = 'catalog/product/edit';
protected $_modelFactory;
protected $urlBuilder;
public function __construct(
Context $context,
\Magento\Framework\UrlInterface $urlBuilder,
CollectionFactory $modelFactory
) {
parent::__construct($context);
$this->_modelFactory = $modelFactory;
$this->urlBuilder = $urlBuilder;
}
public function execute()
{
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$data = $this->getRequest()->getParam('custom_table');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product');
$product = $product->loadByAttribute('customattribute',$data['customattribute']);
// echo $data['customattribute'];
// echo "<pre>";
// print_r(get_class_methods($product));
//die;
$productId = $product->getId();
if (isset($data['customattribute'])) {
$collections = $this->_modelFactory->create();
foreach ($collections as $model) {
$model = $model->load($data['customattribute']);
$model->setData('customattribute', $data['customattribute']);
$model->setData('comments', $data['comments']);
$model->save();
}
}
$this->messageManager->addSuccess(__('comments has been updated.'));
if ($productId) {
$resultRedirect->setPath(
'catalog/product/edit',
['id' => $productId]
);
}
//$resultRedirect->setUrl($this->_redirect->getRefererUrl());
return $resultRedirect;
}
}
$product = $product->loadByAttribute('attributename',$attribute]); echo $product . "|";