/**
  * Create a new ship group for the address and dispatch events to add
  * destination, gifting and item data to the ship group.
  *
  * @param Mage_Customer_Model_Address_Abstract
  * @param Mage_Sales_Model_Order_Item[]
  * @param Mage_Sales_Model_Order
  * @param IShipGroupIterable
  * @param IOrderDestinationIterable
  * @param IOrderItemIterable
  * @return IShipGroup
  */
 protected function _buildShipGroupForAddress(Mage_Customer_Model_Address_Abstract $address, array $items, Mage_Sales_Model_Order $order, IShipGroupIterable $shipGroups, IOrderDestinationIterable $destinations, IOrderItemIterable $orderItems)
 {
     $shipGroup = $shipGroups->getEmptyShipGroup();
     // default set this value to flatrate shipping since magento doesn't
     // currently allow us to figure out how much each item contributes to
     // shipping. The value can be changed by responding to the following
     // event.
     $shipGroup->setChargeType(self::SHIPPING_CHARGE_TYPE_FLATRATE);
     Mage::dispatchEvent($this->_shipGroupEvent, ['address' => $address, 'order' => $order, 'ship_group_payload' => $shipGroup, 'order_destinations_payload' => $destinations]);
     // If none of the event observers added a destination, include a default
     // mapping of the address to a destination.
     if (is_null($shipGroup->getDestination())) {
         $shipGroup->setDestination($this->_buildDefaultDestination($address, $destinations));
     }
     return $this->_addOrderItemReferences($shipGroup, $items, $orderItems, $address, $order);
 }
 /**
  * Create an email address destination for the virtual gift card, using the
  * gift card recipient information for the destination data.
  *
  * @param EbayEnterprise_Order_Model_Create_Itemreferencepair
  * @param IShipGroupIterable
  * @param IOrderDestinationIterable
  * @return IShipGroup
  */
 protected function createShipGroupForVirtualGiftCard(EbayEnterprise_Order_Model_Create_Itemreferencepair $itemRefPair, IShipGroupIterable $shipGroups, IOrderDestinationIterable $destinations)
 {
     $orderItem = $itemRefPair->getItem();
     $itemRefPayload = $itemRefPair->getPayload();
     $shipGroupPayload = $shipGroups->getEmptyShipGroup();
     $destination = $destinations->getEmptyEmailAddress();
     $destination->setEmailAddress($orderItem->getBuyRequest()->getGiftcardRecipientEmail());
     $shipGroupPayload->getItemReferences()->offsetSet($itemRefPayload);
     $shipGroupPayload->setDestination($destination)->setChargeType(EbayEnterprise_Order_Model_Create::SHIPPING_CHARGE_TYPE_FLATRATE);
     // As each virtual gift card will be in its own ship group, it likely needs
     // its own shipping price group for the OMS, even though the "shipping" cost is 0.
     // Add a new price groups for shipping with amount of 0.00 so the item &
     // ship group will have one.
     $itemPayload = $itemRefPayload->getReferencedItem();
     $itemPayload->setShippingPricing($itemPayload->getEmptyPriceGroup()->setAmount(0.0));
     $this->logger->debug('Created ship group for virtual gift card', $this->logContext->getMetaData(__CLASS__, ['email' => $destination->getEmailAddress(), 'sku' => $orderItem->getSku(), 'line_number' => $orderItem->getLineNumber()]));
     return $shipGroupPayload;
 }