本文整理匯總了PHP中Magento\Sales\Model\Order\Item::getProduct方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getProduct方法的具體用法?PHP Item::getProduct怎麽用?PHP Item::getProduct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Sales\Model\Order\Item
的用法示例。
在下文中一共展示了Item::getProduct方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isItemAvailableForReorder
/**
* Check item product availability for reorder
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @return boolean
*/
protected function isItemAvailableForReorder(\Magento\Sales\Model\Order\Item $orderItem)
{
try {
$stockItem = $this->stockRegistry->getStockItem($orderItem->getProduct()->getId(), $orderItem->getStore()->getWebsiteId());
return $stockItem->getIsInStock();
} catch (\Magento\Framework\Exception\NoSuchEntityException $noEntityException) {
return false;
}
}
示例2: isItemAvailableForReorder
/**
* Check item product availability for reorder
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @return boolean
*/
public function isItemAvailableForReorder(\Magento\Sales\Model\Order\Item $orderItem)
{
if ($orderItem->getProduct()) {
return $this->stockItemService->getIsInStock($orderItem->getProduct()->getId());
}
return false;
}
示例3: buildItemName
/**
* Returns the name for a sales item.
* Configurable products will have their chosen options added to their name.
* Bundle products will have their chosen child product names added.
* Grouped products will have their parents name prepended.
* All others will have their own name only.
*
* @param Item $item the sales item model.
*
* @return string
*/
protected function buildItemName(Item $item)
{
$name = $item->getName();
$optNames = array();
if ($item->getProductType() === Type::TYPE_SIMPLE) {
$type = $item->getProduct()->getTypeInstance();
$parentIds = $type->getParentIdsByChild($item->getProductId());
// If the product has a configurable parent, we assume we should tag
// the parent. If there are many parent IDs, we are safer to tag the
// products own name alone.
if (count($parentIds) === 1) {
$attributes = $item->getBuyRequest()->getData('super_attribute');
if (is_array($attributes)) {
foreach ($attributes as $id => $value) {
/** @var Attribute $attribute */
$attribute = $this->_objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->load($id);
$label = $attribute->getSource()->getOptionText($value);
if (!empty($label)) {
$optNames[] = $label;
}
}
}
}
} elseif ($item->getProductType() === Configurable::TYPE_CODE) {
$opts = $item->getProductOptionByCode('attributes_info');
if (is_array($opts)) {
foreach ($opts as $opt) {
if (isset($opt['value']) && is_string($opt['value'])) {
$optNames[] = $opt['value'];
}
}
}
} elseif ($item->getProductType() === Type::TYPE_BUNDLE) {
$opts = $item->getProductOptionByCode('bundle_options');
if (is_array($opts)) {
foreach ($opts as $opt) {
if (isset($opt['value']) && is_array($opt['value'])) {
foreach ($opt['value'] as $val) {
$qty = '';
if (isset($val['qty']) && is_int($val['qty'])) {
$qty .= $val['qty'] . ' x ';
}
if (isset($val['title']) && is_string($val['title'])) {
$optNames[] = $qty . $val['title'];
}
}
}
}
}
} elseif ($item->getProductType() === Grouped::TYPE_CODE) {
$config = $item->getProductOptionByCode('super_product_config');
if (isset($config['product_id'])) {
/** @var Product $parent */
$parent = $this->_objectManager->get('Magento\\Catalog\\Model\\Product')->load($config['product_id']);
$parentName = $parent->getName();
if (!empty($parentName)) {
$name = $parentName . ' - ' . $name;
}
}
}
if (!empty($optNames)) {
$name .= ' (' . implode(', ', $optNames) . ')';
}
return $name;
}
示例4: makeProduct
/**
* @param Item $item
* @return Product
*/
protected function makeProduct(Item $item)
{
$product = SignifydModel::Make("\\Signifyd\\Models\\Product");
$product->itemId = $item->getSku();
$product->itemName = $item->getName();
$product->itemPrice = $item->getPrice();
$product->itemQuantity = (int) $item->getQtyOrdered();
$product->itemUrl = $item->getProduct()->getProductUrl();
$product->itemWeight = $item->getProduct()->getWeight();
return $product;
}
示例5: getOrderItemVariables
/**
* Retrieve tracking variables for an order item
*
* @param \Magento\Sales\Model\Order\Item $item The order item
*
* @return array
*/
private function getOrderItemVariables($item)
{
$variables = [];
if (!$item->isDummy()) {
$itemId = $item->getId();
$prefix = "order.items.{$itemId}";
$variables[$prefix . '.sku'] = $item->getSku();
$variables[$prefix . '.product_id'] = $item->getProductId();
$variables[$prefix . '.qty'] = $item->getQtyOrdered();
$variables[$prefix . '.price'] = $item->getBasePrice();
$variables[$prefix . '.row_total'] = $item->getRowTotal();
$variables[$prefix . '.label'] = $item->getName();
$variables[$prefix . '.salesrules'] = $item->getAppliedRuleIds();
if ($product = $item->getProduct()) {
$categoriesId = $product->getCategoryIds();
if (count($categoriesId)) {
$variables[$prefix . '.category_ids'] = implode(",", $categoriesId);
}
}
}
return $variables;
}