Ejemplo n.º 1
0
 public function testSave()
 {
     $data = ['sample' => ['sampleData', 'link' => ['linkData']]];
     $this->product->expects($this->once())->method('getDownloadableData')->will($this->returnValue($data));
     $this->typeHandler->expects($this->once())->method('save')->with($this->product, $data);
     $this->target->save($this->product);
 }
Ejemplo n.º 2
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param LinkInterface $link
  * @param bool $isGlobalScopeContent
  * @return int
  */
 protected function saveLink(\Magento\Catalog\Api\Data\ProductInterface $product, LinkInterface $link, $isGlobalScopeContent)
 {
     $linkData = ['link_id' => $link->getid() === null ? 0 : $link->getid(), 'is_delete' => 0, 'type' => $link->getLinkType(), 'sort_order' => $link->getSortOrder(), 'title' => $link->getTitle(), 'price' => $link->getPrice(), 'number_of_downloads' => $link->getNumberOfDownloads(), 'is_shareable' => $link->getIsShareable()];
     if ($link->getLinkType() == 'file' && $link->getLinkFile() === null) {
         $linkData['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($link->getLinkFileContent(), 'link_file')]);
     } elseif ($link->getLinkType() === 'url') {
         $linkData['link_url'] = $link->getLinkUrl();
     } else {
         //existing link file
         $linkData['file'] = $this->jsonEncoder->encode([['file' => $link->getLinkFile(), 'status' => 'old']]);
     }
     if ($link->getSampleType() == 'file' && $link->getSampleFile() === null) {
         $linkData['sample']['type'] = 'file';
         $linkData['sample']['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($link->getSampleFileContent(), 'link_sample_file')]);
     } elseif ($link->getSampleType() == 'url') {
         $linkData['sample']['type'] = 'url';
         $linkData['sample']['url'] = $link->getSampleUrl();
     }
     $downloadableData = ['link' => [$linkData]];
     $product->setDownloadableData($downloadableData);
     if ($isGlobalScopeContent) {
         $product->setStoreId(0);
     }
     $this->downloadableType->save($product);
     return $product->getLastAddedLinkId();
 }
Ejemplo n.º 3
0
 /**
  * @magentoDataFixture Magento/Downloadable/_files/product_downloadable_with_files.php
  * @magentoAppArea adminhtml
  */
 public function testSaveTypeSpecificData()
 {
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $product->setOrigData();
     $downloadableData = [];
     $links = $this->_model->getLinks($product);
     $this->assertNotEmpty($links);
     $samples = $this->_model->getSamples($product);
     $this->assertNotEmpty($samples->getData());
     $i = 0;
     foreach ($links as $link) {
         $i++;
         $linkData = $link->getData();
         $linkData['is_delete'] = 0;
         $linkData['type'] = \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE;
         $linkData['title'] = 'Updated downloadable link #' . $i;
         $downloadableData['link'][] = $linkData;
     }
     $i = 0;
     foreach ($samples as $sample) {
         $i++;
         $sampleData = $sample->getData();
         $sampleData['is_delete'] = 0;
         $sampleData['type'] = \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE;
         $sampleData['title'] = 'Updated downloadable sample #' . $i;
         $downloadableData['sample'][] = $sampleData;
     }
     $product->setDownloadableData($downloadableData);
     $this->_model->save($product);
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $expectedLink = ['default_price' => null, 'default_title' => null, 'is_shareable' => '2', 'link_file' => null, 'link_type' => 'file', 'link_url' => null, 'number_of_downloads' => '15', 'price' => '15.0000', 'product' => $product, 'product_id' => 1, 'sample_file' => null, 'sample_type' => 'file', 'sample_url' => null, 'sort_order' => '0', 'store_title' => 'Updated downloadable link #1', 'title' => 'Updated downloadable link #1', 'website_price' => '15.0000'];
     $links = $this->_model->getLinks($product);
     $this->assertNotEmpty($links);
     $this->assertCount(1, $links);
     $link = reset($links);
     foreach ($expectedLink as $key => $value) {
         $this->assertTrue($link->hasData($key), 'Key ' . $key . ' not exist!');
         $this->assertArrayHasKey($key, $link);
         $this->assertEquals($value, $link->getData($key));
     }
     $expectedSample = ['default_title' => null, 'product_id' => '1', 'sample_file' => null, 'sample_type' => 'file', 'sample_url' => null, 'sort_order' => '0', 'store_title' => 'Updated downloadable sample #1', 'title' => 'Updated downloadable sample #1'];
     $samples = $this->_model->getSamples($product);
     $this->assertNotEmpty($samples->getData());
     $this->assertEquals(1, $samples->count());
     /** @var \Magento\Downloadable\Model\Sample $sample */
     $sample = $samples->getFirstItem()->getData();
     foreach ($expectedSample as $key => $value) {
         $this->assertArrayHasKey($key, $sample);
         $this->assertEquals($value, $sample[$key]);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param SampleInterface $sample
  * @param bool $isGlobalScopeContent
  * @return int
  */
 protected function saveSample(\Magento\Catalog\Api\Data\ProductInterface $product, SampleInterface $sample, $isGlobalScopeContent)
 {
     $sampleData = ['sample_id' => $sample->getid() === null ? 0 : $sample->getid(), 'is_delete' => 0, 'type' => $sample->getSampleType(), 'sort_order' => $sample->getSortOrder(), 'title' => $sample->getTitle()];
     if ($sample->getSampleType() == 'file' && $sample->getSampleFile() === null) {
         $sampleData['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($sample->getSampleFileContent(), 'sample')]);
     } elseif ($sample->getSampleType() === 'url') {
         $sampleData['sample_url'] = $sample->getSampleUrl();
     } else {
         //existing file
         $sampleData['file'] = $this->jsonEncoder->encode([['file' => $sample->getSampleFile(), 'status' => 'old']]);
     }
     $downloadableData = ['sample' => [$sampleData]];
     $product->setDownloadableData($downloadableData);
     if ($isGlobalScopeContent) {
         $product->setStoreId(0);
     }
     $this->downloadableType->save($product);
     return $product->getLastAddedSampleId();
 }