Beispiel #1
0
 /**
  * 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;
 }
 /**
  * Supply gift card fields
  *
  * @param IOrderItem
  * @param Mage_Sales_Model_Order_Item
  * @return $payload
  */
 protected function addGiftCardDataToPayload(IOrderItem $payload, Mage_Sales_Model_Order_Item $item)
 {
     if ($item->getProductType() === 'giftcard') {
         // Gift card fields are XML escaped by the SDK, so they do not need
         // to be escaped here.
         $buyRequest = $item->getBuyRequest();
         $from = $this->formatGiftCardName($buyRequest->getGiftcardSenderName(), $buyRequest->getGiftcardSenderEmail());
         $to = $this->formatGiftCardName($buyRequest->getGiftcardRecipientName(), $buyRequest->getGiftcardRecipientEmail());
         $message = $buyRequest->getGiftcardMessage();
         $payload->setGiftCardFrom($from)->setGiftCardTo($to)->setGiftCardMessage($message);
     }
     return $payload;
 }
 /**
  * @param Mage_Sales_Model_Order_Item $orderItem
  * @return Adyen_Subscription_Model_Product_Subscription
  */
 protected function _getProductSubscription(Mage_Sales_Model_Order_Item $orderItem)
 {
     $subscriptionId = $orderItem->getBuyRequest()->getData('adyen_subscription');
     if (!$subscriptionId) {
         return false;
     }
     $subscriptionProductSubscription = Mage::getModel('adyen_subscription/product_subscription')->load($subscriptionId);
     if (!$subscriptionProductSubscription->getId()) {
         return false;
     }
     Mage::dispatchEvent('adyen_subscription_order_getproductsubscription', array('productSubscription' => $subscriptionProductSubscription, 'item' => $orderItem));
     return $subscriptionProductSubscription;
 }
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * 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;
 }