Esempio n. 1
0
 public function canApply($item, $orderId)
 {
     Mage::log("canApply items ", null, 'custom.log');
     $this->productId = $item->getProductId();
     $_product = Mage::getModel('catalog/product')->load($item->getProductId());
     $this->manufacturerName = $_product->getAttributeText('manufacturer');
     $couponDao = new CouponDao();
     $customerId = Mage::getSingleton('customer/session')->getId();
     $coupon = $couponDao->loadCouponByBrand($this->manufacturerName);
     if ($customerId != null && $coupon != null) {
         Mage::log("can apply: load completed  ", null, 'custom.log');
         $couponSaving = $couponDao->loadCompletedCouponSaving($coupon->getCouponId(), $customerId);
         Mage::log($couponSaving, null, 'custom.log');
         if ($couponSaving == null) {
             Mage::log($couponSaving, null, 'custom.log');
             Mage::log("can apply: completed was null  ", null, 'custom.log');
             $couponSaving = $couponDao->loadInCartCouponSaving($coupon->getCouponId(), $customerId);
         }
         if ($couponSaving != null) {
             list($requiredNumberOfProducts, $numberOfProductsOrdered, $maxPaid) = $couponDao->getNumberOfProductsOrderdForSavingCoupon($couponSaving, $customerId);
             Mage::log("stap 1   ", null, 'custom.log');
             if ($requiredNumberOfProducts != 0) {
                 Mage::log("stap 2  ", null, 'custom.log');
                 $this->coupon = true;
                 Mage::log($maxPaid >= $_product->getPrice(), null, 'custom.log');
                 Mage::log("max paid {$maxPaid}    ", null, 'custom.log');
                 Mage::log("product->getPrice()" . $_product->getPrice(), null, 'custom.log');
                 if ($numberOfProductsOrdered >= $requiredNumberOfProducts && $maxPaid >= $_product->getPrice()) {
                     Mage::log("stap 3   ", null, 'custom.log');
                     $this->productName = $_product->getName();
                     $this->feeMount = -1 * $_product->getPrice();
                     $couponDao->setCouponSavingInUse($couponSaving, $_product->getPrice(), $orderId);
                     Mage::log("Komt in aanmerking voor gratis product" . $this->productName . " price" . $this->feeMount, null, 'custom.log');
                     return true;
                 }
             } else {
                 $this->coupon = false;
             }
         }
     }
     Mage::log("Komt niet in aanmerking voor gratis product", null, 'custom.log');
     return false;
 }
Esempio n. 2
0
 public function onSalesOrderPlaceAfter($observer)
 {
     try {
         $couponDao = new CouponDao();
         $invoice = $observer->getEvent()->getInvoice();
         $order = $observer->getOrder();
         foreach ($order->getAllItems() as $item) {
             $_product = Mage::getModel('catalog/product')->load($item->getProductId());
             $manufacturerName = $_product->getAttributeText('manufacturer');
             Mage::log($manufacturerName, null);
             $coupon = $couponDao->loadCouponByBrand($manufacturerName);
             if ($coupon != null) {
                 Mage::log($coupon, null);
                 $couponSaving = $couponDao->loadInCartCouponSaving($coupon->getCouponId(), $order->getCustomerId());
                 if ($couponSaving != null) {
                     Mage::log("  Er was een in cart voor order {$order->getIncrementId}()   en {$manufacturerName}  ", null);
                     $couponDao->setCouponSavingToInVoice($couponSaving, $order->getIncrementId());
                 }
             }
         }
     } catch (Exception $e) {
         Mage::log("This is product is " + $e, null);
     }
     return $this;
 }