public function saveAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $postData = $this->getRequest()->getPost();
             $cartexModel = Mage::getModel('cartex/cart_entity');
             $cartexId = Mage::getresourceModel('cartex/cart_entity')->fetchbyEntityId($this->getRequest()->getParam('id'));
             if ($cartexId) {
                 $cartexModel->setId($cartexId);
             }
             $cartexModel->setPromoName($postData['promo_name'])->setDescription($postData['description'])->setPromoCode($postData['promo_code'])->setPromoType($postData['promo_type'])->setIsActive($postData['is_active'])->setStoreId($postData['store_id'])->setEntityId($this->getRequest()->getParam('id'))->setEntityTypeId(4)->save();
             //				if(isset($postData['rule_id']))
             //					{
             //					$cartexModel->setRuleId($postData['rule_id'])->save();
             //					}
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setCartexData(false);
             $this->_redirect('*/*/');
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setCartexData($this->getRequest()->getPost());
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
 protected function _prepareCollection()
 {
     $collection = Mage::getresourceModel('eav/entity_attribute_set_collection');
     $collection->addFieldToFilter('attribute_set_name', array('neq' => 'Default'));
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
 protected function _getSelectedProducts()
 {
     $productEntityTypeId = Mage::getModel('eav/entity_type')->loadByCode('catalog_product')->getId();
     $cartexId = Mage::app()->getFrontController()->getRequest()->get('id');
     $products = Mage::getresourceModel('cartex/cart_groups')->fetchbyAttributeId($cartexId, $productEntityTypeId);
     return $products;
 }
 public function getIdxCollection()
 {
     $itemCollection = Mage::getresourceModel('cartex/cart_idx')->fetchbyQuoteId($this->_quoteId);
     foreach ($itemCollection as $item) {
         $this->_itemIdxCollection[] = $item['item_id'];
     }
     return $this->_itemIdxCollection;
 }
 protected function setPromoId()
 {
     $this->_promoId = Mage::getresourceModel('cartex/cart_products')->getPromoIdbyProduct($this->getProduct()->getId());
     if ($this->_promoId != 0) {
         $this->_view = true;
     }
     return $this->_promoId;
 }
 public function processRule($promo)
 {
     $this->setCurrentPromoCollection($promo);
     $groupCollection = Mage::getresourceModel('cartex/cart_groups_collection')->addFilter('wdc_attribute_id', $promo->getId())->addFilter('entity_type_id', $this->_entityTypeId);
     if ($groupCollection) {
         foreach ($groupCollection as $group) {
             echo '<br>help!';
         }
     }
 }
 public function processRule($promo)
 {
     $this->setCurrentPromoCollection($promo);
     //$this->_promoGroupId = $promo->getId();
     //$this->_entityTypeId = $promo->getEntityTypeId();
     $valueCollection = Mage::getresourceModel('cartex/cart_value_collection')->addFilter('wdc_attribute_id', $promo->getId());
     if ($valueCollection) {
         foreach ($valueCollection as $checkVal) {
             $this->validateExpressions($checkVal);
         }
     }
 }
 protected function getAssignedProducts()
 {
     $products = array();
     $productEntityTypeId = Mage::getModel('eav/entity_type')->loadByCode('catalog_product')->getId();
     $cartexId = Mage::app()->getFrontController()->getRequest()->get('id');
     $collection = Mage::getresourceModel('cartex/cart_groups_collection')->addFilter('entity_type_id', $productEntityTypeId)->addFilter('wdc_attribute_id', $cartexId);
     foreach ($collection as $item) {
         ////Mage::helper('errorlog')->insert('getAssignedProducts()-collection', $item->getEntityId());
         $products[] = $item->getEntityId();
         ////Mage::helper('errorlog')->insert('serializer', $item->getEntityId());
     }
     return $products;
 }
 public function addAction()
 {
     $itemId = $this->getRequest()->getParam('item_id');
     if (isset($itemId) && !empty($itemId)) {
         $row = Mage::getresourceModel('cartex/cart_idx')->fetchRowbyItemId($itemId);
         $idx = Mage::getModel('cartex/cart_idx')->load($row['item_idx_id']);
         $idx->setIsCurrent(1)->save();
         $cart = Mage::getModel('checkout/cart');
         $cart->addProduct((int) $row['product_id'], $row['qty']);
         $cart->save();
         $this->_redirect('checkout/cart/');
     }
 }
示例#10
0
 public function __construct()
 {
     parent::__construct();
     $this->_objectId = 'id';
     $this->_blockGroup = 'cartex';
     $this->_controller = 'adminhtml_entity';
     $this->_updateButton('save', 'label', Mage::helper('cartex')->__('Save Cart Promo'));
     $this->_updateButton('delete', 'label', Mage::helper('cartex')->__('Delete Cart Promo'));
     if ($this->getRequest()->getParam($this->_objectId)) {
         $model = Mage::getModel('cartex/cart_entity')->load($this->getRequest()->getParam($this->_objectId));
         Mage::register('cartex_data', $model);
         $valueId = Mage::getresourceModel('cartex/cart_value')->fetchbyAttributeId($model->getId());
         $valueModel = Mage::getModel('cartex/cart_value')->load($valueId);
         Mage::register('cartex_valuedata', $valueModel);
     }
 }
示例#11
0
 protected function getPromoProduct()
 {
     $itemCollection = Mage::getresourceModel('cartex/cart_item_collection')->addFilter('wdc_attribute_id', $this->_promoId);
     foreach ($itemCollection as $item) {
         $this->_promoproductId = $item->getEntityId();
         break;
     }
     if ($this->_promoproductId != 0) {
         $product = Mage::getModel('catalog/product')->load($this->_promoproductId);
         if ($product->getStockItem()->getIsInStock() == 1) {
             return $product->getName();
         }
     } else {
         return $this->getProduct()->getId();
     }
 }
示例#12
0
 public function getPromoProduct()
 {
     $_product = null;
     foreach ($this->getActivePromoGroups() as $promo) {
         if (in_array($promo->getPromoType(), $this->getQualifyIds())) {
             if ($promo->getExceptionTypeId() == 0) {
                 foreach ($this->_getGroups($promo->getCartexId(), Mage::getModel('eav/entity_type')->loadByCode('catalog_product')->getId()) as $productId) {
                     if ($productId->getEntityId() == $this->getProduct()->getId()) {
                         $item = Mage::getresourceModel('cartex/cart_item')->fetchbyAttributeId($promo->getCartexId());
                         foreach ($item as $promoProduct) {
                             $_product = Mage::getModel('catalog/product')->load($promoProduct);
                             break;
                         }
                     }
                 }
             }
         }
     }
     return $_product;
 }
示例#13
0
 public function __construct()
 {
     parent::__construct();
     $this->_objectId = 'id';
     $this->_blockGroup = 'cartex';
     $this->_controller = 'adminhtml_promo';
     $this->_updateButton('save', 'label', Mage::helper('cartex')->__('Save Cart Promo'));
     $this->_updateButton('delete', 'label', Mage::helper('cartex')->__('Delete Cart Promo'));
     if ($this->getRequest()->getParam($this->_objectId)) {
         $product = Mage::getModel('catalog/product')->load($this->getRequest()->getParam($this->_objectId));
         Mage::register('current_product', $product);
         $cartexId = Mage::getresourceModel('cartex/cart_entity')->fetchbyEntityId($this->getRequest()->getParam($this->_objectId));
         if ($cartexId) {
             $model = Mage::getModel('cartex/cart_entity')->load($cartexId);
             Mage::register('cartex_product', $model);
         } else {
             Mage::register('cartex_product', array());
         }
     }
 }
示例#14
0
 public function addLineCartItem($productId)
 {
     $this->_quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
     $product = $this->_getProduct($productId);
     $this->_productId = $productId;
     $sellPrice = $product->getFinalPrice() - $this->_discount_amount;
     $product->setPrice($sellPrice);
     $product->setFinalPrice($sellPrice);
     $data = array('quote_id' => $this->_quoteId, 'created_at' => Mage::getModel('core/date')->date('Y-m-d'), 'updated_at' => Mage::getModel('core/date')->date('Y-m-d'), 'product_id' => $productId, 'parent_item_id' => NULL, 'is_virtual' => '0', 'sku' => $product->getSku(), 'name' => $product->getName(), 'applied_rule_ids' => $this->setCurrentRuleId(), 'additional_data' => NULL, 'free_shipping' => '0', 'is_qty_decimal' => '0', 'no_discount' => '1', 'weight' => $product->getWeight(), 'qty' => $this->_promo_add_cnt, 'price' => $sellPrice, 'base_price' => $sellPrice, 'custom_price' => $sellPrice, 'discount_percent' => '0.0000', 'discount_amount' => $this->_discount_amount, 'base_discount_amount' => $this->_discount_amount, 'tax_percent' => '0.0000', 'tax_amount' => '0.0000', 'base_tax_amount' => '0.0000', 'row_total' => $sellPrice * $this->_promo_add_cnt, 'base_row_total' => $sellPrice * $this->_promo_add_cnt, 'row_total_with_discount' => $sellPrice * $this->_promo_add_cnt, 'row_weight' => $product->getWeight() * $this->_promo_add_cnt, 'product_type' => $product->getTypeId(), 'base_tax_before_discount' => '0.0000', 'tax_before_discount' => '0.0000', 'original_custom_price' => $sellPrice, 'gift_message_id' => NULL, 'weee_tax_applied' => 'a:0:{}', 'weee_tax_applied_amount' => '0.0000', 'weee_tax_applied_row_amount' => '0.0000', 'base_weee_tax_applied_amount' => '0.0000', 'base_weee_tax_applied_row_amount' => '0.0000', 'weee_tax_disposition' => '0.0000', 'weee_tax_row_disposition' => '0.0000', 'base_weee_tax_disposition' => '0.0000', 'base_weee_tax_row_disposition' => '0.0000');
     if ($this->checkVersion() == 2) {
         $v14 = array('store_id' => $this->_getStore());
         $data = array_merge($data, $v14);
     }
     Mage::getresourceModel('cartex/cart_idx')->insertCartItem($data, $this->_promoGroupId);
 }
示例#15
0
 protected function _getGroups($promoId, $entityTypeId)
 {
     return Mage::getresourceModel('cartex/cart_groups_collection')->addFilter('entity_type_id', $entityTypeId)->addFilter('wdc_attribute_id', $promoId);
 }
 public function relatedAction()
 {
     $gridBlock = $this->getLayout()->createBlock('cartex/adminhtml_entity_edit_tab_related')->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'related')));
     $cartexId = $this->getRequest()->getParam('id');
     $productEntityTypeId = Mage::getModel('eav/entity_type')->loadByCode('catalog_product')->getId();
     $collection = Mage::getresourceModel('cartex/cart_groups_collection')->addFilter('entity_type_id', $productEntityTypeId)->addFilter('wdc_attribute_id', $cartexId);
     $productsArray = array();
     foreach ($collection as $product) {
         $productsArray[] = $product->getEntityId();
     }
     $serializerBlock = $this->_createSerializerBlock('links[related]', $gridBlock, $productsArray);
     $this->_outputBlocks($gridBlock, $serializerBlock);
 }
 protected function processPriceRequests()
 {
     $valueCollection = Mage::getresourceModel('cartex/cart_value_collection')->addFilter('wdc_attribute_id', $this->_currentPromoCollection->getCartexId());
     if ($valueCollection) {
         foreach ($valueCollection as $checkVal) {
             $this->validateExpressions($checkVal);
         }
     }
 }
 public function addAction()
 {
     $cart = Mage::getModel('checkout/cart');
     $id = $this->getRequest()->getParam('promoid');
     $groupedproductCollection = Mage::getresourceModel('cartex/cart_products_collection')->addFilter('wdc_attribute_id', $id);
     foreach ($groupedproductCollection as $item) {
         $_product = Mage::getModel('catalog/product')->load((int) $item->getEntityId());
         try {
             if ($_product->getIsInStock()) {
                 $cart->addProduct((int) $item->getEntityId(), 1);
                 $cart->save();
             }
         } catch (exception $e) {
             $this->_getSession()->addError(Mage::helper('cartex')->__($e->getMessage()));
             $this->_redirect('checkout/cart/');
         }
     }
     $promo = Mage::getModel('cartex/cart_entity')->load($id);
     $rule = Mage::getModel('salesrule/rule')->load($promo->getRuleId());
     $quote = Mage::getModel('checkout/session')->getQuote();
     //echo $rule->getCouponCode();
     $quote->setCouponCode($rule->getCouponCode());
     //
     $quote->save();
     $this->_redirect('checkout/cart/');
 }
