/** * Get item qty * * @param \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject * @param callable $proceed * @param \Magento\Framework\Object $item * * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetItemQty(\Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject, \Closure $proceed, \Magento\Framework\Object $item) { if ($item->getProduct()->getTypeId() == \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) { return ''; } return $proceed($item); }
/** * Validate Product Rule Condition * * @param \Magento\Framework\Object $object * @return bool */ public function validate(\Magento\Framework\Object $object) { //@todo reimplement this method when is fixed MAGETWO-5713 /** @var \Magento\Catalog\Model\Product $product */ $product = $object->getProduct(); if (!$product instanceof \Magento\Catalog\Model\Product) { $product = $this->_productFactory->create()->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); return parent::validate($product); }
/** * Render single action as link html * * @param array $action * @param \Magento\Framework\Object $row * @return string|false */ protected function _toLinkHtml($action, \Magento\Framework\Object $row) { $product = $row->getProduct(); if (isset($action['process']) && $action['process'] == 'configurable') { if ($product->canConfigure()) { $style = ''; $onClick = sprintf('onclick="return %s.configureItem(%s)"', $action['control_object'], $row->getId()); return sprintf('<a href="%s" %s %s>%s</a>', $action['url'], $style, $onClick, $action['caption']); } else { return false; } } else { return parent::_toLinkHtml($action, $row); } }
/** * Check availability of giftmessages for specified entity. * * @param string $type * @param \Magento\Framework\Object $entity * @param \Magento\Store\Model\Store|int|null $store * @return bool|string|null */ public function isMessagesAvailable($type, \Magento\Framework\Object $entity, $store = null) { if ($type == 'items') { $items = $entity->getAllItems(); if (!is_array($items) || empty($items)) { return $this->_scopeConfig->getValue(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); } if ($entity instanceof \Magento\Sales\Model\Quote) { $_type = $entity->getIsMultiShipping() ? 'address_item' : 'item'; } else { $_type = 'order_item'; } foreach ($items as $item) { if ($item->getParentItem()) { continue; } if ($this->isMessagesAvailable($_type, $item, $store)) { return true; } } } elseif ($type == 'item') { return $this->_getDependenceFromStoreConfig($entity->getProduct()->getGiftMessageAvailable(), $store); } elseif ($type == 'order_item') { return $this->_getDependenceFromStoreConfig($entity->getGiftMessageAvailable(), $store); } elseif ($type == 'address_item') { $storeId = is_numeric($store) ? $store : $this->_storeManager->getStore($store)->getId(); if (!$this->isCached('address_item_' . $entity->getProductId())) { $this->setCached('address_item_' . $entity->getProductId(), $this->_productFactory->create()->setStoreId($storeId)->load($entity->getProductId())->getGiftMessageAvailable()); } return $this->_getDependenceFromStoreConfig($this->getCached('address_item_' . $entity->getProductId()), $store); } else { return $this->_scopeConfig->getValue(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); } return false; }
/** * Can specify specific actions for ability to change given quote options values * Example: cataloginventory decimal qty validation may change qty to int, * so need to change quote item qty option value. * * @param \Magento\Framework\Object $option * @param int|float|null $value * @return $this */ public function updateQtyOption(\Magento\Framework\Object $option, $value) { $optionProduct = $option->getProduct(); $options = $this->getQtyOptions(); if (isset($options[$optionProduct->getId()])) { $options[$optionProduct->getId()]->setValue($value); } $this->getProduct()->getTypeInstance()->updateQtyOption($this->getOptions(), $option, $value, $this->getProduct()); return $this; }
/** * 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\Object $option * @param mixed $value * @param \Magento\Catalog\Model\Product $product * @return $this */ public function updateQtyOption($options, \Magento\Framework\Object $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; }