Example #1
0
 public function importQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
 {
     $this->setQuoteItemId($quoteItem->getId())->setProductId($quoteItem->getProductId())->setProduct($quoteItem->getProduct())->setSuperProductId($quoteItem->getSuperProductId())->setSuperProduct($quoteItem->getSuperProduct())->setSku($quoteItem->getSku())->setImage($quoteItem->getImage())->setName($quoteItem->getName())->setDescription($quoteItem->getDescription())->setWeight($quoteItem->getWeight())->setPrice($quoteItem->getPrice())->setCost($quoteItem->getCost());
     if (!$this->hasQty()) {
         $this->setQty($quoteItem->getQty());
     }
     $this->setQuoteItemImported(true);
     return $this;
 }
Example #2
0
 public function setQuoteItem(Mage_Sales_Model_Quote_Item $item)
 {
     $this->setQuoteItemId($item->getId());
     $this->setQuoteId($item->getQuoteId());
     $this->setProductId($item->getProductId());
     $this->setStoreId($item->getStoreId());
     $this->setQty($item->getQty());
     $this->setIsActive(true);
     $expireDateTime = Mage::helper('zab_timedcart')->getExpireDatetime(now());
     $this->setExpireDatetime($expireDateTime);
     return $this;
 }
Example #3
0
 /**
  * Overwrite @method _addItemToQtyArray
  *
  * Adds stock item qty to $items (creates new entry or increments existing one)
  * $items is array with following structure:
  * array(
  *  $productId  => array(
  *      'qty'   => $qty,
  *      'item'  => $stockItems|null
  *  )
  * )
  *
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  * @param array &$items
  */
 protected function _addItemToQtyArray($quoteItem, &$items)
 {
     $productId = $quoteItem->getProductId();
     if (!$productId) {
         return;
     }
     if (isset($items[$productId])) {
         $items[$productId]['qty'] += $quoteItem->getTotalQty();
     } else {
         $stockItem = null;
         if ($quoteItem->getProduct()) {
             $stockItem = $quoteItem->getProduct()->getStockItem();
         }
         $items[$productId] = array('item' => $stockItem, 'qty' => $quoteItem->getTotalQty(), 'quote_item_id' => $quoteItem->getId(), 'creditmemo_item_id' => null);
     }
 }
 /**
  * Compare item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  bool
  */
 public function compare($item)
 {
     if ($this->getProductId() != $item->getProductId()) {
         return false;
     }
     foreach ($this->getOptions() as $option) {
         if (in_array($option->getCode(), $this->_notRepresentOptions) && !$item->getProduct()->hasCustomOptions()) {
             continue;
         }
         if ($itemOption = $item->getOptionByCode($option->getCode())) {
             $itemOptionValue = $itemOption->getValue();
             $optionValue = $option->getValue();
             // dispose of some options params, that can cramp comparing of arrays
             if (is_string($itemOptionValue) && is_string($optionValue)) {
                 try {
                     /** @var Unserialize_Parser $parser */
                     $parser = Mage::helper('core/unserializeArray');
                     $_itemOptionValue = $parser->unserialize($itemOptionValue);
                     $_optionValue = $parser->unserialize($optionValue);
                     if (is_array($_itemOptionValue) && is_array($_optionValue)) {
                         $itemOptionValue = $_itemOptionValue;
                         $optionValue = $_optionValue;
                         // looks like it does not break bundle selection qty
                         unset($itemOptionValue['qty'], $itemOptionValue['uenc']);
                         unset($optionValue['qty'], $optionValue['uenc']);
                     }
                 } catch (Exception $e) {
                     Mage::logException($e);
                 }
             }
             if ($itemOptionValue != $optionValue) {
                 return false;
             }
         } else {
             return false;
         }
     }
     return true;
 }
 /**
  * Retrieve row url
  *
  * @param Mage_Sales_Model_Quote_Item $row
  * @return string
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('*/catalog_product/edit', array('id' => $row->getProductId()));
 }
 /**
  * determines if we should skip the items with special price or other (in futeure) conditions
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param Amasty_Promo_Model_Sales_Quote_Address $address
  *
  * @return bool
  */
 protected function _skip($item, $address)
 {
     if (!Mage::getStoreConfig('ampromo/general/skip_special_price')) {
         return false;
     }
     if ($item->getProductType() == 'bundle') {
         return false;
     }
     if (is_null($this->_itemsWithDiscount) || count($this->_itemsWithDiscount) == 0) {
         $productIds = array();
         $this->_itemsWithDiscount = array();
         foreach ($this->_getAllItems($address) as $addressItem) {
             $productIds[] = $addressItem->getProductId();
         }
         if (!$productIds) {
             return false;
         }
         $productsCollection = Mage::getModel('catalog/product')->getCollection()->addPriceData()->addAttributeToFilter('entity_id', array('in' => $productIds))->addAttributeToFilter('price', array('gt' => new Zend_Db_Expr('final_price')));
         foreach ($productsCollection as $product) {
             $this->_itemsWithDiscount[] = $product->getId();
         }
     }
     if (Mage::getStoreConfig('ampromo/general/skip_special_price_configurable')) {
         if ($item->getProductType() == "configurable") {
             foreach ($item->getChildren() as $child) {
                 if (in_array($child->getProductId(), $this->_itemsWithDiscount)) {
                     return true;
                 }
             }
         }
     }
     if (!in_array($item->getProductId(), $this->_itemsWithDiscount)) {
         return false;
     }
     return true;
 }
