public function testUpdate() { $agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', [], [], '', false); $argument = $this->getMock('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection', [], [], '', false); $this->_registry->expects($this->once())->method('registry')->with('current_billing_agreement')->will($this->returnValue($agreement)); $agreement->expects($this->once())->method('getId')->will($this->returnValue('agreement id')); $this->_agreementResource->expects($this->once())->method('addOrdersFilter')->with($this->identicalTo($argument), 'agreement id'); $this->assertSame($argument, $this->_model->update($argument)); }
/** * Add billing agreement filter * * @param mixed $argument * @return mixed * @throws \DomainException */ public function update($argument) { $billingAgreement = $this->_registryManager->registry('current_billing_agreement'); if (!$billingAgreement) { throw new \DomainException('Undefined billing agreement object'); } $this->_agreementResource->addOrdersFilter($argument, $billingAgreement->getId()); return $argument; }
public function testAddOrdersFilter() { $this->resourceConnectionMock->expects($this->exactly(2))->method('getConnection')->willReturn($this->connectionMock); $this->resourceConnectionMock->expects($this->once())->method('getTableName')->with('paypal_billing_agreement_order')->willReturn('pref_paypal_billing_agreement_order'); $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('from')->with(['pbao' => 'pref_paypal_billing_agreement_order'], ['order_id'], null)->willReturnSelf(); $this->selectMock->expects($this->exactly(2))->method('where')->withConsecutive(['pbao.agreement_id IN(?)', [100]], ['main_table.entity_id IN (?)', [500]])->willReturnSelf(); $this->connectionMock->expects($this->once())->method('fetchCol')->with($this->selectMock, [])->willReturn([500]); $this->collectionMock->expects($this->once())->method('getSelect')->willReturn($this->selectMock); $this->assertEquals($this->agreementResource, $this->agreementResource->addOrdersFilter($this->collectionMock, 100)); }
/** * Apply various selection filters to prepare the sales order grid collection. * * @return $this */ protected function _prepareCollection() { $billingAgreement = $this->coreRegistry->registry('current_billing_agreement'); if ($billingAgreement) { $collection = $this->collectionFactory->getReport('sales_order_grid_data_source')->addFieldToSelect('entity_id')->addFieldToSelect('increment_id')->addFieldToSelect('customer_id')->addFieldToSelect('created_at')->addFieldToSelect('grand_total')->addFieldToSelect('order_currency_code')->addFieldToSelect('store_id')->addFieldToSelect('billing_name')->addFieldToSelect('shipping_name'); $this->billingAgreementResource->addOrdersFilter($collection, $billingAgreement->getId()); $this->setCollection($collection); } return parent::_prepareCollection(); }
/** * Retrieve related orders collection * * @return \Magento\Sales\Model\ResourceModel\Order\Collection */ public function getRelatedOrders() { if ($this->_relatedOrders === null) { $billingAgreement = $this->_getBillingAgreementInstance(); $billingAgreementId = $billingAgreement ? $billingAgreement->getAgreementId() : 0; $this->_relatedOrders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', (int) $this->_customerSession->getCustomerId())->addFieldToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->setOrder('created_at', 'desc'); $this->_agreementResource->addOrdersFilter($this->_relatedOrders, $billingAgreementId); } return $this->_relatedOrders; }