0

I have an issue ; Deprecated Functionality: explode(): Passing null to parameter #2 ($string). Can you please help?

 public function getEnabled()
{
 return $this->_dataHelper->getEnabled();
}
public function getRenderableAttributes()
{
 if (!$this->getEnabled()) {
 return [];
 }
 $attributeCode = $this->_dataHelper->getAttributeCode();
 $product = $this->getProduct();
 $selectedFeaturesRaw = $product->getData($attributeCode);
 $selectedFeaturesSplit = explode(',', $selectedFeaturesRaw);
 $attr = $product->getResource()->getAttribute($attributeCode);
 $selectedFeatures = [];
 foreach ($selectedFeaturesSplit as $selectedFeatureCode) {
 if ($attr->usesSource()) {
 $selectedFeatures[] = $attr->getSource()->getOptionText($selectedFeatureCode);
 }
 }
 if (empty($selectedFeatures)) {
 return [];
 }
 $features = [];
 $searchCriteria = $this->_searchCriteriaBuilder->addFilter('attribute_value', $selectedFeatures, 'in')->create();
 $searchResults = $this->_dataRepository->getList($searchCriteria);
 $features = array_map(function ($feature) {
 return $feature->getData();
 }, $searchResults->getItems());
 return $features;
}
asked Dec 18, 2022 at 18:00
0

2 Answers 2

0

Replace your code selectedFeaturesRaw = $product->getData($attributeCode);
with
$selectedFeaturesRaw = $product->getData($attributeCode) ?: '';

Finally, your code should look like the following:

public function getEnabled()
{
 return $this->_dataHelper->getEnabled();
}
public function getRenderableAttributes()
{
 if (!$this->getEnabled()) {
 return [];
 }
 $attributeCode = $this->_dataHelper->getAttributeCode();
 $product = $this->getProduct();
 $selectedFeaturesRaw = $product->getData($attributeCode) ?: '';
 $selectedFeaturesSplit = explode(',', $selectedFeaturesRaw);
 $attr = $product->getResource()->getAttribute($attributeCode);
 $selectedFeatures = [];
 foreach ($selectedFeaturesSplit as $selectedFeatureCode) {
 if ($attr->usesSource()) {
 $selectedFeatures[] = $attr->getSource()->getOptionText($selectedFeatureCode);
 }
 }
 if (empty($selectedFeatures)) {
 return [];
 }
 $features = [];
 $searchCriteria = $this->_searchCriteriaBuilder->addFilter('attribute_value', $selectedFeatures, 'in')->create();
 $searchResults = $this->_dataRepository->getList($searchCriteria);
 $features = array_map(function ($feature) {
 return $feature->getData();
 }, $searchResults->getItems());
 return $features;
}
answered Dec 18, 2022 at 18:22
0
0

Change below line.

 $selectedFeaturesSplit = explode(',', (string)$selectedFeaturesRaw);
answered Dec 19, 2022 at 13:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.