Exemple #1
0
 /**
  * Save title and price of link item
  *
  * @param Mage_Downloadable_Model_Link $linkObject
  * @return Mage_Downloadable_Model_Mysql4_link
  */
 public function saveItemTitleAndPrice($linkObject)
 {
     $stmt = $this->_getReadAdapter()->select()->from($this->getTable('downloadable/link_title'))->where('link_id = ?', $linkObject->getId())->where('store_id = ?', $linkObject->getStoreId());
     if ($this->_getReadAdapter()->fetchOne($stmt)) {
         $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $linkObject->getStoreId());
         if ($linkObject->getUseDefaultTitle()) {
             $this->_getWriteAdapter()->delete($this->getTable('downloadable/link_title'), $where);
         } else {
             $this->_getWriteAdapter()->update($this->getTable('downloadable/link_title'), array('title' => $linkObject->getTitle()), $where);
         }
     } else {
         if (!$linkObject->getUseDefaultTitle()) {
             $this->_getWriteAdapter()->insert($this->getTable('downloadable/link_title'), array('link_id' => $linkObject->getId(), 'store_id' => $linkObject->getStoreId(), 'title' => $linkObject->getTitle()));
         }
     }
     $stmt = null;
     $stmt = $this->_getReadAdapter()->select()->from($this->getTable('downloadable/link_price'))->where('link_id = ?', $linkObject->getId())->where('website_id = ?', $linkObject->getWebsiteId());
     if ($this->_getReadAdapter()->fetchOne($stmt)) {
         $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . ' AND ' . $this->_getReadAdapter()->quoteInto('website_id = ?', $linkObject->getWebsiteId());
         if ($linkObject->getUseDefaultPrice()) {
             $this->_getReadAdapter()->delete($this->getTable('downloadable/link_price'), $where);
         } else {
             $this->_getWriteAdapter()->update($this->getTable('downloadable/link_price'), array('price' => $linkObject->getPrice()), $where);
         }
     } else {
         if (!$linkObject->getUseDefaultPrice()) {
             $this->_getWriteAdapter()->insert($this->getTable('downloadable/link_price'), array('link_id' => $linkObject->getId(), 'website_id' => $linkObject->getWebsiteId(), 'price' => $linkObject->getPrice()));
         }
     }
     return $this;
 }
 /**
  * Save title and price of link item
  *
  * @param Mage_Downloadable_Model_Link $linkObject
  * @return Mage_Downloadable_Model_Resource_Link
  */
 public function saveItemTitleAndPrice($linkObject)
 {
     $writeAdapter = $this->_getWriteAdapter();
     $linkTitleTable = $this->getTable('downloadable/link_title');
     $linkPriceTable = $this->getTable('downloadable/link_price');
     $select = $writeAdapter->select()->from($this->getTable('downloadable/link_title'))->where('link_id=:link_id AND store_id=:store_id');
     $bind = array(':link_id' => $linkObject->getId(), ':store_id' => (int) $linkObject->getStoreId());
     if ($writeAdapter->fetchOne($select, $bind)) {
         $where = array('link_id = ?' => $linkObject->getId(), 'store_id = ?' => (int) $linkObject->getStoreId());
         if ($linkObject->getUseDefaultTitle()) {
             $writeAdapter->delete($linkTitleTable, $where);
         } else {
             $insertData = array('title' => $linkObject->getTitle());
             $writeAdapter->update($linkTitleTable, $insertData, $where);
         }
     } else {
         if (!$linkObject->getUseDefaultTitle()) {
             $writeAdapter->insert($linkTitleTable, array('link_id' => $linkObject->getId(), 'store_id' => (int) $linkObject->getStoreId(), 'title' => $linkObject->getTitle()));
         }
     }
     $select = $writeAdapter->select()->from($linkPriceTable)->where('link_id=:link_id AND website_id=:website_id');
     $bind = array(':link_id' => $linkObject->getId(), ':website_id' => (int) $linkObject->getWebsiteId());
     if ($writeAdapter->fetchOne($select, $bind)) {
         $where = array('link_id = ?' => $linkObject->getId(), 'website_id = ?' => $linkObject->getWebsiteId());
         if ($linkObject->getUseDefaultPrice()) {
             $writeAdapter->delete($linkPriceTable, $where);
         } else {
             $writeAdapter->update($linkPriceTable, array('price' => $linkObject->getPrice()), $where);
         }
     } else {
         if (!$linkObject->getUseDefaultPrice()) {
             $dataToInsert[] = array('link_id' => $linkObject->getId(), 'website_id' => (int) $linkObject->getWebsiteId(), 'price' => (double) $linkObject->getPrice());
             if ($linkObject->getOrigData('link_id') != $linkObject->getLinkId()) {
                 $_isNew = true;
             } else {
                 $_isNew = false;
             }
             if ($linkObject->getWebsiteId() == 0 && $_isNew && !Mage::helper('catalog')->isPriceGlobal()) {
                 $websiteIds = $linkObject->getProductWebsiteIds();
                 foreach ($websiteIds as $websiteId) {
                     $baseCurrency = Mage::app()->getBaseCurrencyCode();
                     $websiteCurrency = Mage::app()->getWebsite($websiteId)->getBaseCurrencyCode();
                     if ($websiteCurrency == $baseCurrency) {
                         continue;
                     }
                     $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($websiteCurrency);
                     if (!$rate) {
                         $rate = 1;
                     }
                     $newPrice = $linkObject->getPrice() * $rate;
                     $dataToInsert[] = array('link_id' => $linkObject->getId(), 'website_id' => (int) $websiteId, 'price' => $newPrice);
                 }
             }
             $writeAdapter->insertMultiple($linkPriceTable, $dataToInsert);
         }
     }
     return $this;
 }
