本文整理汇总了PHP中Magento\Sales\Model\Order\Item::getProductType方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::getProductType方法的具体用法?PHP Item::getProductType怎么用?PHP Item::getProductType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order\Item
的用法示例。
在下文中一共展示了Item::getProductType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertOrderItem
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param array $response
* @return void
*/
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
{
$this->assertEquals($orderItem->getId(), $response['item_id']);
$this->assertEquals($orderItem->getOrderId(), $response['order_id']);
$this->assertEquals($orderItem->getProductId(), $response['product_id']);
$this->assertEquals($orderItem->getProductType(), $response['product_type']);
$this->assertEquals($orderItem->getBasePrice(), $response['base_price']);
$this->assertEquals($orderItem->getRowTotal(), $response['row_total']);
}
示例2: aroundGetProductId
/**
* Get product id
*
* @param \Magento\Sales\Model\Order\Admin\Item $subject
* @param callable $proceed
* @param \Magento\Sales\Model\Order\Item $item
*
* @return int
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundGetProductId(\Magento\Sales\Model\Order\Admin\Item $subject, \Closure $proceed, \Magento\Sales\Model\Order\Item $item)
{
if ($item->getProductType() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
$productOptions = $item->getProductOptions();
$product = $this->productFactory->create();
return $product->getIdBySku($productOptions['simple_sku']);
}
return $proceed($item);
}
示例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;
}