Esempio n. 1
0
 public function testValidate()
 {
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->assertTrue($this->_model->validate($product));
     $this->_model->getAttribute()->setIsRequired(true);
     try {
         $this->assertFalse($this->_model->validate($product));
         $this->_model->getAttribute()->setIsRequired(false);
     } catch (\Exception $e) {
         $this->_model->getAttribute()->setIsRequired(false);
         throw $e;
     }
 }
 /**
  * @param MediaBackendModel $mediaBackendModel
  * @param Product $product
  * @return Product
  */
 public function afterAfterSave(MediaBackendModel $mediaBackendModel, Product $product)
 {
     $mediaCollection = $this->getMediaEntriesDataCollection($product, $mediaBackendModel->getAttribute());
     if (!empty($mediaCollection)) {
         $videoDataCollection = $this->collectVideoData($mediaCollection);
         $this->saveVideoData($videoDataCollection, $product->getStoreId());
         $this->saveAdditionalStoreData($videoDataCollection);
     }
     return $product;
 }
Esempio n. 3
0
 /**
  * Duplicates gallery db values
  *
  * @param \Magento\Catalog\Model\Product\Attribute\Backend\Media $object
  * @param array $newFiles
  * @param int $originalProductId
  * @param int $newProductId
  * @return $this
  */
 public function duplicate($object, $newFiles, $originalProductId, $newProductId)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array('value_id', 'value'))->where('attribute_id = ?', $object->getAttribute()->getId())->where('entity_id = ?', $originalProductId);
     $valueIdMap = array();
     // Duplicate main entries of gallery
     foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
         $data = array('attribute_id' => $object->getAttribute()->getId(), 'entity_id' => $newProductId, 'value' => isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value']);
         $valueIdMap[$row['value_id']] = $this->insertGallery($data);
     }
     if (count($valueIdMap) == 0) {
         return $this;
     }
     // Duplicate per store gallery values
     $select = $this->_getReadAdapter()->select()->from($this->getTable(self::GALLERY_VALUE_TABLE))->where('value_id IN(?)', array_keys($valueIdMap));
     foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
         $row['value_id'] = $valueIdMap[$row['value_id']];
         $this->insertGalleryValueInStore($row);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function getAttribute()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAttribute');
     if (!$pluginInfo) {
         return parent::getAttribute();
     } else {
         return $this->___callPlugins('getAttribute', func_get_args(), $pluginInfo);
     }
 }