Exemple #3
0
 /**
  * Save title and price of link item
  *
  * @param Mage_Downloadable_Model_Link $linkObject
  * @return Mage_Downloadable_Model_Mysql4_link
  */
 public function saveItemTitleAndPrice($linkObject)
 {
     $stmt = $this->_getReadAdapter()->select()->from($this->getTable('downloadable/link_title'))->where('link_id = ?', $linkObject->getId())->where('store_id = ?', $linkObject->getStoreId());
     if ($this->_getReadAdapter()->fetchOne($stmt)) {
         $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $linkObject->getStoreId());
         if ($linkObject->getUseDefaultTitle()) {
             $this->_getWriteAdapter()->delete($this->getTable('downloadable/link_title'), $where);
         } else {
             $this->_getWriteAdapter()->update($this->getTable('downloadable/link_title'), array('title' => $linkObject->getTitle()), $where);
         }
     } else {
         if (!$linkObject->getUseDefaultTitle()) {
             $this->_getWriteAdapter()->insert($this->getTable('downloadable/link_title'), array('link_id' => $linkObject->getId(), 'store_id' => $linkObject->getStoreId(), 'title' => $linkObject->getTitle()));
         }
     }
     $stmt = null;
     $stmt = $this->_getReadAdapter()->select()->from($this->getTable('downloadable/link_price'))->where('link_id = ?', $linkObject->getId())->where('website_id = ?', $linkObject->getWebsiteId());
     if ($this->_getReadAdapter()->fetchOne($stmt)) {
         $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . ' AND ' . $this->_getReadAdapter()->quoteInto('website_id = ?', $linkObject->getWebsiteId());
         if ($linkObject->getUseDefaultPrice()) {
             $this->_getReadAdapter()->delete($this->getTable('downloadable/link_price'), $where);
         } else {
             $this->_getWriteAdapter()->update($this->getTable('downloadable/link_price'), array('price' => $linkObject->getPrice()), $where);
         }
     } else {
         if (!$linkObject->getUseDefaultPrice()) {
             $dataToInsert[] = array('link_id' => $linkObject->getId(), 'website_id' => $linkObject->getWebsiteId(), 'price' => $linkObject->getPrice());
             $_isNew = $linkObject->getOrigData('link_id') != $linkObject->getLinkId();
             if ($linkObject->getWebsiteId() == 0 && $_isNew && !Mage::helper('catalog')->isPriceGlobal()) {
                 $websiteIds = $linkObject->getProductWebsiteIds();
                 foreach ($websiteIds as $websiteId) {
                     $baseCurrency = Mage::app()->getBaseCurrencyCode();
                     $websiteCurrency = Mage::app()->getWebsite($websiteId)->getBaseCurrencyCode();
                     if ($websiteCurrency == $baseCurrency) {
                         continue;
                     }
                     $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($websiteCurrency);
                     if (!$rate) {
                         $rate = 1;
                     }
                     $newPrice = $linkObject->getPrice() * $rate;
                     $dataToInsert[] = array('link_id' => $linkObject->getId(), 'website_id' => $websiteId, 'price' => $newPrice);
                 }
             }
             foreach ($dataToInsert as $_data) {
                 $this->_getWriteAdapter()->insert($this->getTable('downloadable/link_price'), $_data);
             }
         }
     }
     return $this;
 }