本文整理匯總了PHP中Magento\Sales\Model\Order\Item::getProductId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getProductId方法的具體用法?PHP Item::getProductId怎麽用?PHP Item::getProductId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Sales\Model\Order\Item
的用法示例。
在下文中一共展示了Item::getProductId方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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;
}
示例3: initFromOrderItem
/**
* Initialize creation data from existing order Item
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param int $qty
* @return \Magento\Quote\Model\Quote\Item|string|$this
*/
public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty = null)
{
if (!$orderItem->getId()) {
return $this;
}
$product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId());
if ($product->getId()) {
$product->setSkipCheckRequiredOption(true);
$buyRequest = $orderItem->getBuyRequest();
if (is_numeric($qty)) {
$buyRequest->setQty($qty);
}
$item = $this->getQuote()->addProduct($product, $buyRequest);
if (is_string($item)) {
return $item;
}
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
$item->addOption(new \Magento\Framework\DataObject(['product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions)]));
}
$this->_eventManager->dispatch('sales_convert_order_item_to_quote_item', ['order_item' => $orderItem, 'quote_item' => $item]);
return $item;
}
return $this;
}
示例4: addOrderItem
/**
* Convert order item to quote item
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param true|null $qtyFlag if is null set product qty like in order
* @return $this
*/
public function addOrderItem($orderItem, $qtyFlag = null)
{
/* @var $orderItem \Magento\Sales\Model\Order\Item */
if ($orderItem->getParentItem() === null) {
$storeId = $this->_storeManager->getStore()->getId();
try {
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
} catch (NoSuchEntityException $e) {
return $this;
}
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new \Magento\Framework\Object($info);
if ($qtyFlag === null) {
$info->setQty($orderItem->getQtyOrdered());
} else {
$info->setQty(1);
}
$this->addProduct($product, $info);
}
return $this;
}
示例5: 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;
}
示例6: itemToQuoteItem
/**
* Retrieve
*
* @param \Magento\Sales\Model\Order\Item $item
* @return \Magento\Sales\Model\Quote\Item
*/
public function itemToQuoteItem(\Magento\Sales\Model\Order\Item $item)
{
$quoteItem = $this->_quoteItemFactory->create()->setStoreId($item->getOrder()->getStoreId())->setQuoteItemId($item->getId())->setProductId($item->getProductId())->setParentProductId($item->getParentProductId());
$this->_objectCopyService->copyFieldsetToTarget('sales_convert_order_item', 'to_quote_item', $item, $quoteItem);
return $quoteItem;
}
示例7: addOrderItem
/**
* Convert order item to quote item
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param true|null $qtyFlag if is null set product qty like in order
* @return $this
*/
public function addOrderItem($orderItem, $qtyFlag = null)
{
/* @var $orderItem \Magento\Sales\Model\Order\Item */
if (is_null($orderItem->getParentItem())) {
$product = $this->_productFactory->create()->setStoreId($this->_storeManager->getStore()->getId())->load($orderItem->getProductId());
if (!$product->getId()) {
return $this;
}
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new \Magento\Framework\Object($info);
if (is_null($qtyFlag)) {
$info->setQty($orderItem->getQtyOrdered());
} else {
$info->setQty(1);
}
$this->addProduct($product, $info);
}
return $this;
}
示例8: getProductId
/**
* Get product id
*
* @param \Magento\Sales\Model\Order\Item $item
*
* @return int
*/
public function getProductId(\Magento\Sales\Model\Order\Item $item)
{
return $item->getProductId();
}
示例9: addOrderItem
/**
* Convert order item to quote item
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param true|null $qtyFlag if is null set product qty like in order
* @return $this
*/
public function addOrderItem($orderItem, $qtyFlag = null)
{
/* @var $orderItem \Magento\Sales\Model\Order\Item */
if ($orderItem->getParentItem() === null) {
$storeId = $this->_storeManager->getStore()->getId();
try {
/**
* We need to reload product in this place, because products
* with the same id may have different sets of order attributes.
*/
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
} catch (NoSuchEntityException $e) {
return $this;
}
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new \Magento\Framework\DataObject($info);
if ($qtyFlag === null) {
$info->setQty($orderItem->getQtyOrdered());
} else {
$info->setQty(1);
}
$this->addProduct($product, $info);
}
return $this;
}