Cdiscount / API-MarketPlace-SDK-PHP

15 stars 42 forks source link

Product -> Response -> ModelListResponse #53

Open Eayshwary opened 5 years ago

Eayshwary commented 5 years ago

this function

protected function _addProductModel($productModelXML) { $productModel = new ProductModel(intval($productModelXML['ModelId'])); $productModel->setCategoryCode($productModelXML['CategoryCode']); $productModel->setName($productModelXML['Name']); foreach ($productModelXML['Definition']['ListProperties']['a:KeyValueOfstringArrayOfstringty7Ep6D1'] as $keyValueXml) { $keyvalueObj = new KeyValueProperty($keyValueXml['a:Key']); foreach ($keyValueXml['a:Value']['a:string'] as $value) { $keyvalueObj->addValue($value); } $productModel->addKeyValueProperty($keyvalueObj); } if (isset($productModelXML['Definition']['MandatoryModelProperties']) && !SoapTools::isSoapValueNull($productModelXML['Definition']['MandatoryModelProperties']) && isset($productModelXML['Definition']['MandatoryModelProperties']['a:string'])) { var_dump($productModelXML['Definition']['MandatoryModelProperties']); foreach ($productModelXML['Definition']['MandatoryModelProperties']['a:string'] as $mandatoryModelProperty) { $productModel->addMandatoryModelProperty($mandatoryModelProperty); } } array_push($this->_modelList, $productModel); }

needs a var_dump removed as this displays the model list while calling this function and

if $productModelXML['Definition']['MandatoryModelProperties']['a:string'] this is not an array to which there is foreach loop on this statement --> there is fatal error

solution:

protected function _addProductModel($productModelXML) { $productModel = new ProductModel(intval($productModelXML['ModelId']));

    $productModel->setCategoryCode($productModelXML['CategoryCode']);
    $productModel->setName($productModelXML['Name']);

    foreach ($productModelXML['Definition']['ListProperties']['a:KeyValueOfstringArrayOfstringty7Ep6D1'] as $keyValueXml) {

        $keyvalueObj = new KeyValueProperty($keyValueXml['a:Key']);

        foreach ($keyValueXml['a:Value']['a:string'] as $value) {
            $keyvalueObj->addValue($value);
        }

        $productModel->addKeyValueProperty($keyvalueObj);
    }

    if (isset($productModelXML['Definition']['MandatoryModelProperties']) && !SoapTools::isSoapValueNull($productModelXML['Definition']['MandatoryModelProperties'])
        && isset($productModelXML['Definition']['MandatoryModelProperties']['a:string'])) {

        if (!is_array($productModelXML['Definition']['MandatoryModelProperties']['a:string'])) {
            $productModelXML['Definition']['MandatoryModelProperties']['a:string'] =
                array($productModelXML['Definition']['MandatoryModelProperties']['a:string']);
        }
        foreach ($productModelXML['Definition']['MandatoryModelProperties']['a:string'] as $mandatoryModelProperty) {
            $productModel->addMandatoryModelProperty($mandatoryModelProperty);
        }
    }

    array_push($this->_modelList, $productModel);
}