public function testGetLabelWithoutCustomText()
 {
     $category = 'Some text';
     $id = 1;
     $idPath = 'id/' . $id;
     $store = 1;
     $this->block->setData('id_path', $idPath);
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->entityResource->expects($this->once())->method('getAttributeRawValue')->with($id, 'name', $store)->will($this->returnValue($category));
     $this->assertEquals($category, $this->block->getLabel());
 }
Exemple #2
0
 /**
  * Prepare label using passed text as parameter.
  * If anchor text was not specified get entity name from DB.
  *
  * @return string
  */
 public function getLabel()
 {
     if (!$this->_anchorText) {
         if ($this->getData('anchor_text')) {
             $this->_anchorText = $this->getData('anchor_text');
         } elseif ($this->_entityResource) {
             $idPath = explode('/', $this->_getData('id_path'));
             if (isset($idPath[1])) {
                 $id = $idPath[1];
                 if ($id) {
                     $this->_anchorText = $this->_entityResource->getAttributeRawValue($id, 'name', $this->_storeManager->getStore());
                 }
             }
         }
     }
     return $this->_anchorText;
 }
Exemple #3
0
 /**
  * Process category data after save category object
  * save related products ids and update path value
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\DataObject $object)
 {
     /**
      * Add identifier for new category
      */
     if (substr($object->getPath(), -1) == '/') {
         $object->setPath($object->getPath() . $object->getId());
         $this->_savePath($object);
     }
     $this->_saveCategoryProducts($object);
     return parent::_afterSave($object);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function validate($object)
 {
     //validate attribute set entity type
     $entityType = $this->typeFactory->create()->loadByCode(\Magento\Catalog\Model\Product::ENTITY);
     $attributeSet = $this->setFactory->create()->load($object->getAttributeSetId());
     if ($attributeSet->getEntityTypeId() != $entityType->getId()) {
         return ['attribute_set' => 'Invalid attribute set entity type'];
     }
     return parent::validate($object);
 }