예제 #1
0
 public static function crateFromOrderItem(Mage_Sales_Model_Order_Item $orderItem)
 {
     $productId = $orderItem->getProductId();
     /** @var Mage_Catalog_Model_Product $product */
     $product = Mage::getModel('catalog/product')->load($productId);
     $discounts = $product->getPrice() - $product->getFinalPrice();
     $aArticle = new self();
     $aArticle->id = $productId;
     $aArticle->name = $orderItem->getName();
     $aArticle->url = $product->getProductUrl();
     $aArticle->image_url = $product->getImageUrl();
     $aArticle->quantity = intval($orderItem->getQtyOrdered());
     $aArticle->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($orderItem->getPrice() + $discounts);
     $aArticle->description = substr($product->getDescription(), 0, 255);
     $aArticle->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(self::getProductTaxRate($product));
     $aArticle->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($discounts);
     return $aArticle;
 }
예제 #2
0
 /**
  * Retrieves RMA item name for backend
  *
  * @param Mage_Sales_Model_Order_Item $item
  * @return string
  */
 public function getAdminProductName($item)
 {
     $name = $item->getName();
     $result = array();
     if ($options = $item->getProductOptions()) {
         if (isset($options['options'])) {
             $result = array_merge($result, $options['options']);
         }
         if (isset($options['additional_options'])) {
             $result = array_merge($result, $options['additional_options']);
         }
         if (isset($options['attributes_info'])) {
             $result = array_merge($result, $options['attributes_info']);
         }
         if (!empty($result)) {
             $implode = array();
             foreach ($result as $val) {
                 $implode[] = isset($val['print_value']) ? $val['print_value'] : $val['value'];
             }
             return $name . ' (' . implode(', ', $implode) . ')';
         }
     }
     return $name;
 }
예제 #3
0
 /**
  * Retrieve
  *
  * @param Mage_Sales_Model_Order_Item $item
  * @return unknown
  */
 public function itemToQuoteItem(Mage_Sales_Model_Order_Item $item)
 {
     $quoteItem = Mage::getModel('sales/quote_item')->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setProductId($item->getProductId())->setSuperProductId($item->getSuperProductId())->setParentProductId($item->getParentProductId())->setSku($item->getSku())->setName($item->getName())->setDescription($item->getDescription())->setWeight($item->getWeight())->setCustomPrice($item->getPrice())->setDiscountPercent($item->getDiscountPercent())->setDiscountAmount($item->getDiscountAmount())->setTaxPercent($item->getTaxPercent())->setTaxAmount($item->getTaxAmount())->setRowWeight($item->getRowWeight())->setRowTotal($item->getRowTotal())->setAppliedRuleIds($item->getAppliedRuleIds())->setBaseDiscountAmount($item->getBaseDiscountAmount())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotal($item->getBaseRowTotal());
     return $quoteItem;
 }
예제 #4
0
 /**
  * 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;
 }
예제 #5
0
 /**
  * Returns the item specific values.
  * 
  * @param Mage_Sales_Model_Order_Item $item The item to get values from
  * @param Mage_Sales_Model_Order $order The order the item belongs to
  * @return Array The array containing the item specific values
  */
 protected function getOrderItemValues($item, $order, $itemInc = 1)
 {
     return array($itemInc, $item->getName(), $item->getStatus(), $this->getItemSku($item), $this->getItemOptions($item), $this->formatPrice($item->getOriginalPrice(), $order), $this->formatPrice($item->getData('price'), $order), (int) $item->getQtyOrdered(), (int) $item->getQtyInvoiced(), (int) $item->getQtyShipped(), (int) $item->getQtyCanceled(), (int) $item->getQtyRefunded(), $this->formatPrice($item->getTaxAmount(), $order), $this->formatPrice($item->getDiscountAmount(), $order), $this->formatPrice($this->getItemTotal($item), $order));
 }
 private function _scheduleSerialAssignment(Mage_Sales_Model_Order_Item $orderItem)
 {
     $queueItem = $this->getInfo('queue_item');
     if ($queueItem instanceof Gorilla_Queue_Model_Queue && $queueItem->getId()) {
         try {
             $queueItem->update();
             return true;
         } catch (Exception $e) {
             $ecodesException = new ICC_Ecodes_Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
             Mage::logException($ecodesException);
             $this->addError('There was an error registering with the Queue. Some eCodes may not recieve serial assignments.');
             return false;
         }
     } else {
         try {
             Mage::getModel('gorilla_queue/queue')->addToQueue('ecodes/observer', 'assignSerialsFromQueue', array('order_item_id' => $orderItem->getId(), 'sku' => $orderItem->getSku(), 'gp_sku' => $this->getGpSkuFromProductId($orderItem->getProductId())), 'ecodes-assign-serials')->setShortDescription('Order Item ' . $orderItem->getId() . ' needs a serial. [' . $orderItem->getName() . ']')->save();
             return true;
         } catch (Exception $e) {
             $ecodesException = new ICC_Ecodes_Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
             Mage::logException($ecodesException);
             $this->addError('There was an error registering with the Queue. Some eCodes may not recieve serial assignments.');
             return false;
         }
     }
 }
