本文整理汇总了PHP中Mage_Sales_Model_Order_Item::getProductOptionByCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Item::getProductOptionByCode方法的具体用法?PHP Mage_Sales_Model_Order_Item::getProductOptionByCode怎么用?PHP Mage_Sales_Model_Order_Item::getProductOptionByCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Order_Item
的用法示例。
在下文中一共展示了Mage_Sales_Model_Order_Item::getProductOptionByCode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getItemSku
/**
* Returns the sku of the given item dependant on the product type.
*
* @param Mage_Sales_Model_Order_Item $item The item to return info from
* @return String The sku
*/
protected function getItemSku($item)
{
if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
return $item->getProductOptionByCode('simple_sku');
}
return $item->getSku();
}
示例2: addOrderItem
/**
* Convert order item to quote item
*
* @param Mage_Sales_Model_Order_Item $orderItem
* @param mixed $qtyFlag if is null set product qty like in order
* @return Mage_Checkout_Model_Cart
*/
public function addOrderItem($orderItem, $qtyFlag = null)
{
/* @var $orderItem Mage_Sales_Model_Order_Item */
if (is_null($orderItem->getParentItem())) {
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($orderItem->getProductId());
if (!$product->getId()) {
return $this;
}
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new Varien_Object($info);
if (is_null($qtyFlag)) {
$info->setQty($orderItem->getQtyOrdered());
} else {
$info->setQty(1);
}
$this->addProduct($product, $info);
}
return $this;
}
示例3: initFromOrderItem
/**
* Initialize creation data from existing order Item
*
* @param Mage_Sales_Model_Order_Item $orderItem
* @param int $qty
* @return Mage_Sales_Model_Quote_Item | string
*/
public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = null)
{
if (!$orderItem->getId()) {
return $this;
}
$product = Mage::getModel('catalog/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 Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions))));
}
Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item));
return $item;
}
return $this;
}
示例4: _sendEmail
/**
* Send email to giftcard recipient
*
* @param Mage_Sales_Model_Order_Item $item
* @param int $numGiftCardsToSend
* @return void
*/
protected function _sendEmail($item, $numGiftCardsToSend)
{
if ($numGiftCardsToSend <= 0) {
return;
}
$options = $item->getProductOptions();
$createdGiftCardCodes = isset($options['giftcard_created_codes']) ? $options['giftcard_created_codes'] : array();
$sentCodes = isset($options['giftcard_sent_codes']) ? $options['giftcard_sent_codes'] : array();
$sentCodesQty = count($sentCodes);
$availableCodes = $sentCodesQty > 0 ? array_diff($createdGiftCardCodes, $sentCodes) : $createdGiftCardCodes;
if (count($availableCodes) <= 0) {
return;
}
$newlySentCodes = array();
$numNewlySentCodes = 0;
foreach ($availableCodes as $code) {
$newlySentCodes[] = $code;
$sentCodes[] = $code;
$numNewlySentCodes++;
if ($numNewlySentCodes == $numGiftCardsToSend) {
break;
}
}
$sender = $item->getProductOptionByCode('giftcard_sender_name');
$senderName = $item->getProductOptionByCode('giftcard_sender_name');
$senderEmail = $item->getProductOptionByCode('giftcard_sender_email');
if ($senderEmail) {
$sender = "{$sender} <{$senderEmail}>";
}
$isRedeemable = $this->_isGiftCardRedeemable($item);
$amount = $item->getBasePrice();
$store = Mage::app()->getStore($item->getOrder()->getStoreId());
$codeList = Mage::helper('enterprise_giftcard')->getEmailGeneratedItemsBlock()->setCodes($newlySentCodes)->setIsRedeemable($isRedeemable)->setStore($store);
$balance = Mage::app()->getLocale()->currency($store->getBaseCurrencyCode())->toCurrency($amount);
$templateData = array('name' => $item->getProductOptionByCode('giftcard_recipient_name'), 'email' => $item->getProductOptionByCode('giftcard_recipient_email'), 'sender_name_with_email' => $sender, 'sender_name' => $senderName, 'gift_message' => $item->getProductOptionByCode('giftcard_message'), 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $numNewlySentCodes, 'store' => $store, 'store_name' => $store->getName(), 'is_redeemable' => $isRedeemable);
$email = Mage::getModel('core/email_template')->setDesignConfig(array('store' => $store->getId()));
$email->sendTransactional($item->getProductOptionByCode('giftcard_email_template'), Mage::getStoreConfig(Enterprise_GiftCard_Model_Giftcard::XML_PATH_EMAIL_IDENTITY, $store->getId()), $item->getProductOptionByCode('giftcard_recipient_email'), $item->getProductOptionByCode('giftcard_recipient_name'), $templateData);
$options['giftcard_sent_codes'] = $sentCodes;
if ($email->getSentSuccess()) {
$options['email_sent'] = 1;
}
$item->setProductOptions($options);
return;
}
示例5: reorderItem
/**
* Add new item to quote based on existing order Item
*
* @param Mage_Sales_Model_Order_Item $orderItem
* @return Mage_Sales_Model_Quote_Item
* @throws Mage_Core_Exception
*/
public function reorderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = 1)
{
if (!$orderItem->getId()) {
Mage::throwException(Mage::helper('enterprise_checkout')->__('Failed to reorder item'));
}
$product = Mage::getModel('catalog/product')->setStoreId($this->getStore()->getId())->load($orderItem->getProductId());
if ($product->getId()) {
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new Varien_Object($info);
$product->setSkipCheckRequiredOption(true);
$item = $this->createQuote()->addProduct($product, $info);
if (is_string($item)) {
Mage::throwException($item);
}
$item->setQty($qty);
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
$item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions))));
}
Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item));
return $item;
} else {
Mage::throwException(Mage::helper('enterprise_checkout')->__('Failed to add a product of order item'));
}
}
示例6: _getOrderItemOptionValues
/**
* Return sales item as object
* @param Mage_Sales_Model_Order_Item $item
* @return Varien_Object
*/
protected function _getOrderItemOptionValues(Mage_Sales_Model_Order_Item $item)
{
$buyRequest = $item->getProductOptionByCode('info_buyRequest');
$obj = new Varien_Object();
$obj->setData($buyRequest);
return $obj;
}
示例7: loadOrderItemOptions
/**
* load option data for $item
*
* @param Mage_Sales_Model_Order_Item
* @return Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection
*/
protected function loadOrderItemOptions(Mage_Sales_Model_Order_Item $item)
{
$buyRequest = $item->getProductOptionByCode('info_buyRequest');
$attrs = isset($buyRequest['super_attribute']) ? $buyRequest['super_attribute'] : [];
$attrTable = ['attribute_table' => Mage::getSingleton('core/resource')->getTableName('eav/attribute')];
$options = Mage::getResourceModel('eav/entity_attribute_option_collection');
// join with the attribute table to get the attribute code.
$options->getSelect()->join($attrTable, 'main_table.attribute_id=attribute_table.attribute_id', ['attribute_code']);
$options->setStoreFilter($item->getStoreId());
$options->addFieldToFilter('main_table.attribute_id', ['in' => array_keys($attrs)]);
$options->addFieldToFilter('main_table.option_id', ['in' => array_values($attrs)]);
return $options;
}
示例8: 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 Mage_Sales_Model_Order_Item $item the sales item model.
*
* @return string
*/
protected function buildItemName(Mage_Sales_Model_Order_Item $item)
{
$name = $item->getName();
$optNames = array();
if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
/** @var Mage_Catalog_Model_Product_Type_Configurable $model */
$model = Mage::getModel('catalog/product_type_configurable');
$parentIds = $model->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 Mage_Catalog_Model_Resource_Eav_Attribute $attribute */
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($id);
$label = $attribute->getSource()->getOptionText($value);
if (!empty($label)) {
$optNames[] = $label;
}
}
}
}
} elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
$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() === Mage_Catalog_Model_Product_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() === Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
$config = $item->getProductOptionByCode('super_product_config');
if (isset($config['product_id'])) {
/** @var Mage_Catalog_Model_Product $parent */
$parent = Mage::getModel('catalog/product')->load($config['product_id']);
$parentName = $parent->getName();
if (!empty($parentName)) {
$name = $parentName . ' - ' . $name;
}
}
}
if (!empty($optNames)) {
$name .= ' (' . implode(', ', $optNames) . ')';
}
return $name;
}
示例9: initFromOrderItem
/**
* Initialize creation data from existing order Item
*
* @param Mage_Sales_Model_Order_Item $orderItem
* @param int $qty
* @return Mage_Sales_Model_Quote_Item | string
*/
public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = null)
{
if (!$orderItem->getId()) {
return $this;
}
$product = Mage::getModel('catalog/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;
}
/*********************************************Set custom price selected starts************************************************************/
if (!$this->getSession()->getReordered() && $orderItem->getOriginalPrice() != $orderItem->getPrice()) {
if ($orderItem->getProductType() == 'configurable' || $orderItem->getProductType() == 'bundle') {
$productId = $orderItem->getProductId();
$quoteItemId = $orderItem->getQuoteItemId();
$items = $this->getQuote()->getItemsCollection();
foreach ($items as $item) {
if ($item->getProduct()->getId() == $productId && !$item->getApplyPriceFlag()) {
if ($orderItem->getOriginalPrice() != $orderItem->getPrice()) {
$item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice());
}
//$item->setApplyPriceFlag(true);
}
}
} else {
$item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice());
}
}
/*********************************************Set custom price selected ends************************************************************/
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
$item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions))));
}
Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item));
return $item;
}
return $this;
}