예제 #1
0
 /**
  * Check whether attribute instance (attribute, backend, frontend or source) has method and applicable
  *
  * @param AbstractAttribute|\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend|\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $instance
  * @param string $method
  * @param array $args array of arguments
  * @return boolean
  */
 protected function _isCallableAttributeInstance($instance, $method, $args)
 {
     if ($instance instanceof \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend && ($method == 'beforeSave' || $method == 'afterSave')) {
         $attributeCode = $instance->getAttribute()->getAttributeCode();
         if (isset($args[0]) && $args[0] instanceof \Magento\Framework\DataObject && $args[0]->getData($attributeCode) === false) {
             return false;
         }
     }
     return parent::_isCallableAttributeInstance($instance, $method, $args);
 }
예제 #2
0
 public function getValue(\Magento\Framework\DataObject $object)
 {
     if ($this->getConfigField('input') !== 'multiselect') {
         return parent::getValue($object);
     }
     return $this->getValuesAsHtmlList($object);
 }
예제 #3
0
 /**
  * 2015-09-20
  * Цель метода — перевод экранных названий свойств (товаров, разделов, покупателей и т.п.).
  * @see \Df\Framework\Plugin\Data\Form\Element\AbstractElement::afterGetEscapedValue()
  * @see \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::getLabel()
  * @param Sb $sb
  * @param string $result
  * @return string
  */
 public function afterGetLabel(Sb $sb, $result)
 {
     df_state()->attributeSet($sb->getAttribute());
     /** @var string[] $result */
     /**
      * 2015-09-21
      * Важно сразу привести результат к строке,
      * потому что иначе @see __() вернёт объект и отложит перевод на потом,
      * когда мы уже выпадем из контекста свойства (finally ниже).
      */
     try {
         $result = (string) __($result);
     } finally {
         df_state()->attributeUnset();
     }
     return $result;
 }
예제 #4
0
 /**
  * Retrieve attribute value
  *
  * @param \Magento\Framework\DataObject $object
  * @return mixed
  */
 public function getValue(\Magento\Framework\DataObject $object)
 {
     $data = '';
     $value = parent::getValue($object);
     if ($value) {
         $data = $this->_localeDate->formatDateTime(new \DateTime($value), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE);
     }
     return $data;
 }
예제 #5
0
파일: Datetime.php 프로젝트: aiesh/magento2
 /**
  * Retrieve attribute value
  *
  * @param \Magento\Framework\Object $object
  * @return mixed
  */
 public function getValue(\Magento\Framework\Object $object)
 {
     $data = '';
     $value = parent::getValue($object);
     $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM);
     if ($value) {
         try {
             $data = $this->_localeDate->date($value, \Zend_Date::ISO_8601, null, false)->toString($format);
         } catch (\Exception $e) {
             $data = $this->_localeDate->date($value, null, null, false)->toString($format);
         }
     }
     return $data;
 }
예제 #6
0
 public function testGetItems()
 {
     $attributeCode = 'attributeCode';
     $attributeValue = 'attributeValue';
     $attributeLabel = 'attributeLabel';
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->request->expects($this->once())->method('getParam')->with($attributeCode)->will($this->returnValue($attributeValue));
     $this->frontend->expects($this->once())->method('getOption')->with($attributeValue)->will($this->returnValue($attributeLabel));
     $filterItem = $this->createFilterItem(0, $attributeLabel, $attributeValue, 0);
     $this->state->expects($this->once())->method('addFilter')->with($filterItem)->will($this->returnSelf());
     $expectedFilterItems = [];
     $result = $this->target->apply($this->request)->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItemsWithoutApply()
 {
     $attributeCode = 'attributeCode';
     $selectedOptions = [['label' => 'selectedOptionLabel1', 'value' => 'selectedOptionValue1', 'count' => 25], ['label' => 'selectedOptionLabel2', 'value' => 'selectedOptionValue2', 'count' => 13], ['label' => 'selectedOptionLabel3', 'value' => 'selectedOptionValue3', 'count' => 10]];
     $facetedData = ['selectedOptionValue1' => ['count' => 10], 'selectedOptionValue2' => ['count' => 45], 'selectedOptionValue3' => ['count' => 50]];
     $builtData = [['label' => $selectedOptions[0]['label'], 'value' => $selectedOptions[0]['value'], 'count' => $facetedData[$selectedOptions[0]['value']]['count']], ['label' => $selectedOptions[1]['label'], 'value' => $selectedOptions[1]['value'], 'count' => $facetedData[$selectedOptions[1]['value']]['count']], ['label' => $selectedOptions[2]['label'], 'value' => $selectedOptions[2]['value'], 'count' => $facetedData[$selectedOptions[2]['value']]['count']]];
     $this->attribute->expects($this->exactly(2))->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->frontend->expects($this->once())->method('getSelectOptions')->will($this->returnValue($selectedOptions));
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->will($this->returnValue($facetedData));
     $this->itemDataBuilder->expects($this->at(0))->method('addItemData')->with($selectedOptions[0]['label'], $selectedOptions[0]['value'], $facetedData[$selectedOptions[0]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->at(1))->method('addItemData')->with($selectedOptions[1]['label'], $selectedOptions[1]['value'], $facetedData[$selectedOptions[1]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->once())->method('build')->will($this->returnValue($builtData));
     $this->fulltextCollection->expects($this->once())->method('getSize')->will($this->returnValue(50));
     $expectedFilterItems = [$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']), $this->createFilterItem(1, $builtData[1]['label'], $builtData[1]['value'], $builtData[1]['count']), $this->createFilterItem(2, $builtData[2]['label'], $builtData[2]['value'], $builtData[2]['count'])];
     $result = $this->target->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
예제 #8
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItemsOnlyWithResults()
 {
     $attributeCode = 'attributeCode';
     $selectedOptions = [['label' => 'selectedOptionLabel1', 'value' => 'selectedOptionValue1'], ['label' => 'selectedOptionLabel2', 'value' => 'selectedOptionValue2']];
     $facetedData = ['selectedOptionValue1' => ['count' => 10], 'selectedOptionValue2' => ['count' => 0]];
     $builtData = [['label' => $selectedOptions[0]['label'], 'value' => $selectedOptions[0]['value'], 'count' => $facetedData[$selectedOptions[0]['value']]['count']]];
     $this->attribute->expects($this->atLeastOnce())->method('getAttributeCode')->willReturn($attributeCode);
     $this->attribute->expects($this->atLeastOnce())->method('getIsFilterable')->willReturn(AbstractFilter::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS);
     $this->attribute->expects($this->atLeastOnce())->method('getFrontend')->will($this->returnValue($this->frontend));
     $this->target->setAttributeModel($this->attribute);
     $this->frontend->expects($this->once())->method('getSelectOptions')->willReturn($selectedOptions);
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->willReturn($facetedData);
     $this->fulltextCollection->expects($this->once())->method('getSize')->will($this->returnValue(50));
     $this->itemDataBuilder->expects($this->once())->method('addItemData')->with($selectedOptions[0]['label'], $selectedOptions[0]['value'], $facetedData[$selectedOptions[0]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->once())->method('build')->willReturn($builtData);
     $expectedFilterItems = [$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count'])];
     $result = $this->target->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
예제 #9
0
 public function getValue(\Magento\Framework\DataObject $object)
 {
     $value = parent::getValue($object);
     return sprintf('<strong>%s</strong>', $value);
 }