예제 #7
0
 /**
  * Return the order items data in an array for easy processing 
  *
  * @param Mage_Sales_Model_Order_Item $item
  * @param Mage_Sales_Model_Order $order
  * @return array
  */
 protected function getOrderItemData($item, $order)
 {
     $data = array();
     /*
      * get applied coupon type on each iems
      */
     $rule = Mage::getModel('salesrule/rule')->load($item->getData('applied_rule_ids'), 'rule_id');
     $data['ItemId'] = $item->getItemId();
     $data['Name'] = $item->getName();
     $data['Status'] = $item->getStatus();
     $data['SKU'] = $this->getItemSku($item);
     $data['productId'] = $this->getOrderItemProductId($item->getItemId());
     $data['ProductType'] = $this->getOrderItemType($item->getItemId());
     $data['Options'] = $this->getItemOptions($item);
     $data['MRP'] = $item->getData('product_mrp');
     $data['OriginalPrice'] = $this->getOriginalPriceTotal($item);
     $data['Price'] = $item->getData('price');
     $data['QtyOrdered'] = (int) $item->getQtyOrdered();
     $data['QtyBackordered'] = (int) $item->getQtyBackordered();
     $data['QtyInvoiced'] = (int) $item->getQtyInvoiced();
     $data['QtyShipped'] = (int) $item->getQtyShipped();
     $data['QtyCanceled'] = (int) $item->getQtyCanceled();
     $data['QtyRefunded'] = (int) $item->getQtyRefunded();
     $data['Weight'] = $item->getWeight();
     $data['TotalWeight'] = $item->getRowWeight();
     $data['Tax'] = $item->getTaxAmount();
     $data['TaxPercent'] = $item->getTaxPercent();
     if (!empty($rule->getData('voucher_type'))) {
         $data['DiscountType'] = strtoupper($rule->getData('voucher_type'));
     } else {
         $data['DiscountType'] = null;
     }
     $data['Discount'] = $item->getDiscountAmount();
     $data['CatalogDiscount'] = round($this->getCatalogDiscountAmount($item));
     $data['Total'] = $this->getItemTotal($item);
     //Premium Packaging
     $pckOpt = $item->getPckOption();
     if ($pckOpt == 1) {
         $hasPremiumPackaging = "Yes";
     } else {
         $hasPremiumPackaging = "No";
     }
     $data['HasPremiumPackaging'] = $hasPremiumPackaging;
     $data['PremiumSKU'] = $item->getPckSku();
     $data['PremiumQty'] = (int) $item->getPckQty();
     return $data;
 }
 /**
  * add the item payload to the relationship as
  * the parent
  *
  * @param IItemRelationship
  * @param Mage_Sales_Model_Order_Item
  */
 protected function addItemAsParent(IItemRelationship $relationship, Mage_Sales_Model_Order_Item $keyItem)
 {
     $relationship->setParentItem($this->itemPayload)->setType($keyItem->getRelationshipType() ?: IItemRelationship::TYPE_DYNAMIC)->setName($keyItem->getName());
 }