Skip to content

Commit

Permalink
ENGCOM-4684: Fixed Changing sample for downloadable product failure #…
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaschenko authored Apr 23, 2019
2 parents f927dba + 5454d6d commit 26e3142
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions app/code/Magento/Downloadable/Model/SampleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* Class SampleRepository
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SampleRepository implements \Magento\Downloadable\Api\SampleRepositoryInterface
Expand Down Expand Up @@ -100,7 +101,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getList($sku)
{
Expand Down Expand Up @@ -209,6 +210,8 @@ public function save(
}

/**
* Save sample.
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param SampleInterface $sample
* @param bool $isGlobalScopeContent
Expand Down Expand Up @@ -257,6 +260,8 @@ protected function saveSample(
}

/**
* Update sample.
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param SampleInterface $sample
* @param bool $isGlobalScopeContent
Expand Down Expand Up @@ -308,15 +313,18 @@ protected function updateSample(
$existingSample->setTitle($sample->getTitle());
}

if ($sample->getSampleType() === 'file' && $sample->getSampleFileContent() === null) {
$sample->setSampleFile($existingSample->getSampleFile());
if ($sample->getSampleType() === 'file'
&& $sample->getSampleFileContent() === null
&& $sample->getSampleFile() !== null
) {
$existingSample->setSampleFile($sample->getSampleFile());
}
$this->saveSample($product, $sample, $isGlobalScopeContent);
return $existingSample->getId();
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function delete($id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ public function testUpdateDownloadableProductSamplesWithNewFile()
'title' => 'sample2_updated',
'sort_order' => 2,
'sample_type' => 'file',
'sample_file_content' => [
'name' => 'sample2.jpg',
'file_data' => base64_encode(file_get_contents($this->testImagePath)),
],
];

$response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["downloadable_product_samples"] =
Expand Down Expand Up @@ -606,7 +610,7 @@ protected function deleteProductBySku($productSku)
protected function saveProduct($product)
{
if (isset($product['custom_attributes'])) {
for ($i=0; $i<sizeof($product['custom_attributes']); $i++) {
for ($i = 0, $iMax = count($product['custom_attributes']); $i < $iMax; $i++) {
if ($product['custom_attributes'][$i]['attribute_code'] == 'category_ids'
&& !is_array($product['custom_attributes'][$i]['value'])
) {
Expand Down

0 comments on commit 26e3142

Please sign in to comment.