PHP Classes

File: demo/CreatePurchaseOrders.php

Recommend this page to a friend!
  Classes of Oleksii Mylotskyi   PHP MoySklad Client   demo/CreatePurchaseOrders.php   Download  
File: demo/CreatePurchaseOrders.php
Role: Example script
Content type: text/plain
Description: Demo Files
Class: PHP MoySklad Client
Access the MoySklad API using ORM like objects
Author: By
Last change:
Date: 8 years ago
Size: 1,750 bytes
 

Contents

Class file image Download
<?php
namespace Zf2ClientMoysklad;

require_once
__DIR__.'/_config.php';

use
Zf2ClientMoysklad\Entity\Good;
use
Zf2ClientMoysklad\Entity\PurchaseOrder;
use
Zf2ClientMoysklad\Repository\BasicRepository;

global
$sm;

/* @var $entityManager EntityManager */
$entityManager = $sm->get('zf2clientmoysklad_entity_manager');

/*====================== Method for Create purchase orders ==========================*/

$entityToOrder = '1e474a24-5cd7-11e3-00e2-7054d21a8d1e';

/* @var $goodEntity Good */
$goodEntity = $entityManager->find('Zf2ClientMoysklad\Entity\Good', $entityToOrder);

$purchaseOrder = new PurchaseOrder();
$purchaseOrderPosition = new PurchaseOrder\Position();

$entityManager->persist($purchaseOrder);

//Dealer id
$purchaseOrder->setSourceAgentUuid('2678f502-5cc9-11e3-320b-7054d21a8d1e');

//Your organisation id
$purchaseOrder->setTargetAgentUuid('266ce37b-5cc9-11e3-92f6-7054d21a8d1e');

$purchaseOrderPosition->setGoodsUuid($goodEntity->getUuid());
$purchaseOrderPosition->setPriceSum($goodEntity->getPrice());
$purchaseOrderPosition->setPriceSumInCurrency($goodEntity->getPrice());
$purchaseOrderPosition->setQuantity(1000);
$purchaseOrderPosition->setReserve(10);

$purchaseOrder->addOrderPosition($purchaseOrderPosition);

$purchaseOrderPosition = new PurchaseOrder\Position();
$purchaseOrderPosition->setGoodsUuid($goodEntity->getUuid());
$purchaseOrderPosition->setPriceSum($goodEntity->getPrice());
$purchaseOrderPosition->setPriceSumInCurrency($goodEntity->getPrice());
$purchaseOrderPosition->setQuantity(10);
$purchaseOrderPosition->setReserve(1);

$purchaseOrder->addOrderPosition($purchaseOrderPosition);

$entityManager->flush();

/*---------------------------------------------------------------------------------*/