public function testUpdate() { $agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', array(), array(), '', false); $argument = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Collection', array(), array(), '', 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; }
/** * Retrieve related orders collection * * @return \Magento\Sales\Model\Resource\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; }