コード例 #1
0
 public function testGetDiscountCollection()
 {
     $ruleCollection = $this->getMock('Magento\\SalesRule\\Model\\ResourceModel\\Rule\\Collection', ['addWebsiteGroupDateFilter', 'addFieldToFilter', 'setOrder', 'load'], [], '', false);
     $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCollection));
     $ruleCollection->expects($this->once())->method('addWebsiteGroupDateFilter')->will($this->returnSelf());
     $ruleCollection->expects($this->once())->method('addFieldToFilter')->will($this->returnSelf());
     $ruleCollection->expects($this->once())->method('setOrder')->will($this->returnSelf());
     $ruleCollection->expects($this->once())->method('load')->will($this->returnSelf());
     $this->assertEquals($ruleCollection, $this->discounts->getDiscountCollection(1, 1));
 }
コード例 #2
0
 public function testGetRssData()
 {
     $ruleData = ['to_date' => '12/12/14', 'from_date' => '12/12/14', 'coupon_code' => '1234567', 'description' => 'Rule Description', 'name' => 'Rule Name'];
     $rssData = ['title' => 'Frontend Name - Discounts and Coupons', 'description' => 'Frontend Name - Discounts and Coupons', 'link' => 'http://rss.magento.com/discount', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => ['title' => 'Rule Name', 'link' => 'http://rss.magento.com', 'description' => ['description' => 'Rule Description', 'start_date' => '12/12/14', 'end_date' => '12/12/14', 'coupon_code' => '1234567']]];
     $rssUrl = 'http://rss.magento.com/discount';
     $url = 'http://rss.magento.com';
     $ruleModel = $this->getMock('Magento\\SalesRule\\Model\\Rule', ['__wakeup', 'getCouponCode', 'getToDate', 'getFromDate', 'getDescription', 'getName'], [], '', false);
     $this->storeModel->expects($this->once())->method('getWebsiteId')->will($this->returnValue(1));
     $this->storeModel->expects($this->never())->method('getName');
     $this->storeModel->expects($this->atLeastOnce())->method('getFrontendName')->willReturn('Frontend Name');
     $this->requestInterface->expects($this->any())->method('getParam')->will($this->returnValue(1));
     $this->urlBuilderInterface->expects($this->any())->method('getUrl')->will($this->returnValue($url));
     $this->rssBuilderInterface->expects($this->any())->method('getUrl')->will($this->returnValue($rssUrl));
     $this->scopeConfigInterface->expects($this->any())->method('getValue')->will($this->returnValue('en_US'));
     $ruleModel->expects($this->any())->method('getCouponCode')->will($this->returnValue($ruleData['coupon_code']));
     $ruleModel->expects($this->any())->method('getToDate')->will($this->returnValue($ruleData['to_date']));
     $ruleModel->expects($this->once())->method('getFromDate')->will($this->returnValue($ruleData['from_date']));
     $ruleModel->expects($this->once())->method('getDescription')->will($this->returnValue($ruleData['description']));
     $ruleModel->expects($this->once())->method('getName')->will($this->returnValue($ruleData['name']));
     $this->rssModel->expects($this->any())->method('getDiscountCollection')->will($this->returnValue([$ruleModel]));
     $this->timezoneInterface->expects($this->any())->method('formatDate')->will($this->returnValue('12/12/14'));
     $data = $this->block->getRssData();
     $this->assertEquals($rssData['title'], $data['title']);
     $this->assertEquals($rssData['description'], $data['description']);
     $this->assertEquals($rssData['link'], $data['link']);
     $this->assertEquals($rssData['charset'], $data['charset']);
     $this->assertEquals($rssData['language'], $data['language']);
     $this->assertEquals($rssData['entries']['title'], $data['entries'][0]['title']);
     $this->assertEquals($rssData['entries']['link'], $data['entries'][0]['link']);
     $this->assertContains($rssData['entries']['description']['description'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['start_date'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['end_date'], $data['entries'][0]['description']);
     $this->assertContains($rssData['entries']['description']['coupon_code'], $data['entries'][0]['description']);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getRssData()
 {
     $storeId = $this->getStoreId();
     $storeModel = $this->storeManager->getStore($storeId);
     $websiteId = $storeModel->getWebsiteId();
     $customerGroupId = $this->getCustomerGroupId();
     $url = $this->_urlBuilder->getUrl('');
     $newUrl = $this->rssUrlBuilder->getUrl(['type' => 'discounts', 'store_id' => $storeId, 'cid' => $customerGroupId]);
     $title = __('%1 - Discounts and Coupons', $storeModel->getFrontendName());
     $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel);
     $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang];
     /** @var $rule \Magento\SalesRule\Model\Rule */
     foreach ($this->rssModel->getDiscountCollection($websiteId, $customerGroupId) as $rule) {
         $toDate = $rule->getToDate() ? '<br/>Discount End Date: ' . $this->formatDate($rule->getToDate(), \IntlDateFormatter::MEDIUM) : '';
         $couponCode = $rule->getCouponCode() ? '<br/> Coupon Code: ' . $rule->getCouponCode() : '';
         $description = sprintf('<table><tr><td style="text-decoration:none;">%s<br/>Discount Start Date: %s %s %s</td></tr></table>', $rule->getDescription(), $this->formatDate($rule->getFromDate(), \IntlDateFormatter::MEDIUM), $toDate, $couponCode);
         $data['entries'][] = ['title' => $rule->getName(), 'description' => $description, 'link' => $url];
     }
     return $data;
 }