Esempio n. 1
0
 public function getBestsellerProducts()
 {
     $storeId = (int) Mage::app()->getStore()->getId();
     // Date
     $myFromDate = Mage::getStoreConfig('sm_bestseller/sm_bestseller_source/fromdate');
     $myToDate = Mage::getStoreConfig('sm_bestseller/sm_bestseller_source/todate');
     $date = new Zend_Date();
     Zend_debug::dump($date->getDate()->get('Y-MM-dd'));
     die;
     $fromDate = $date->setDate($myFromDate)->get('Y-MM-dd');
     $toDate = $date->setDate($myToDate)->get('Y-MM-dd');
     $collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addStoreFilter()->addPriceData()->addTaxPercents()->addUrlRewrite()->setPageSize(6);
     $collection->getSelect()->joinLeft(array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_yearly')), "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'", array('SUM(aggregation.qty_ordered) AS sold_quantity'))->group('e.entity_id')->order(array('sold_quantity DESC', 'e.created_at'));
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
     return $collection;
 }
Esempio n. 2
0
 public function testAction()
 {
     $config = Mage::getConfig();
     Zend_debug::dump(get_class_methods($config));
     die;
 }
 public function shipproductAction()
 {
     if (!$this->_getSession()->isLoggedIn()) {
         $this->_redirect('*/*/login');
         return;
     }
     if ($data = $this->getRequest()->getPost()) {
         $dropshipId = $data['dropship_id'];
         $supplier = $this->_getSession()->getSupplier();
         $dropship = Mage::getModel('inventorydropship/inventorydropship')->getCollection()->addFieldToFilter('dropship_id', $dropshipId)->addFieldToFilter('supplier_id', $supplier->getId())->getFirstItem();
         $success = false;
         if ($dropship->getId()) {
             $supplierNotNeedToConfirmProvide = true;
             if (Mage::getStoreConfig('inventoryplus/dropship/supplier_confirm_provide')) {
                 $supplierNotNeedToConfirmProvide = false;
             }
             $adminNotNeedToApprove = true;
             if (Mage::getStoreConfig('inventoryplus/dropship/admin_approve')) {
                 $adminNotNeedToApprove = false;
             }
             $supplierNotNeedToConfirmShipped = true;
             if (Mage::getStoreConfig('inventoryplus/dropship/supplier_confirm_shipped')) {
                 $supplierNotNeedToConfirmShipped = false;
             }
             $resource = Mage::getSingleton('core/resource');
             $writeConnection = $resource->getConnection('core_write');
             $readConnection = $resource->getConnection('core_read');
             $itemIds = $data['item'];
             $shipped = array();
             $savedQtys = array();
             $productIds = array();
             $qtyNeedRequest = null;
             try {
                 foreach ($itemIds as $itemId => $key) {
                     if (!is_numeric($key) || $key < 0) {
                         $key = 0;
                     }
                     $dropshipProduct = Mage::getModel('inventorydropship/inventorydropship_product')->getCollection()->addFieldToFilter('dropship_id', $dropshipId)->addFieldToFilter('item_id', $itemId)->getFirstItem();
                     if ($dropshipProduct->getId()) {
                         $success = true;
                         if ($key > $dropshipProduct->getQtyApprove() - $dropshipProduct->getQtyShipped()) {
                             $key = $dropshipProduct->getQtyApprove() - $dropshipProduct->getQtyShipped();
                         }
                         $shipped[$itemId] = $key;
                         if ($key > 0) {
                             $savedQtys[$dropshipProduct->getItemId()] = $key;
                             $productIds[$dropshipProduct->getItemId()] = $dropshipProduct->getProductId();
                         }
                         if ($dropshipProduct->getQtyOffer() == 0 && $adminNotNeedToApprove && $supplierNotNeedToConfirmShipped) {
                             $dropshipProduct->setData('qty_approve', $dropshipProduct->getQtyShipped() + $key);
                         }
                         $dropshipProduct->setData('qty_shipped', $dropshipProduct->getQtyShipped() + $key)->save();
                         $orderItem = Mage::getModel('sales/order_item')->load($itemId);
                         if ($orderItem->getProductType() == 'configurable') {
                             $itemData = unserialize($orderItem->getData('product_options'));
                             $productSku = $itemData['simple_sku'];
                             $productId = Mage::getModel('catalog/product')->getIdBySku($productSku);
                         } else {
                             $productId = $orderItem->getProductId();
                         }
                         /* return avaiable qty for warehouse */
                         $warehouseOrder = Mage::getModel('inventoryplus/warehouse_order')->getCollection()->addFieldToFilter('order_id', $orderItem->getOrderId())->addFieldToFilter('product_id', $productId)->getFirstItem();
                         $warehouseId = $warehouseOrder->getWarehouseId();
                         $warehouseProduct = Mage::getModel('inventoryplus/warehouse_product')->getCollection()->addFieldToFilter('warehouse_id', $warehouseId)->addFieldToFilter('product_id', $productId)->getFirstItem();
                         $availableQty = $warehouseProduct->getAvailableQty();
                         try {
                             $minToChangeStatus = Mage::getStoreConfig('cataloginventory/item_options/min_qty');
                             $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
                             $stockItem->setQty($stockItem->getQty() + $key)->save();
                             if ($stockItem->getQty() > $minToChangeStatus) {
                                 $stockItem->setIsInStock(1)->save();
                             }
                             $new_onhold_qty = $warehouseOrder->getQty() - $key;
                             $warehouseOrder->setQty($new_onhold_qty)->save();
                             $warehouseProduct->setAvailableQty($availableQty + $key)->save();
                         } catch (Exception $e) {
                         }
                     }
                 }
             } catch (Exception $e) {
                 $this->_getSession()->addError($exception->getMessage());
                 $this->_redirect('*/*/viewdropship', array('id' => $dropshipId));
                 return;
             }
             if ($success) {
                 $partial = false;
                 $dropshipProducts = Mage::getModel('inventorydropship/inventorydropship_product')->getCollection()->addFieldToFilter('dropship_id', $dropshipId);
                 foreach ($dropshipProducts as $dropshipProduct) {
                     if ($dropshipProduct->getQtyShipped() != $dropshipProduct->getQtyApprove()) {
                         $partial = true;
                         break;
                     }
                 }
                 if ($partial) {
                     $dropship->setStatus('4');
                 } else {
                     $dropship->setStatus('6');
                 }
                 try {
                     $dropship->save();
                     //create shipment when supplier approved
                     if ($savedQtys) {
                         Mage::getModel('admin/session')->setData('break_shipment_event_dropship', true);
                         Mage::getModel('core/session')->setData('break_shipment_event_dropship', true);
                         $order = Mage::getModel('sales/order')->load($dropship->getOrderId());
                         $transaction = Mage::getModel('core/resource_transaction')->addObject($order);
                         $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($savedQtys);
                         $shipment->register();
                         $shipment->getOrder()->setIsInProcess(true);
                         $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($shipment->getOrder())->save();
                     }
                 } catch (Exception $e) {
                     Zend_debug::dump($e->getTraceAsString());
                     die('====');
                 }
                 $this->_getSession()->addSuccess($this->__('Drop ship was successfully shipped!'));
                 Mage::helper('inventorydropship')->sendEmailConfirmShippedToAdmin($dropshipId, $shipped);
                 $this->_redirect('*/*/viewdropship', array('id' => $dropshipId));
                 return;
             }
         }
         $this->_getSession()->addError($this->__('Please enter Qty To Ship greater than 0 to ship this dropship!'));
         $this->_redirect('*/*/viewdropship', array('id' => $dropshipId));
         return;
     }
 }
    $installer->run("ALTER TABLE {$this->getTable('sales/order')} ADD COLUMN `webpos_base_change` decimal(12,4) NOT NULL default '0'");
}
if (!$webposHelper->columnExist($this->getTable('sales/invoice'), 'webpos_change')) {
    $installer->run("ALTER TABLE {$this->getTable('sales/invoice')} ADD COLUMN `webpos_change` decimal(12,4) NOT NULL default '0'");
}
if (!$webposHelper->columnExist($this->getTable('sales/invoice'), 'webpos_base_change')) {
    $installer->run("ALTER TABLE {$this->getTable('sales/invoice')} ADD COLUMN `webpos_base_change` decimal(12,4) NOT NULL default '0'");
}
$webposHelper->addDefaultData();
$installer->endSetup();
$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();
$fieldList = array('tax_class_id');
foreach ($fieldList as $field) {
    $applyTo = explode(',', $installer->getAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to'));
    if (!in_array('customsale', $applyTo)) {
        $applyTo[] = 'customsale';
        $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to', implode(',', $applyTo));
    }
}
$installer->endSetup();
$product = Mage::getModel('catalog/product');
$product->getIdBySku('webpos-customsale');
if ($product->getId()) {
    try {
        $product->setData('tax_class_id', 0);
        $product->save();
    } catch (Exception $e) {
        Zend_debug::dump($e->getMessage());
    }
}
 public function refreshToken($parameters = array())
 {
     $params = array("client_id" => $this->client_id, "client_secret" => $this->client_secret, "grant_type" => "refresh_token");
     foreach ($parameters as $k => $v) {
         $params[$k] = $v;
     }
     $response = $this->request($this->token_url, $params, "POST");
     $response = $this->parseRequestResult($response);
     Zend_debug::dump();
     die;
     if (!$response || !isset($response->access_token)) {
         throw new Exception("The Authorization Service has return: " . $response->error);
     }
     if (isset($response->access_token)) {
         $this->access_token = $response->access_token;
     }
     if (isset($response->refresh_token)) {
         $this->refresh_token = $response->refresh_token;
     }
     if (isset($response->expires_in)) {
         $this->access_token_expires_in = $response->expires_in;
     }
     // calculate when the access token expire
     $this->access_token_expires_at = time() + $response->expires_in;
     return $response;
 }
 /**
  * facebook share action
  */
 public function facebookAction()
 {
     //        if (!Mage::helper('magenotification')->checkLicenseKeyFrontController($this)) {
     //            return;
     //        }
     if ($this->_getAccountHelper()->accountNotLogin()) {
         $url = Mage::getUrl('affiliateplus/account/login');
         echo "<html><head></head><body><script type='text/javascript'>\n\t\t\t\ttry{\n\t\t\t\t\twindow.opener.location.href = '{$url}';\n\t\t\t\t}catch(e){}\n\t\t    \twindow.close();\n\t    \t</script></body></html>";
         exit;
     }
     try {
         $isAuth = $this->getRequest()->getParam('auth');
         if (!class_exists('Facebook')) {
             require_once Mage::getBaseDir('lib') . DS . 'Facebookv3' . DS . 'facebook.php';
         }
         $facebook = new Facebook(array('appId' => $this->_getConfigHelper()->getReferConfig('fbapp_id'), 'secret' => $this->_getConfigHelper()->getReferConfig('fbapp_secret'), 'cookie' => true));
         $userId = $facebook->getUser();
         if ($isAuth || !$userId) {
             $loginUrl = $facebook->getLoginUrl(array('display' => 'popup', 'redirect_uri' => Mage::getUrl('*/*/facebook'), 'scope' => 'publish_stream,email,publish_actions'));
             unset($_SESSION['fb_' . $this->_getConfigHelper()->getReferConfig('fbapp_id') . '_code']);
             unset($_SESSION['fb_' . $this->_getConfigHelper()->getReferConfig('fbapp_id') . '_access_token']);
             unset($_SESSION['fb_' . $this->_getConfigHelper()->getReferConfig('fbapp_id') . '_user_id']);
             die("<script type='text/javascript'>top.location.href = '{$loginUrl}';</script>");
         }
         $params = $this->getRequest()->getParams();
         if (!isset($params['message'])) {
             echo "<html><head></head><body><script type='text/javascript'>\n\t\t\t\tvar newUrl = window.location.href;\n\t\t\t\tvar message = '';\n\t\t\t\ttry{\n\t\t\t\t\tmessage = window.opener.document.getElementById('affiliate-facebook-content').value;\n\t\t\t\t\tmessage = encodeURIComponent(message);\n\t\t\t\t}catch(e){}\n\t\t\t\tvar fragment = '';\n\t\t\t\tif (newUrl.indexOf('#')){\n\t\t\t\t\tfragment = '#' + newUrl.split('#')[1];\n\t\t\t\t\tnewUrl = newUrl.split('#')[0];\n\t\t\t\t}\n\t\t\t\tif (newUrl.indexOf('?') != -1) newUrl += '&message=' + message;\n\t\t\t\telse newUrl += '?message=' + message;\n\t\t\t\tnewUrl += fragment;\n\t\t\t\ttop.location.href = newUrl;\n\t\t\t\t</script></body></html>";
             exit;
         }
         $message = $params['message'];
         if (!$message) {
             $message = Mage::getBlockSingleton('affiliateplusreferfriend/refer')->getDefaultSharingContent();
         }
         $facebook->api("/{$userId}/feed", 'POST', array('message' => $message));
         echo "<script type='text/javascript'>\n\t\t\ttry{\n\t\t\t\twindow.opener.document.getElementById('affiliate-facebook-msg').show();\n\t\t\t}catch(e){}\n\t\t\twindow.close();\n\t\t\t</script>";
         exit;
     } catch (Exception $e) {
         Zend_debug::dump($e->getMessage());
         die('11');
     }
     echo "<script type='text/javascript'>\n\t\ttry{\n\t\t\twindow.opener.document.getElementById('affiliate-facebook-msg').hide();\n\t\t}catch(e){}\n    \twindow.close();\n    \t</script>";
     exit;
 }
 public function updatedb23Action()
 {
     $installer = new Mage_Core_Model_Resource_Setup();
     $installer->startSetup();
     $webposHelper = Mage::helper("webpos");
     if (!$webposHelper->columnExist($installer->getTable('sales_flat_order'), 'webpos_admin_id')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales_flat_order')} ADD COLUMN `webpos_admin_id` int(10) default NULL");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales_flat_order'), 'webpos_admin_name')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales_flat_order')} ADD COLUMN `webpos_admin_name` varchar(255) default NULL");
     }
     if (!$webposHelper->columnExist($installer->getTable('webpos_user'), 'store_ids')) {
         $installer->run("ALTER TABLE {$installer->getTable('webpos_user')} ADD `store_ids` VARCHAR(255) NOT NULL AFTER `user_id`;");
     }
     if (!$webposHelper->columnExist($installer->getTable('webpos_transaction'), 'user_id')) {
         $installer->run("ALTER TABLE {$installer->getTable('webpos_transaction')} ADD `user_id` int(4) unsigned DEFAULT NULL;");
     }
     if (!$webposHelper->columnExist($installer->getTable('webpos_transaction'), 'till_id')) {
         $installer->run("ALTER TABLE {$installer->getTable('webpos_transaction')} ADD `till_id` unsigned NULL DEFAULT 0;");
     }
     if (!$webposHelper->columnExist($installer->getTable('webpos_transaction'), 'location_id')) {
         $installer->run("ALTER TABLE {$installer->getTable('webpos_transaction')} ADD `location_id` unsigned NULL DEFAULT 0;");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'till_id')) {
         $installer->run(" ALTER TABLE {$installer->getTable('sales/order')} ADD `till_id` int(11) unsigned NOT NULL DEFAULT 0; ");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'location_id')) {
         $installer->run(" ALTER TABLE {$installer->getTable('sales/order')} ADD `location_id` int(11) unsigned NOT NULL DEFAULT 0; ");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/quote_payment'), 'ccforpos_ref_no')) {
         $installer->run(" ALTER TABLE {$installer->getTable('sales/quote_payment')} ADD `ccforpos_ref_no` VARCHAR( 255 ) NOT NULL; ");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order_payment'), 'ccforpos_ref_no')) {
         $installer->run(" ALTER TABLE {$installer->getTable('sales/order_payment')} ADD `ccforpos_ref_no` VARCHAR( 255 ) NOT NULL; ");
     }
     if (!$webposHelper->columnExist($installer->getTable('webpos_order'), 'till_id')) {
         $installer->run(" ALTER TABLE {$installer->getTable('webpos_order')} ADD `till_id` int(11) unsigned NOT NULL DEFAULT 0; ");
     }
     if (!$webposHelper->columnExist($installer->getTable('webpos_order'), 'location_id')) {
         $installer->run(" ALTER TABLE {$installer->getTable('webpos_order')} ADD `location_id` int(11) unsigned NOT NULL DEFAULT 0; ");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_cash')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_cash` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_base_cash')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_base_cash` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_cash')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_cash` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_base_cash')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_base_cash` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_ccforpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_ccforpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_base_ccforpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_base_ccforpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_ccforpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_ccforpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_base_ccforpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_base_ccforpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_cp1forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_cp1forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_base_cp1forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_base_cp1forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_cp1forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_cp1forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_base_cp1forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_base_cp1forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_cp2forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_cp2forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_base_cp2forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_base_cp2forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_cp2forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_cp2forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_base_cp2forpos')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_base_cp2forpos` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_change')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_change` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/order'), 'webpos_base_change')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/order')} ADD COLUMN `webpos_base_change` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_change')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_change` decimal(12,4) NOT NULL default '0'");
     }
     if (!$webposHelper->columnExist($installer->getTable('sales/invoice'), 'webpos_base_change')) {
         $installer->run("ALTER TABLE {$installer->getTable('sales/invoice')} ADD COLUMN `webpos_base_change` decimal(12,4) NOT NULL default '0'");
     }
     $installer->endSetup();
     $installer = new Mage_Eav_Model_Entity_Setup();
     $installer->startSetup();
     $fieldList = array('tax_class_id');
     foreach ($fieldList as $field) {
         $applyTo = explode(',', $installer->getAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to'));
         if (!in_array('customsale', $applyTo)) {
             $applyTo[] = 'customsale';
             $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to', implode(',', $applyTo));
         }
     }
     $installer->endSetup();
     $product = Mage::getModel('catalog/product');
     $product->getIdBySku('webpos-customsale');
     if ($product->getId()) {
         try {
             $product->setData('tax_class_id', 0);
             $product->save();
         } catch (Exception $e) {
             Zend_debug::dump($e->getMessage());
         }
     }
 }
Esempio n. 8
0
function vd($arr)
{
    Zend_debug::dump($arr);
    die('Stop by Kostya!');
}