예제 #1
0
 public function testCreateClientNameNotFound()
 {
     $this->setExpectedException('Client_Html_Exception');
     Client_Html_Email_Watch_Factory::createClient($this->_context, $this->_templatePaths, 'notfound');
 }
예제 #2
0
 /**
  * Executes the job.
  *
  * @throws Controller_Jobs_Exception If an error occurs
  */
 public function run()
 {
     $arcavias = $this->_getArcavias();
     $context = $this->_getContext();
     $config = $context->getConfig();
     $mailer = $context->getMail();
     $view = $context->getView();
     $templatePaths = $arcavias->getCustomPaths('client/html');
     $helper = new MW_View_Helper_Config_Default($view, $config);
     $view->addHelper('config', $helper);
     $client = Client_Html_Email_Watch_Factory::createClient($context, $templatePaths);
     $typeItem = $this->_getListTypeItem('watch');
     $whItem = $this->_getWarehouseItem('default');
     $productManager = MShop_Factory::createManager($context, 'product');
     $listManager = MShop_Factory::createManager($context, 'customer/list');
     $manager = MShop_Factory::createManager($context, 'customer');
     $search = $manager->createSearch(true);
     $expr = array($search->compare('==', 'customer.list.typeid', $typeItem->getId()), $search->compare('==', 'customer.list.domain', 'product'), $search->getConditions());
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'customer.id')));
     $date = date('Y-m-d H:i:s');
     $domains = array('text', 'price', 'media');
     $start = 0;
     do {
         $prodIds = $custIds = array();
         $customers = $manager->searchItems($search);
         $listSearch = $listManager->createSearch();
         $expr = array($listSearch->compare('==', 'customer.list.parentid', array_keys($customers)), $listSearch->compare('==', 'customer.list.typeid', $typeItem->getId()), $listSearch->compare('==', 'customer.list.domain', 'product'));
         $listSearch->setConditions($listSearch->combine('&&', $expr));
         $listSearch->setSlice(0, $listSearch->getSliceSize() * 100);
         $listItems = $listManager->searchItems($listSearch);
         foreach ($listItems as $id => $listItem) {
             $refId = $listItem->getRefId();
             $custIds[$listItem->getParentId()][$id] = $refId;
             $prodIds[$refId] = $refId;
         }
         $prodSearch = $productManager->createSearch(true);
         $expr = array($prodSearch->compare('==', 'product.id', $prodIds), $prodSearch->getConditions(), $prodSearch->compare('==', 'product.stock.warehouseid', $whItem->getId()), $prodSearch->compare('>', 'product.stock.stocklevel', 0));
         $prodSearch->setConditions($prodSearch->combine('&&', $expr));
         $prodSearch->setSlice(0, 0x7fffffff);
         $products = $productManager->searchItems($prodSearch, $domains);
         foreach ($custIds as $custId => $list) {
             $custListItems = $listIds = array();
             foreach ($list as $listId => $prodId) {
                 $listItem = $listItems[$listId];
                 if ($listItem->getDateEnd() < $date) {
                     $listIds[] = $listId;
                 }
                 $custListItems[$listId] = $listItems[$listId];
             }
             $custProducts = $this->getProducts($custListItems, $products);
             try {
                 if (!empty($custProducts)) {
                     $view->extProducts = $custProducts;
                     $view->extAddressItem = $customers[$custId]->getPaymentAddress();
                     $helper = new MW_View_Helper_Translate_Default($view, $context->getI18n($view->extAddressItem->getLanguageId()));
                     $view->addHelper('translate', $helper);
                     $message = $mailer->createMessage();
                     $helper = new MW_View_Helper_Mail_Default($view, $message);
                     $view->addHelper('mail', $helper);
                     $client->setView($view);
                     $client->getHeader();
                     $client->getBody();
                     $mailer->send($message);
                     $listManager->deleteItems($listIds + array_keys($custProducts));
                 }
             } catch (Exception $e) {
                 $str = 'Error while trying to send product notification e-mail for customer ID "%1$s": %2$s';
                 $msg = sprintf($str, $custId, $e->getMessage());
                 $context->getLogger()->log($msg);
             }
         }
         $count = count($customers);
         $start += $count;
         $search->setSlice($start);
     } while ($count >= $search->getSliceSize());
 }
예제 #3
0
 /**
  * Returns the product notification e-mail client
  *
  * @param MShop_Context_Item_Interface $context Context item object
  * @return Client_Html_Interface Product notification e-mail client
  */
 protected function _getClient(MShop_Context_Item_Interface $context)
 {
     if (!isset($this->_client)) {
         $templatePaths = $this->_getArcavias()->getCustomPaths('client/html');
         $this->_client = Client_Html_Email_Watch_Factory::createClient($context, $templatePaths);
     }
     return $this->_client;
 }