Example #7
0
 /**
  * Returns the name for a quote 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 parent product name prepended.
  * All others will have their own name only.
  *
  * @param Mage_Sales_Model_Quote_Item $item the quote item model.
  *
  * @return string
  */
 public function getProductName($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) {
         /* @var $helper Mage_Catalog_Helper_Product_Configuration */
         $helper = Mage::helper('catalog/product_configuration');
         foreach ($helper->getConfigurableOptions($item) as $opt) {
             if (isset($opt['value']) && is_string($opt['value'])) {
                 $optNames[] = $opt['value'];
             }
         }
     } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
         $type = $item->getProduct()->getTypeInstance(true);
         $opts = $type->getOrderOptions($item->getProduct());
         if (isset($opts['bundle_options']) && is_array($opts['bundle_options'])) {
             foreach ($opts['bundle_options'] 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->getBuyRequest()->getData('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;
 }
Example #8
0
 /**
  * Gets a list of all rule ID's that are associated with the given item.
  *
  * @param   Mage_Sales_Model_Quote_Item $item   : The item object with which the returned rules are associated
  * @return  array(int)                          : An array of rule ID's that are associated with the item
  */
 public function getCatalogRewardsRuleIds($item, $wId = null)
 {
     return $this->getCatalogRewardsRuleIdsForProduct($item->getProductId(), $wId);
 }
Example #9
0
 /**
  * Add new product to registry
  *
  * @param int|Mage_Sales_Model_Quote_Item $itemToAdd
  * @param Varien_Object $request
  * @return Enterprise_GiftRegistry_Model_Item
  */
 public function addItem($itemToAdd, $request = null)
 {
     if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) {
         $productId = $itemToAdd->getProductId();
         $qty = $itemToAdd->getQty();
     } else {
         $productId = $itemToAdd;
         $qty = $request && $request->getQty() ? $request->getQty() : 1;
     }
     $product = $this->getProduct($productId);
     if ($product->getTypeInstance(true)->hasRequiredOptions($product) && (!$request && !$itemToAdd instanceof Mage_Sales_Model_Quote_Item)) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) {
         $cartCandidate = $itemToAdd->getProduct();
         $cartCandidate->setCustomOptions($itemToAdd->getOptionsByCode());
         $cartCandidates = array($cartCandidate);
     } else {
         if (!$request) {
             $request = new Varien_Object();
             $request->setBundleOption(array());
             //Bundle options mocking for compatibility
         }
         $cartCandidates = $product->getTypeInstance(true)->prepareForCart($request, $product);
     }
     if (is_string($cartCandidates)) {
         //prepare process has error, seems like we have bundle
         throw new Mage_Core_Exception($cartCandidates, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     $item = Mage::getModel('enterprise_giftregistry/item');
     $items = $item->getCollection()->addRegistryFilter($this->getId());
     foreach ($cartCandidates as $currentCandidate) {
         if ($currentCandidate->getParentProductId()) {
             continue;
         }
         $alreadyExists = false;
         $productId = $currentCandidate->getId();
         foreach ($items as $itemForCheck) {
             if ($itemForCheck->isRepresentProduct($currentCandidate)) {
                 $alreadyExists = true;
                 $matchedItem = $itemForCheck;
                 break;
             }
         }
         $candidateQty = $currentCandidate->getCartQty();
         if (!empty($candidateQty)) {
             $qty = $candidateQty;
         }
         if ($alreadyExists) {
             $matchedItem->setQty($matchedItem->getQty() + $qty)->save();
         } else {
             $customOptions = $currentCandidate->getCustomOptions();
             $item = Mage::getModel('enterprise_giftregistry/item');
             $item->setEntityId($this->getId())->setProductId($productId)->setOptions($customOptions)->setQty($qty)->save();
         }
     }
     return $item;
 }
Example #10
0
 /**
  * Retrieve simple product id from quote item
  *
  * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Quote_Address_Item $item
  *
  * @return int
  */
 protected function _retrieveProductIdFromQuoteItem($item)
 {
     $productId = $item->getProductId();
     if ($item->getOptionByCode('simple_product')) {
         $productId = $item->getOptionByCode('simple_product')->getProduct()->getId();
     }
     return $productId;
 }
Example #11
0
 /**
  * Return vendor ID for quote item based on requested qty
  *
  * if $qty===true, always return dropship vendor id
  * if $qty===false, always return local vendor id
  * otherwise return local vendor if enough qty in stock
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param integer|boolean $qty
  * @return integer
  * @deprecated since 1.6.0
  */
 public function getQuoteItemVendor($item, $qty = 0)
 {
     $product = $item->getProduct();
     if (!$product || !$product->hasUdropshipVendor()) {
         // if not available, load full product info to get product vendor
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
     }
     $store = $item->getQuote() ? $item->getQuote()->getStore() : $item->getOrder()->getStore();
     $localVendorId = $this->getLocalVendorId($store);
     $vendorId = $product->getUdropshipVendor();
     // product doesn't have vendor specified OR force local vendor
     if (!$vendorId || $qty === false) {
         return $localVendorId;
     }
     // force real vendor
     if ($qty === true) {
         return $vendorId;
     }
     // local stock is available
     if (Mage::getSingleton('udropship/stock_availability')->getUseLocalStockIfAvailable($store, $vendorId) && $product->getStockItem()->checkQty($qty)) {
         return $localVendorId;
     }
     // all other cases
     return $vendorId;
 }
Example #12
0
 /**
  * Adds stock item qty to $items (creates new entry or increments existing one)
  * $items is array with following structure:
  * array(
  *  $productId  => array(
  *      'qty'   => $qty,
  *      'item'  => $stockItems|null
  *  )
  * )
  *
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  * @param array &$items
  */
 private function _addItemToQtyArray($quoteItem, &$items)
 {
     $productId = $quoteItem->getProductId();
     if (!$productId) {
         return;
     }
     if (isset($items[$productId])) {
         $items[$productId]['qty'] += $quoteItem->getTotalQty();
     } else {
         $stockItem = null;
         if ($quoteItem->getProduct()) {
             $stockItem = $quoteItem->getProduct()->getStockItem();
         }
         $items[$productId] = array('item' => $stockItem, 'qty' => $quoteItem->getTotalQty());
     }
 }
 private function _isDownloadableEcodeItem(Mage_Sales_Model_Quote_Item $quoteItem)
 {
     $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
     if ($product->getSerialRequired()) {
         return true;
     }
     return false;
 }
Example #14
0
 /**
  * Compare item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  bool
  */
 public function compare($item)
 {
     if ($this->getProductId() != $item->getProductId()) {
         return false;
     }
     foreach ($this->getOptions() as $option) {
         if (in_array($option->getCode(), $this->_notRepresentOptions)) {
             continue;
         }
         if ($itemOption = $item->getOptionByCode($option->getCode())) {
             $itemOptionValue = $itemOption->getValue();
             $optionValue = $option->getValue();
             // dispose of some options params, that can cramp comparing of arrays
             if (is_string($itemOptionValue) && is_string($optionValue)) {
                 $_itemOptionValue = @unserialize($itemOptionValue);
                 $_optionValue = @unserialize($optionValue);
                 if (is_array($_itemOptionValue) && is_array($_optionValue)) {
                     $itemOptionValue = $_itemOptionValue;
                     $optionValue = $_optionValue;
                     // looks like it does not break bundle selection qty
                     unset($itemOptionValue['qty'], $itemOptionValue['uenc'], $optionValue['qty'], $optionValue['uenc']);
                 }
             }
             if ($itemOptionValue != $optionValue) {
                 return false;
             }
         } else {
             return false;
         }
     }
     return true;
 }
Example #15
0
 /**
  * Retrieve product for item code
  *
  * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item $item
  * @return null|Mage_Catalog_Model_Product
  * @throws OnePica_AvaTax_Exception
  */
 protected function _getProductForItemCode($item)
 {
     $product = $this->_getProductByProductId($item->getProductId());
     if (!$this->_getCalculationHelper()->isConfigurable($item)) {
         return $product;
     }
     $children = $item->getChildren();
     if (isset($children[0]) && $children[0]->getProductId()) {
         $product = $this->_getProductByProductId($children[0]->getProductId());
     }
     return $product;
 }
Example #16
0
 /**
  * Add generate an array of product data
  *
  * @name generateProductData
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function generateProductData($item)
 {
     $orderOptions = array();
     $product = Mage::getModel('catalog/product')->load($item->getProductId());
     if ($product->getVisibility() == 1) {
         return null;
     }
     $productOptions = $item->getProductOptions();
     if (is_object($item->getProduct())) {
         $orderOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
     }
     $productData = $this->parseObject($product, 'addProduct');
     $itemData = $this->parseObject($item, 'addProduct');
     $itemData['variant'] = $this->extractAttributes($productOptions, $orderOptions);
     return array_filter(array_merge($productData, $itemData), 'strlen');
 }
 /**
  * Loads all relevant product and category data for the item
  *
  * @param  Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $item
  * @param  int $orderStoreId
  * @param  int $websiteId
  * @param  int $maxLimit
  */
 public function loadCatalogData($item, $storeId, $websiteId, $maxLimit = 10)
 {
     $product = null;
     $categories = array();
     $related = array();
     $upsells = array();
     // load product details
     if ($item->getProductId()) {
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
         // deleted
         if (!$product->getId()) {
             $product = null;
         }
         if ($product) {
             $relatedCollection = $product->getRelatedProductCollection()->addAttributeToSelect('name')->addAttributeToSelect('sku')->addAttributeToSelect('url_path')->addAttributeToSelect('image')->addAttributeToSelect('visibility')->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setPageSize($maxLimit);
             foreach ($relatedCollection as $p) {
                 $websiteIds = $p->getWebsiteIds();
                 if (in_array($websiteId, $websiteIds)) {
                     $related[$p->getId()] = $this->convertAttributeData($p);
                 }
             }
             $upsellCollection = $product->getUpSellProductCollection()->addAttributeToSelect('name')->addAttributeToSelect('sku')->addAttributeToSelect('url_path')->addAttributeToSelect('image')->addAttributeToSelect('visibility')->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setPageSize($maxLimit);
             foreach ($upsellCollection as $p) {
                 $websiteIds = $p->getWebsiteIds();
                 if (in_array($websiteId, $websiteIds)) {
                     $upsells[$p->getId()] = $this->convertAttributeData($p);
                 }
             }
             $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name')->addAttributeToSelect('is_active')->addAttributeToSelect('url_path')->addAttributeToFilter('level', array('gt' => 1))->setPageSize($maxLimit);
             foreach ($categoryCollection as $category) {
                 $storeIds = $category->getStoreIds();
                 if (in_array($storeId, $storeIds)) {
                     $categories[$category->getId()] = $this->convertAttributeData($category);
                 }
             }
             $product->setRelatedProducts($related);
             $product->setUpSellProducts($upsells);
         }
         $item->setData('product', $product);
         $item->setCategories($categories);
     }
 }