Пример #1
0
 /**
  * Format total value based on order currency
  *
  * @param \Magento\Framework\DataObject $total
  * @return string
  */
 public function formatValue($total)
 {
     if (!$total->getIsFormated()) {
         return $this->_adminHelper->displayPrices($this->getOrder(), $total->getBaseValue(), $total->getValue());
     }
     return $total->getValue();
 }
Пример #2
0
 /**
  * Method is needed for specific actions to change given quote options values
  * according current product type logic
  * Example: the catalog inventory validation of decimal qty can change qty to int,
  * so need to change quote item qty option value too.
  *
  * @param   array $options
  * @param   \Magento\Framework\DataObject $option
  * @param   mixed $value
  * @param   \Magento\Catalog\Model\Product $product
  * @return $this
  */
 public function updateQtyOption($options, \Magento\Framework\DataObject $option, $value, $product)
 {
     $optionProduct = $option->getProduct($product);
     $optionUpdateFlag = $option->getHasQtyOptionUpdate();
     $optionCollection = $this->getOptionsCollection($product);
     $selections = $this->getSelectionsCollection($optionCollection->getAllIds(), $product);
     foreach ($selections as $selection) {
         if ($selection->getProductId() == $optionProduct->getId()) {
             foreach ($options as &$option) {
                 if ($option->getCode() == 'selection_qty_' . $selection->getSelectionId()) {
                     if ($optionUpdateFlag) {
                         $option->setValue(intval($option->getValue()));
                     } else {
                         $option->setValue($value);
                     }
                 }
             }
         }
     }
     return $this;
 }
Пример #3
0
 /**
  * Add field to Options form based on parameter configuration
  *
  * @param \Magento\Framework\DataObject $parameter
  * @return \Magento\Framework\Data\Form\Element\AbstractElement
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _addField($parameter)
 {
     $form = $this->getForm();
     $fieldset = $this->getMainFieldset();
     //$form->getElement('options_fieldset');
     // prepare element data with values (either from request of from default values)
     $fieldName = $parameter->getKey();
     $data = ['name' => $form->addSuffixToName($fieldName, 'parameters'), 'label' => __($parameter->getLabel()), 'required' => $parameter->getRequired(), 'class' => 'widget-option', 'note' => __($parameter->getDescription())];
     if ($values = $this->getWidgetValues()) {
         $data['value'] = isset($values[$fieldName]) ? $values[$fieldName] : '';
     } else {
         $data['value'] = $parameter->getValue();
         //prepare unique id value
         if ($fieldName == 'unique_id' && $data['value'] == '') {
             $data['value'] = md5(microtime(1));
         }
     }
     // prepare element dropdown values
     if ($values = $parameter->getValues()) {
         // dropdown options are specified in configuration
         $data['values'] = [];
         foreach ($values as $option) {
             $data['values'][] = ['label' => __($option['label']), 'value' => $option['value']];
         }
         // otherwise, a source model is specified
     } elseif ($sourceModel = $parameter->getSourceModel()) {
         $data['values'] = $this->_sourceModelPool->get($sourceModel)->toOptionArray();
     }
     // prepare field type or renderer
     $fieldRenderer = null;
     $fieldType = $parameter->getType();
     // hidden element
     if (!$parameter->getVisible()) {
         $fieldType = 'hidden';
         // just an element renderer
     } elseif ($fieldType && $this->_isClassName($fieldType)) {
         $fieldRenderer = $this->getLayout()->createBlock($fieldType);
         $fieldType = $this->_defaultElementType;
     }
     // instantiate field and render html
     $field = $fieldset->addField($this->getMainFieldsetHtmlId() . '_' . $fieldName, $fieldType, $data);
     if ($fieldRenderer) {
         $field->setRenderer($fieldRenderer);
     }
     // extra html preparations
     if ($helper = $parameter->getHelperBlock()) {
         $helperBlock = $this->getLayout()->createBlock($helper->getType(), '', ['data' => $helper->getData()]);
         if ($helperBlock instanceof \Magento\Framework\DataObject) {
             $helperBlock->setConfig($helper->getData())->setFieldsetId($fieldset->getId())->prepareElementHtml($field);
         }
     }
     // dependencies from other fields
     $dependenceBlock = $this->getChildBlock('form_after');
     $dependenceBlock->addFieldMap($field->getId(), $fieldName);
     if ($parameter->getDepends()) {
         foreach ($parameter->getDepends() as $from => $row) {
             $values = isset($row['values']) ? array_values($row['values']) : (string) $row['value'];
             $dependenceBlock->addFieldDependence($fieldName, $from, $values);
         }
     }
     return $field;
 }
Пример #4
0
 /**
  * Format total value based on order currency
  *
  * @param   \Magento\Framework\DataObject $total
  * @return  string
  */
 public function formatValue($total)
 {
     if (!$total->getIsFormated()) {
         return $this->getOrder()->formatPrice($total->getValue());
     }
     return $total->getValue();
 }