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;
}
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;
}
0
0

Change below line.

    $selectedFeaturesSplit = explode(',', (string)$selectedFeaturesRaw);

Your Answer

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.