示例#19
0
 public function updateCoupon($cartexCouponId, $ruleId, $couponCode)
 {
     $model = $this->getRuleModel();
     try {
         if ($this->checkVersion() == 2) {
             $couponId = Mage::getresourceModel('cartex/cart_coupon')->getCouponIdbyRuleId($ruleId);
             $model->load($couponId)->setCode($couponCode)->save();
             $couponModel = Mage::getModel('cartex/cart_coupon')->setId($cartexCouponId)->setCouponCode($couponCode)->save();
         } else {
             $model->load($ruleId)->setCouponCode($couponCode)->save();
             $couponModel = Mage::getModel('cartex/cart_coupon')->setId($cartexCouponId)->setCouponCode($couponCode)->save();
         }
     } catch (exception $e) {
         echo $e->getMessage();
     }
 }
 protected function getPromoCollection()
 {
     return Mage::getresourceModel('cartex/cart_products_collection')->addFilter('wdc_attribute_id', $this->_promoId);
 }
 public function getCart()
 {
     return Mage::getresourceModel('cartex/cart_item')->getCurrentCart();
 }
 public function wdcSalesQuoteRemoveItem($observer)
 {
     $item = $observer->getEvent()->getQuoteItem();
     Mage::getresourceModel('cartex/cart_idx')->deletebyItemId($item->getId(), 1, 'observer');
 }
示例#23
0
 protected function getCartItems()
 {
     return Mage::getresourceModel('cartex/cart_item')->getCurrentCart();
 }