Public Member Functions | |
prepareProductSave ($observer) | |
saveDownloadableOrderItem ($observer) | |
setHasDownloadableProducts ($observer) | |
setLinkStatus ($observer) | |
isAllowedGuestCheckout (Varien_Event_Observer $observer) | |
Public Attributes | |
const | XML_PATH_DISABLE_GUEST_CHECKOUT = 'catalog/downloadable/disable_guest_checkout' |
Definition at line 34 of file Observer.php.
isAllowedGuestCheckout | ( | Varien_Event_Observer $ | observer | ) |
Check is allowed guest checkuot if quote contain downloadable product(s)
Varien_Event_Observer | $observer |
Definition at line 209 of file Observer.php.
00210 { 00211 $quote = $observer->getEvent()->getQuote(); 00212 /* @var $quote Mage_Sales_Model_Quote */ 00213 $store = $observer->getEvent()->getStore(); 00214 $result = $observer->getEvent()->getResult(); 00215 00216 $isContain = false; 00217 00218 foreach ($quote->getAllItems() as $item) { 00219 if (($product = $item->getProduct()) && 00220 $product->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) { 00221 $isContain = true; 00222 } 00223 } 00224 00225 if ($isContain && Mage::getStoreConfigFlag(self::XML_PATH_DISABLE_GUEST_CHECKOUT, $store)) { 00226 $result->setIsAllowed(false); 00227 } 00228 00229 return $this; 00230 }
prepareProductSave | ( | $ | observer | ) |
Prepare product to save
Varien_Object | $observer |
Definition at line 44 of file Observer.php.
00045 { 00046 $request = $observer->getEvent()->getRequest(); 00047 $product = $observer->getEvent()->getProduct(); 00048 00049 if ($downloadable = $request->getPost('downloadable')) { 00050 $product->setDownloadableData($downloadable); 00051 } 00052 00053 return $this; 00054 }
saveDownloadableOrderItem | ( | $ | observer | ) |
Save data from order to purchased links
Varien_Object | $observer |
Definition at line 62 of file Observer.php.
00063 { 00064 $orderItem = $observer->getEvent()->getItem(); 00065 if (Mage::getModel('downloadable/link_purchased')->load($orderItem->getId(), 'order_item_id')->getId()) { 00066 return $this; 00067 } 00068 $product = Mage::getModel('catalog/product') 00069 ->setStoreId($orderItem->getOrder()->getStoreId()) 00070 ->load($orderItem->getProductId()); 00071 if ($product->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) { 00072 $links = $product->getTypeInstance(true)->getLinks($product); 00073 if ($linkIds = $orderItem->getProductOptionByCode('links')) { 00074 $linkPurchased = Mage::getModel('downloadable/link_purchased'); 00075 Mage::helper('core')->copyFieldset( 00076 'downloadable_sales_copy_order', 00077 'to_downloadable', 00078 $orderItem->getOrder(), 00079 $linkPurchased 00080 ); 00081 Mage::helper('core')->copyFieldset( 00082 'downloadable_sales_copy_order_item', 00083 'to_downloadable', 00084 $orderItem, 00085 $linkPurchased 00086 ); 00087 $linkSectionTitle = ( 00088 $product->getLinksTitle()? 00089 $product->getLinksTitle():Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_LINKS_TITLE) 00090 ); 00091 $linkPurchased->setLinkSectionTitle($linkSectionTitle) 00092 ->save(); 00093 foreach ($linkIds as $linkId) { 00094 if (isset($links[$linkId])) { 00095 $linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item') 00096 ->setPurchasedId($linkPurchased->getId()) 00097 ->setOrderItemId($orderItem->getId()); 00098 00099 Mage::helper('core')->copyFieldset( 00100 'downloadable_sales_copy_link', 00101 'to_purchased', 00102 $links[$linkId], 00103 $linkPurchasedItem 00104 ); 00105 $linkHash = strtr(base64_encode(microtime() . $linkPurchased->getId() . $orderItem->getId() . $product->getId()), '+/=', '-_,'); 00106 $numberOfDownloads = $links[$linkId]->getNumberOfDownloads()*$orderItem->getQtyOrdered(); 00107 $linkPurchasedItem->setLinkHash($linkHash) 00108 ->setNumberOfDownloadsBought($numberOfDownloads) 00109 ->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING) 00110 ->setCreatedAt($orderItem->getCreatedAt()) 00111 ->setUpdatedAt($orderItem->getUpdatedAt()) 00112 ->save(); 00113 } 00114 } 00115 } 00116 } 00117 00118 return $this; 00119 }
setHasDownloadableProducts | ( | $ | observer | ) |
Set checkout session flag if order has downloadable product(s)
Varien_Object | $observer |
Definition at line 127 of file Observer.php.
00128 { 00129 $session = Mage::getSingleton('checkout/session'); 00130 if (!$session->getHasDownloadableProducts()) { 00131 $order = $observer->getEvent()->getOrder(); 00132 foreach ($order->getAllItems() as $item) { 00133 /* @var $item Mage_Sales_Model_Order_Item */ 00134 if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE 00135 || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE 00136 || $item->getProductOptionByCode('is_downloadable')) 00137 { 00138 $session->setHasDownloadableProducts(true); 00139 break; 00140 } 00141 } 00142 } 00143 return $this; 00144 }
setLinkStatus | ( | $ | observer | ) |
Set status of link
Varien_Object | $observer |
Definition at line 152 of file Observer.php.
00153 { 00154 $order = $observer->getEvent()->getOrder(); 00155 /* @var $order Mage_Sales_Model_Order */ 00156 $status = ''; 00157 $orderItemsIds = array(); 00158 $orderItemStatusToEnable = Mage::getStoreConfig(Mage_Downloadable_Model_Link_Purchased_Item::XML_PATH_ORDER_ITEM_STATUS); 00159 if ($order->getState() == Mage_Sales_Model_Order::STATE_HOLDED) { 00160 $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING; 00161 } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED 00162 || $order->getState() == Mage_Sales_Model_Order::STATE_CLOSED) { 00163 $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED; 00164 } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) { 00165 $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT; 00166 } else { 00167 foreach ($order->getAllItems() as $item) { 00168 if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE 00169 || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) 00170 { 00171 if ($item->getStatusId() == $orderItemStatusToEnable) { 00172 $orderItemsIds[] = $item->getId(); 00173 } 00174 } 00175 } 00176 if ($orderItemsIds) { 00177 $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE; 00178 } 00179 } 00180 if (!$orderItemsIds && $status) { 00181 foreach ($order->getAllItems() as $item) { 00182 if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE 00183 || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) 00184 { 00185 $orderItemsIds[] = $item->getId(); 00186 } 00187 } 00188 } 00189 00190 if ($orderItemsIds) { 00191 $linkPurchased = Mage::getResourceModel('downloadable/link_purchased_item_collection') 00192 ->addFieldToFilter('order_item_id', array('in'=>$orderItemsIds)); 00193 foreach ($linkPurchased as $link) { 00194 if ($link->getStatus() != Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED) { 00195 $link->setStatus($status) 00196 ->save(); 00197 } 00198 } 00199 } 00200 return $this; 00201 }
const XML_PATH_DISABLE_GUEST_CHECKOUT = 'catalog/downloadable/disable_guest_checkout' |
Definition at line 36 of file Observer.php.