Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Changing sample for downloadable product failure #19806

Merged
merged 3 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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