- An Important Note
- Are You A New Programmer Or New To Magento?
- Commonly Used Classes and Methods
- How to Display Rental Price Periods For A Product?
- How to Check Rental Price For Specific Dates?
- How to Check Inventory For Reservation Product?
- How to Edit Reservation Dates On An Order?
- How to Add To Rental Queue?
- How to Check Order Reservation Dates and Order Dropoff & Pickup Dates?
- How To Mark An Order Shipped and Returned?
- How To Update Turnover Time Before & After?
- How To Check Reservation Dates Of A Product In The Cart?
An Important Note #
Do not “hack” the core or the rental extension module directly. All your code should be in app/code/local/yourcompany/yourmodule. That way if we update the rental system your changes will not be overwritten. This is generally how most programming frameworks work. You don’t directly edit the classes and methods, you extend them.
Are You A New Programmer Or New To Magento? #
Make sure to get familiar with PHP OOP concepts. We recommend the following learning resources:
2. Magento programming books from Packt
- Magento PHP Developer’s Guide
- Magento 1.8 Developer Cookbook
- Getting Started With Magento Development
3. Alan Storm Magento tutorials
4. For design changes please check:
- Official Magento design guide PDF
- Smashing Magazine Magento Layout Tutorial
- Alan Storm No Frills Magento Layout (very good PDF on layouts, worth the $)
- Mastering Magento Theme Design (Also very good but cost $)
5. Good Magento overview: Magento The Right Way
Commonly Used Classes and Methods #
The most important class is ITwebexperts_Payperrentals_Helper_Data which is found in the helper folder. All the methods are static methods.
How to Display Rental Price Periods For A Product? #
ITwebexperts_Payperrentals_Helper_Data::getPriceList(productId,nr = -1)
it will provide a list of a specified number of pricing per periods. if $nr variable is -1 it will provide all of them, else it will provide the $nr number of pricing per periods.
How to Check Rental Price For Specific Dates? #
ITwebexperts_Payperrentals_Helper_Data::calculatePrice($productId, $startingDate, $endingDate, $qty, $customerGroup)
it will provide the price for a specific period for a specified productId. it needs $qty because that might have different pricing per qty and also $customerGroup because it might have different pricing per group.
How to Check Inventory For Reservation Product? #
ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product_id, $startingDate, $endingDate)
It will return the number of items available for a productId in a specific interval.
How to Edit Reservation Dates On An Order? #
Mage::getResourceSingleton(‘payperrentals/reservationorders’)->updateStartEndByOrderId($id, $start, $end);
$id must be order increment id
How to Add To Rental Queue? #
// get product and buy request variable
$Product = $item->getProduct();
$buyRequest = $Product->getCustomOption(‘info_buyRequest’)->getValue();
// add to queue
ITwebexperts_Payperrentals_Helper_Data::::addProductToQueue($product, $buyRequest);
How to Check Order Reservation Dates and Order Dropoff & Pickup Dates? #
// $orderId is the id of your order you want to load
$order = Mage::getModel(‘sales/order’)->load($orderId);
$order->getStartDatetime() – reservation start date if the date is the same for all products on order.
$order->getEndDatetime() – reservation end date if the date is the same for all products on order.
$order->getSendDatetime() – dropoff date if the date is the same for all products on order.
$order->getReturnDatetime() – pickup date if the date is the same for all products on order.
How To Mark An Order Shipped and Returned? #
// supposing you want to send order $orderId
$coll = Mage::getModel(‘payperrentals/reservationorders’)
->getCollection()
->addOtypeFilter(ITwebexperts_Payperrentals_Model_Reservationorders::TYPE_ORDER)
->addOrderIdFilter($orderId)
->addSelectFilter(“product_type = ‘”.ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE.”‘”)
->addSendReturnFilter();
foreach ($coll as $resOrder) {
$product = Mage::getModel(‘catalog/product’)->load($resOrder->getProductId());
$sn = array();
if($product->getPayperrentalsUseSerials()){
$coll1 = Mage::getModel(‘payperrentals/serialnumbers’)
->getCollection()
->addEntityIdFilter($resOrder->getProductId())
->addSelectFilter(“status=’A'”);
foreach($coll1 as $item){
$sn[] = $item->getSn(); }
}
foreach($sn as $serial){
Mage::getResourceSingleton(‘payperrentals/serialnumbers’)
->updateStatusBySerial($serial, ‘O’);
}
$serialNumber = implode(‘,’,$sn);
$sendTime = date(‘Y-m-d H:i:s’, Mage::getModel(‘core/date’)->timestamp(time()));
$sendReturn = Mage::getModel(‘payperrentals/sendreturn’)
->setOrderId($resOrder->getOrderId())
->setProductId($resOrder->getProductId())
->setResStartdate($resOrder->getStartDate())
->setResEnddate($resOrder->getEndDate())
->setSendDate($sendTime)
->setReturnDate(‘0000-00-00 00:00:00’)
->setQty($resOrder->getQty())
//here needs a check this should always be true
->setSn($serialNumber)
->save();
Mage::getResourceSingleton(‘payperrentals/reservationorders’)->updateSendReturnById($id, $sendReturn->getId());
}
// supposing you want to return order $orderId
$coll = Mage::getModel(‘payperrentals/sendreturn’)
->getCollection()
->addSelectFilter(“return_date=’0000-00-00 00:00:00′”)
->addOrderIdFilter($orderId);
foreach ($coll as $resOrder) {
$sn = explode(‘,’, $resOrder->getSn());
$returnTime = date(‘Y-m-d H:i:s’, Mage::getModel(‘core/date’)->timestamp(time()));
foreach($sn as $serial){
Mage::getResourceSingleton(‘payperrentals/serialnumbers’)
->updateStatusBySerial($serial, ‘A’);
}
Mage::getResourceSingleton(‘payperrentals/sendreturn’)
->updateReturndateById($id, $returnTime);
}
How To Update Turnover Time Before & After? #
There is no way. Turnover time before and after is based on a global variable or per product.
How To Check Reservation Dates Of A Product In The Cart? #
$quoteItems = Mage::getSingleton(‘checkout/cart’)->getQuote()->getItemsCollection();
foreach($quoteItems as $item)
{
$Product = $item->getProduct();
$source = unserialize($Product->getCustomOption(‘info_buyRequest’)->getValue());
if(!isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION]))
{
continue;
}
$start_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION];
$end_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION];
}